mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 09:43:17 -04:00 
			
		
		
		
	plugin/rewrite: cleanup (#1916)
delete unused tests and fix import lines. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
		| @@ -1,102 +0,0 @@ | |||||||
| package rewrite |  | ||||||
|  |  | ||||||
| /* |  | ||||||
| func TestConditions(t *testing.T) { |  | ||||||
| 	tests := []struct { |  | ||||||
| 		condition string |  | ||||||
| 		isTrue    bool |  | ||||||
| 	}{ |  | ||||||
| 		{"a is b", false}, |  | ||||||
| 		{"a is a", true}, |  | ||||||
| 		{"a not b", true}, |  | ||||||
| 		{"a not a", false}, |  | ||||||
| 		{"a has a", true}, |  | ||||||
| 		{"a has b", false}, |  | ||||||
| 		{"ba has b", true}, |  | ||||||
| 		{"bab has b", true}, |  | ||||||
| 		{"bab has bb", false}, |  | ||||||
| 		{"a not_has a", false}, |  | ||||||
| 		{"a not_has b", true}, |  | ||||||
| 		{"ba not_has b", false}, |  | ||||||
| 		{"bab not_has b", false}, |  | ||||||
| 		{"bab not_has bb", true}, |  | ||||||
| 		{"bab starts_with bb", false}, |  | ||||||
| 		{"bab starts_with ba", true}, |  | ||||||
| 		{"bab starts_with bab", true}, |  | ||||||
| 		{"bab ends_with bb", false}, |  | ||||||
| 		{"bab ends_with bab", true}, |  | ||||||
| 		{"bab ends_with ab", true}, |  | ||||||
| 		{"a match *", false}, |  | ||||||
| 		{"a match a", true}, |  | ||||||
| 		{"a match .*", true}, |  | ||||||
| 		{"a match a.*", true}, |  | ||||||
| 		{"a match b.*", false}, |  | ||||||
| 		{"ba match b.*", true}, |  | ||||||
| 		{"ba match b[a-z]", true}, |  | ||||||
| 		{"b0 match b[a-z]", false}, |  | ||||||
| 		{"b0a match b[a-z]", false}, |  | ||||||
| 		{"b0a match b[a-z]+", false}, |  | ||||||
| 		{"b0a match b[a-z0-9]+", true}, |  | ||||||
| 		{"a not_match *", true}, |  | ||||||
| 		{"a not_match a", false}, |  | ||||||
| 		{"a not_match .*", false}, |  | ||||||
| 		{"a not_match a.*", false}, |  | ||||||
| 		{"a not_match b.*", true}, |  | ||||||
| 		{"ba not_match b.*", false}, |  | ||||||
| 		{"ba not_match b[a-z]", false}, |  | ||||||
| 		{"b0 not_match b[a-z]", true}, |  | ||||||
| 		{"b0a not_match b[a-z]", true}, |  | ||||||
| 		{"b0a not_match b[a-z]+", true}, |  | ||||||
| 		{"b0a not_match b[a-z0-9]+", false}, |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	for i, test := range tests { |  | ||||||
| 		str := strings.Fields(test.condition) |  | ||||||
| 		ifCond, err := NewIf(str[0], str[1], str[2]) |  | ||||||
| 		if err != nil { |  | ||||||
| 			t.Error(err) |  | ||||||
| 		} |  | ||||||
| 		isTrue := ifCond.True(nil) |  | ||||||
| 		if isTrue != test.isTrue { |  | ||||||
| 			t.Errorf("Test %v: expected %v found %v", i, test.isTrue, isTrue) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	invalidOperators := []string{"ss", "and", "if"} |  | ||||||
| 	for _, op := range invalidOperators { |  | ||||||
| 		_, err := NewIf("a", op, "b") |  | ||||||
| 		if err == nil { |  | ||||||
| 			t.Errorf("Invalid operator %v used, expected error.", op) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	replaceTests := []struct { |  | ||||||
| 		url       string |  | ||||||
| 		condition string |  | ||||||
| 		isTrue    bool |  | ||||||
| 	}{ |  | ||||||
| 		{"/home", "{uri} match /home", true}, |  | ||||||
| 		{"/hom", "{uri} match /home", false}, |  | ||||||
| 		{"/hom", "{uri} starts_with /home", false}, |  | ||||||
| 		{"/hom", "{uri} starts_with /h", true}, |  | ||||||
| 		{"/home/.hiddenfile", `{uri} match \/\.(.*)`, true}, |  | ||||||
| 		{"/home/.hiddendir/afile", `{uri} match \/\.(.*)`, true}, |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	for i, test := range replaceTests { |  | ||||||
| 		r, err := http.NewRequest("GET", test.url, nil) |  | ||||||
| 		if err != nil { |  | ||||||
| 			t.Error(err) |  | ||||||
| 		} |  | ||||||
| 		str := strings.Fields(test.condition) |  | ||||||
| 		ifCond, err := NewIf(str[0], str[1], str[2]) |  | ||||||
| 		if err != nil { |  | ||||||
| 			t.Error(err) |  | ||||||
| 		} |  | ||||||
| 		isTrue := ifCond.True(r) |  | ||||||
| 		if isTrue != test.isTrue { |  | ||||||
| 			t.Errorf("Test %v: expected %v found %v", i, test.isTrue, isTrue) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| */ |  | ||||||
| @@ -12,6 +12,7 @@ import ( | |||||||
| 	"github.com/coredns/coredns/plugin/metadata" | 	"github.com/coredns/coredns/plugin/metadata" | ||||||
| 	"github.com/coredns/coredns/plugin/pkg/variables" | 	"github.com/coredns/coredns/plugin/pkg/variables" | ||||||
| 	"github.com/coredns/coredns/request" | 	"github.com/coredns/coredns/request" | ||||||
|  |  | ||||||
| 	"github.com/miekg/dns" | 	"github.com/miekg/dns" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -287,8 +288,7 @@ func newEdns0SubnetRule(mode, action, v4BitMaskLen, v6BitMaskLen string) (*edns0 | |||||||
| } | } | ||||||
|  |  | ||||||
| // fillEcsData sets the subnet data into the ecs option | // fillEcsData sets the subnet data into the ecs option | ||||||
| func (rule *edns0SubnetRule) fillEcsData(w dns.ResponseWriter, r *dns.Msg, | func (rule *edns0SubnetRule) fillEcsData(w dns.ResponseWriter, r *dns.Msg, ecs *dns.EDNS0_SUBNET) error { | ||||||
| 	ecs *dns.EDNS0_SUBNET) error { |  | ||||||
|  |  | ||||||
| 	req := request.Request{W: w, Req: r} | 	req := request.Request{W: w, Req: r} | ||||||
| 	family := req.Family() | 	family := req.Family() | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
| 	"github.com/coredns/coredns/plugin" | 	"github.com/coredns/coredns/plugin" | ||||||
|  |  | ||||||
| 	"github.com/miekg/dns" | 	"github.com/miekg/dns" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,9 +18,6 @@ const ( | |||||||
| 	RewriteIgnored Result = iota | 	RewriteIgnored Result = iota | ||||||
| 	// RewriteDone is returned when rewrite is done on request. | 	// RewriteDone is returned when rewrite is done on request. | ||||||
| 	RewriteDone | 	RewriteDone | ||||||
| 	// RewriteStatus is returned when rewrite is not needed and status code should be set |  | ||||||
| 	// for the request. |  | ||||||
| 	RewriteStatus |  | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // These are defined processing mode. | // These are defined processing mode. | ||||||
| @@ -57,11 +54,6 @@ func (rw Rewrite) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg | |||||||
| 			} | 			} | ||||||
| 		case RewriteIgnored: | 		case RewriteIgnored: | ||||||
| 			break | 			break | ||||||
| 		case RewriteStatus: |  | ||||||
| 			// only valid for complex rules. |  | ||||||
| 			// if cRule, ok := rule.(*ComplexRule); ok && cRule.Status != 0 { |  | ||||||
| 			// return cRule.Status, nil |  | ||||||
| 			// } |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	if rw.noRevert || len(wr.ResponseRules) == 0 { | 	if rw.noRevert || len(wr.ResponseRules) == 0 { | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ package rewrite | |||||||
| import ( | import ( | ||||||
| 	"github.com/coredns/coredns/core/dnsserver" | 	"github.com/coredns/coredns/core/dnsserver" | ||||||
| 	"github.com/coredns/coredns/plugin" | 	"github.com/coredns/coredns/plugin" | ||||||
|  |  | ||||||
| 	"github.com/mholt/caddy" | 	"github.com/mholt/caddy" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user