Skip to content

Commit

Permalink
fix for #1070 (we dont want to store negative responses)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Tingaikin <denis.tingajkin@xored.com>
  • Loading branch information
denis-tingaikin committed May 13, 2022
1 parent 449abee commit 4cf9975
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/networkservice/chains/nsmgr/single_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Test_DNSUsecase(t *testing.T) {
err = ioutil.WriteFile(resolveConfigPath, []byte("nameserver 8.8.4.4\nsearch example.com\n"), os.ModePerm)
require.NoError(t, err)

const expectedCorefile = ". {\n\tfanout . 8.8.4.4\n\tlog\n\treload\n\tcache\n}\nmy.domain1 {\n\tfanout . 8.8.4.4 8.8.8.8\n\tlog\n\tcache\n}"
const expectedCorefile = ". {\n\tfanout . 8.8.4.4\n\tlog\n\treload\n\tcache {\n\t\tdenial 0\n\t}\n}\nmy.domain1 {\n\tfanout . 8.8.4.4 8.8.8.8\n\tlog\n\tcache {\n\t\tdenial 0\n\t}\n}"

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, client.WithAdditionalFunctionality(dnscontext.NewClient(
dnscontext.WithChainContext(ctx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func Test_DNSContextClient_Usecases(t *testing.T) {
fanout . 8.8.4.4
log
reload
cache
cache {
denial 0
}
}`

requireFileChanged(ctx, t, corefilePath, expectedEmptyCorefile)
Expand All @@ -67,7 +69,7 @@ func Test_DNSContextClient_Usecases(t *testing.T) {
expectedCorefile string
}{
{
expectedCorefile: ". {\n\tfanout . 8.8.4.4\n\tlog\n\treload\n\tcache\n}\nexample.com {\n\tfanout . 8.8.8.8\n\tlog\n\tcache\n}",
expectedCorefile: ". {\n\tfanout . 8.8.4.4\n\tlog\n\treload\n\tcache {\n\t\tdenial 0\n\t}\n}\nexample.com {\n\tfanout . 8.8.8.8\n\tlog\n\tcache {\n\t\tdenial 0\n\t}\n}",
request: &networkservice.NetworkServiceRequest{
Connection: &networkservice.Connection{
Id: "nsc-1",
Expand All @@ -85,7 +87,7 @@ func Test_DNSContextClient_Usecases(t *testing.T) {
},
},
{
expectedCorefile: ". {\n\tfanout . 8.8.4.4\n\tlog\n\treload\n\tcache\n}\nexample.com {\n\tfanout . 7.7.7.7 8.8.8.8 9.9.9.9\n\tlog\n\tcache\n}",
expectedCorefile: ". {\n\tfanout . 8.8.4.4\n\tlog\n\treload\n\tcache {\n\t\tdenial 0\n\t}\n}\nexample.com {\n\tfanout . 7.7.7.7 8.8.8.8 9.9.9.9\n\tlog\n\tcache {\n\t\tdenial 0\n\t}\n}",
request: &networkservice.NetworkServiceRequest{
Connection: &networkservice.Connection{
Id: "nsc-1",
Expand Down
8 changes: 6 additions & 2 deletions pkg/registry/common/querycache/nse_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ import (

type queryCacheNSEClient struct {
ctx context.Context
cache *cache
cache {
denial 0
} *cache
}

// NewClient creates new querycache NSE registry client that caches all resolved NSEs
func NewClient(ctx context.Context, opts ...Option) registry.NetworkServiceEndpointRegistryClient {
return &queryCacheNSEClient{
ctx: ctx,
cache: newCache(ctx, opts...),
cache {
denial 0
}: newCache(ctx, opts...),
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/tools/dnscontext/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func (m *Manager) String() string {
plugin := defaultPlugin
sort.Strings(v)
if k == "" {
_, _ = sb.WriteString(fmt.Sprintf(serverBlockTemplate, AnyDomain, plugin, strings.Join(v, " "), "log\n\treload\n\tcache"))
_, _ = sb.WriteString(fmt.Sprintf(serverBlockTemplate, AnyDomain, plugin, strings.Join(v, " "), "log\n\treload\n\tcache {\n\t\tdenial 0\n\t}"))
} else {
_, _ = sb.WriteString(fmt.Sprintf(serverBlockTemplate, k, plugin, strings.Join(v, " "), "log\n\tcache"))
_, _ = sb.WriteString(fmt.Sprintf(serverBlockTemplate, k, plugin, strings.Join(v, " "), "log\n\tcache {\n\t\tdenial 0\n\t}"))
}
i++
if i < len(result) {
Expand Down
28 changes: 21 additions & 7 deletions pkg/tools/dnscontext/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func TestManager_StoreAnyDomain(t *testing.T) {
fanout . IP1 IP2
log
reload
cache
cache {
denial 0
}
}`
var m dnscontext.Manager
m.Store("0", &networkservice.DNSConfig{
Expand All @@ -46,7 +48,9 @@ func TestManager_StoreAnyDomainConflict(t *testing.T) {
fanout . IP1 IP2 IP3
log
reload
cache
cache {
denial 0
}
}`
var m dnscontext.Manager
m.Store("0", &networkservice.DNSConfig{
Expand All @@ -65,11 +69,15 @@ func TestManager_Store(t *testing.T) {
expected := []string{`zone-a {
fanout . IP1 IP2
log
cache
cache {
denial 0
}
}`, `zone-b zone-c {
fanout . IP3 IP4
log
cache
cache {
denial 0
}
}`}
var m dnscontext.Manager
m.Store("0", &networkservice.DNSConfig{
Expand All @@ -90,7 +98,9 @@ func TestManager_StoreConflict(t *testing.T) {
const expected = `zone-a {
fanout . IP1 IP2 IP3
log
cache
cache {
denial 0
}
}`
var m dnscontext.Manager
m.Store("0", &networkservice.DNSConfig{
Expand All @@ -109,7 +119,9 @@ func TestManger_Remove(t *testing.T) {
const expected = `zone-a {
fanout . IP1 IP2
log
cache
cache {
denial 0
}
}`
var m dnscontext.Manager
m.Store("0", &networkservice.DNSConfig{
Expand All @@ -127,7 +139,9 @@ func TestManger_RemoveConflict(t *testing.T) {
const expected = `zone-a {
fanout . IP1 IP2
log
cache
cache {
denial 0
}
}`
var m dnscontext.Manager
m.Store("0", &networkservice.DNSConfig{
Expand Down

0 comments on commit 4cf9975

Please sign in to comment.