@marcel91200 / caddy Mirror · read-only
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 01:00 UTC

master
go 74 lines 1.63 KB
Raw
1 package httpcaddyfile
2
3 import (
4 "testing"
5
6 "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
7 "github.com/caddyserver/caddy/v2/modules/caddytls"
8 )
9
10 func TestAutomationPolicyIsSubset(t *testing.T) {
11 for i, test := range []struct {
12 a, b []string
13 expect bool
14 }{
15 {
16 a: []string{"example.com"},
17 b: []string{},
18 expect: true,
19 },
20 {
21 a: []string{},
22 b: []string{"example.com"},
23 expect: false,
24 },
25 {
26 a: []string{"foo.example.com"},
27 b: []string{"*.example.com"},
28 expect: true,
29 },
30 {
31 a: []string{"foo.example.com"},
32 b: []string{"foo.example.com"},
33 expect: true,
34 },
35 {
36 a: []string{"foo.example.com"},
37 b: []string{"example.com"},
38 expect: false,
39 },
40 {
41 a: []string{"example.com", "foo.example.com"},
42 b: []string{"*.com", "*.*.com"},
43 expect: true,
44 },
45 {
46 a: []string{"example.com", "foo.example.com"},
47 b: []string{"*.com"},
48 expect: false,
49 },
50 } {
51 apA := &caddytls.AutomationPolicy{SubjectsRaw: test.a}
52 apB := &caddytls.AutomationPolicy{SubjectsRaw: test.b}
53 if actual := automationPolicyIsSubset(apA, apB); actual != test.expect {
54 t.Errorf("Test %d: Expected %t but got %t (A: %v B: %v)", i, test.expect, actual, test.a, test.b)
55 }
56 }
57 }
58
59 func TestAutomationPoliciesAllowSameHostOnDifferentPorts(t *testing.T) {
60 input := `https://example.com:5000 localhost:5000 {
61 respond "one"
62 }
63
64 https://example.net localhost:8080 {
65 respond "two"
66 }
67 `
68
69 adapter := caddyfile.Adapter{ServerType: ServerType{}}
70 _, _, err := adapter.Adapt([]byte(input), nil)
71 if err != nil {
72 t.Fatalf("adapting Caddyfile: %v", err)
73 }
74 }