2020-10-29 05:36:00 +03:00
|
|
|
package httpcaddyfile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/caddyserver/caddy/v2/modules/caddytls"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAutomationPolicyIsSubset(t *testing.T) {
|
|
|
|
for i, test := range []struct {
|
|
|
|
a, b []string
|
|
|
|
expect bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
a: []string{"example.com"},
|
|
|
|
b: []string{},
|
|
|
|
expect: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []string{},
|
|
|
|
b: []string{"example.com"},
|
|
|
|
expect: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []string{"foo.example.com"},
|
|
|
|
b: []string{"*.example.com"},
|
|
|
|
expect: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []string{"foo.example.com"},
|
|
|
|
b: []string{"foo.example.com"},
|
|
|
|
expect: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []string{"foo.example.com"},
|
|
|
|
b: []string{"example.com"},
|
|
|
|
expect: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []string{"example.com", "foo.example.com"},
|
|
|
|
b: []string{"*.com", "*.*.com"},
|
|
|
|
expect: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: []string{"example.com", "foo.example.com"},
|
|
|
|
b: []string{"*.com"},
|
|
|
|
expect: false,
|
|
|
|
},
|
|
|
|
} {
|
2023-03-28 00:16:22 +03:00
|
|
|
apA := &caddytls.AutomationPolicy{SubjectsRaw: test.a}
|
|
|
|
apB := &caddytls.AutomationPolicy{SubjectsRaw: test.b}
|
2020-10-29 05:36:00 +03:00
|
|
|
if actual := automationPolicyIsSubset(apA, apB); actual != test.expect {
|
|
|
|
t.Errorf("Test %d: Expected %t but got %t (A: %v B: %v)", i, test.expect, actual, test.a, test.b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|