feat(dns): allow empty alias discovery without HSD client
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
f6afe97b35
commit
8857ed4e51
2 changed files with 64 additions and 8 deletions
16
service.go
16
service.go
|
|
@ -290,10 +290,6 @@ func (service *Service) DiscoverFromChainAliases(ctx context.Context, client *HS
|
|||
if !found {
|
||||
return nil
|
||||
}
|
||||
effectiveHSDClient, err := service.resolveHSDClient(client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(aliases) == 0 {
|
||||
now := time.Now()
|
||||
fingerprint := aliasFingerprint(aliases)
|
||||
|
|
@ -301,6 +297,10 @@ func (service *Service) DiscoverFromChainAliases(ctx context.Context, client *HS
|
|||
service.recordTreeRootState(now, "", fingerprint)
|
||||
return nil
|
||||
}
|
||||
effectiveHSDClient, err := service.resolveHSDClient(client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return service.discoverFromChainAliasesUsingTreeRoot(ctx, aliases, effectiveHSDClient)
|
||||
}
|
||||
|
||||
|
|
@ -516,10 +516,6 @@ func (service *Service) DiscoverFromMainchainAliases(ctx context.Context, chainC
|
|||
if !found {
|
||||
return nil
|
||||
}
|
||||
effectiveHSDClient, err := service.resolveHSDClient(hsdClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(aliases) == 0 {
|
||||
now := time.Now()
|
||||
fingerprint := aliasFingerprint(aliases)
|
||||
|
|
@ -527,6 +523,10 @@ func (service *Service) DiscoverFromMainchainAliases(ctx context.Context, chainC
|
|||
service.recordTreeRootState(now, "", fingerprint)
|
||||
return nil
|
||||
}
|
||||
effectiveHSDClient, err := service.resolveHSDClient(hsdClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return service.discoverFromChainAliasesUsingTreeRoot(ctx, aliases, effectiveHSDClient)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1061,6 +1061,34 @@ func TestServiceDiscoverAliasesClearsCacheWhenAliasListBecomesEmpty(t *testing.T
|
|||
}
|
||||
}
|
||||
|
||||
func TestServiceDiscoverAliasesClearsCacheWhenAliasListIsEmptyWithoutHSDClient(t *testing.T) {
|
||||
service := NewService(ServiceOptions{
|
||||
Records: map[string]NameRecords{
|
||||
"legacy.charon.lthn": {
|
||||
A: []string{"10.11.11.11"},
|
||||
},
|
||||
},
|
||||
ChainAliasDiscoverer: func(_ context.Context) ([]string, error) {
|
||||
return []string{}, nil
|
||||
},
|
||||
})
|
||||
service.hsdClient = nil
|
||||
service.mainchainAliasClient = nil
|
||||
|
||||
if err := service.DiscoverAliases(context.Background()); err != nil {
|
||||
t.Fatalf("expected empty alias discovery to succeed without HSD client: %v", err)
|
||||
}
|
||||
|
||||
if _, ok := service.Resolve("legacy.charon.lthn"); ok {
|
||||
t.Fatal("expected stale records to be cleared when the alias list is empty")
|
||||
}
|
||||
|
||||
health := service.Health()
|
||||
if health.NamesCached != 0 {
|
||||
t.Fatalf("expected empty cache after clearing aliases, got %d", health.NamesCached)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceDiscoverAliasesParsesAliasDetailRecordsFromActionCaller(t *testing.T) {
|
||||
var treeRootCalls int32
|
||||
var nameResourceCalls int32
|
||||
|
|
@ -1703,6 +1731,34 @@ func TestServiceDiscoverAliasesReturnsNilWithoutDiscovererOrHSDClient(t *testing
|
|||
}
|
||||
}
|
||||
|
||||
func TestServiceDiscoverFromMainchainAliasesClearsCacheWhenAliasListIsEmptyWithoutHSDClient(t *testing.T) {
|
||||
service := NewService(ServiceOptions{
|
||||
Records: map[string]NameRecords{
|
||||
"legacy.charon.lthn": {
|
||||
A: []string{"10.11.11.11"},
|
||||
},
|
||||
},
|
||||
ChainAliasDiscoverer: func(_ context.Context) ([]string, error) {
|
||||
return []string{}, nil
|
||||
},
|
||||
})
|
||||
service.mainchainAliasClient = nil
|
||||
service.hsdClient = nil
|
||||
|
||||
if err := service.DiscoverFromMainchainAliases(context.Background(), nil, nil); err != nil {
|
||||
t.Fatalf("expected empty mainchain alias discovery to succeed without HSD or mainchain client: %v", err)
|
||||
}
|
||||
|
||||
if _, ok := service.Resolve("legacy.charon.lthn"); ok {
|
||||
t.Fatal("expected stale records to be cleared when the mainchain alias list is empty")
|
||||
}
|
||||
|
||||
health := service.Health()
|
||||
if health.NamesCached != 0 {
|
||||
t.Fatalf("expected empty cache after clearing aliases, got %d", health.NamesCached)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceCreatesDefaultHSDClientWhenURLNotConfigured(t *testing.T) {
|
||||
service := NewService(ServiceOptions{
|
||||
ChainAliasDiscoverer: func(_ context.Context) ([]string, error) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue