|
|
|
@ -175,3 +175,275 @@ func fileList(manifest *pluginManifest) []string { |
|
|
|
sort.Strings(keys) |
|
|
|
sort.Strings(keys) |
|
|
|
return keys |
|
|
|
return keys |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func Test_urlMatch_privateGlob(t *testing.T) { |
|
|
|
|
|
|
|
type args struct { |
|
|
|
|
|
|
|
specs []string |
|
|
|
|
|
|
|
target string |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tests := []struct { |
|
|
|
|
|
|
|
name string |
|
|
|
|
|
|
|
args args |
|
|
|
|
|
|
|
shouldMatch bool |
|
|
|
|
|
|
|
}{ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support single wildcard matching single subdomain", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://*.example.com"}, |
|
|
|
|
|
|
|
target: "https://test.example.com", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support single wildcard matching multiple subdomains", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://*.example.com"}, |
|
|
|
|
|
|
|
target: "https://more.test.example.com", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support multiple wildcards matching multiple subdomains", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://**.example.com"}, |
|
|
|
|
|
|
|
target: "https://test.example.com", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support multiple wildcards matching multiple subdomains", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://**.example.com"}, |
|
|
|
|
|
|
|
target: "https://more.test.example.com", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support single wildcard matching single paths", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://www.example.com/*"}, |
|
|
|
|
|
|
|
target: "https://www.example.com/grafana1", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support single wildcard matching multiple paths", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://www.example.com/*"}, |
|
|
|
|
|
|
|
target: "https://www.example.com/other/grafana", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support double wildcard matching multiple paths", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://www.example.com/**"}, |
|
|
|
|
|
|
|
target: "https://www.example.com/other/grafana", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support subdomain mismatch", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://www.test.example.com/grafana/docs"}, |
|
|
|
|
|
|
|
target: "https://www.dev.example.com/grafana/docs", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support single wildcard matching single path", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://www.example.com/grafana*"}, |
|
|
|
|
|
|
|
target: "https://www.example.com/grafana1", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support single wildcard matching different path prefix", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://www.example.com/grafana*"}, |
|
|
|
|
|
|
|
target: "https://www.example.com/somethingelse", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support path mismatch", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://example.com/grafana"}, |
|
|
|
|
|
|
|
target: "https://example.com/grafana1", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support both domain and path wildcards", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://*.example.com/*"}, |
|
|
|
|
|
|
|
target: "https://www.example.com/grafana1", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support wildcards without TLDs", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://example.*"}, |
|
|
|
|
|
|
|
target: "https://www.example.com/grafana1", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support exact match", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://example.com/test"}, |
|
|
|
|
|
|
|
target: "https://example.com/test", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Does not support scheme mismatch", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://test.example.com/grafana"}, |
|
|
|
|
|
|
|
target: "http://test.example.com/grafana", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support trailing slash in spec", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://example.com/"}, |
|
|
|
|
|
|
|
target: "https://example.com", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support trailing slash in target", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://example.com"}, |
|
|
|
|
|
|
|
target: "https://example.com/", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
|
|
|
got, err := urlMatch(tt.args.specs, tt.args.target, plugins.PrivateGlobSignature) |
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
require.Equal(t, tt.shouldMatch, got) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func Test_urlMatch_private(t *testing.T) { |
|
|
|
|
|
|
|
type args struct { |
|
|
|
|
|
|
|
specs []string |
|
|
|
|
|
|
|
target string |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tests := []struct { |
|
|
|
|
|
|
|
name string |
|
|
|
|
|
|
|
args args |
|
|
|
|
|
|
|
shouldMatch bool |
|
|
|
|
|
|
|
}{ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support exact match", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://example.com/test"}, |
|
|
|
|
|
|
|
target: "https://example.com/test", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support trailing slash in spec", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://example.com/test/"}, |
|
|
|
|
|
|
|
target: "https://example.com/test", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Support trailing slash in target", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://example.com/test"}, |
|
|
|
|
|
|
|
target: "https://example.com/test/", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support single wildcard matching single subdomain", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://*.example.com"}, |
|
|
|
|
|
|
|
target: "https://test.example.com", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support multiple wildcards matching multiple subdomains", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://**.example.com"}, |
|
|
|
|
|
|
|
target: "https://more.test.example.com", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support single wildcard matching single paths", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://www.example.com/*"}, |
|
|
|
|
|
|
|
target: "https://www.example.com/grafana1", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support double wildcard matching multiple paths", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://www.example.com/**"}, |
|
|
|
|
|
|
|
target: "https://www.example.com/other/grafana", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support subdomain mismatch", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://www.test.example.com/grafana/docs"}, |
|
|
|
|
|
|
|
target: "https://www.dev.example.com/grafana/docs", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support path mismatch", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://example.com/grafana"}, |
|
|
|
|
|
|
|
target: "https://example.com/grafana1", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support both domain and path wildcards", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://*.example.com/*"}, |
|
|
|
|
|
|
|
target: "https://www.example.com/grafana1", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support wildcards without TLDs", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://example.*"}, |
|
|
|
|
|
|
|
target: "https://www.example.com/grafana1", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
name: "Do not support scheme mismatch", |
|
|
|
|
|
|
|
args: args{ |
|
|
|
|
|
|
|
specs: []string{"https://test.example.com/grafana"}, |
|
|
|
|
|
|
|
target: "http://test.example.com/grafana", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
shouldMatch: false, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _, tt := range tests { |
|
|
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) { |
|
|
|
|
|
|
|
got, err := urlMatch(tt.args.specs, tt.args.target, plugins.PrivateSignature) |
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
require.Equal(t, tt.shouldMatch, got) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|