summaryrefslogtreecommitdiff
path: root/caddyconfig/httpcaddyfile/tlsapp_test.go
diff options
context:
space:
mode:
authorMatt Holt <mholt@users.noreply.github.com>2020-10-28 20:36:00 -0600
committerGitHub <noreply@github.com>2020-10-28 20:36:00 -0600
commitdb4f1c02772dfd1f50bd745b322be1b60c72ac41 (patch)
tree2658205ada92a332822aa78f88d69a0fe9120453 /caddyconfig/httpcaddyfile/tlsapp_test.go
parentb6e96d6f4a55f96ccbb69f112822f0a923942246 (diff)
httpcaddyfile: Revise automation policy generation (#3824)
* httpcaddyfile: Revise automation policy generation This should fix a frustrating edge case where wildcard subjects are used, which potentially get shadowed by more specific versions of themselves; see the new tests for an example. This change is motivated by an actual customer requirement. Although all the tests pass, this logic is incredibly complex and nuanced, and I'm worried it is not correct. But it took me about 4 days to get this far on a solution. I did my best. * Fix typo
Diffstat (limited to 'caddyconfig/httpcaddyfile/tlsapp_test.go')
-rw-r--r--caddyconfig/httpcaddyfile/tlsapp_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/tlsapp_test.go b/caddyconfig/httpcaddyfile/tlsapp_test.go
new file mode 100644
index 0000000..1925e02
--- /dev/null
+++ b/caddyconfig/httpcaddyfile/tlsapp_test.go
@@ -0,0 +1,56 @@
+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,
+ },
+ } {
+ apA := &caddytls.AutomationPolicy{Subjects: test.a}
+ apB := &caddytls.AutomationPolicy{Subjects: test.b}
+ 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)
+ }
+ }
+}