MCPcopy Create free account
hub / github.com/foxcpp/maddy / TestCheckDomainAuth

Function TestCheckDomainAuth

internal/auth/auth_test.go:26–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestCheckDomainAuth(t *testing.T) {
27 cases := []struct {
28 rawUsername string
29
30 perDomain bool
31 allowedDomains []string
32
33 loginName string
34 }{
35 {
36 rawUsername: "username",
37 loginName: "username",
38 },
39 {
40 rawUsername: "username",
41 allowedDomains: []string{"example.org"},
42 loginName: "username",
43 },
44 {
45 rawUsername: "username@example.org",
46 allowedDomains: []string{"example.org"},
47 loginName: "username",
48 },
49 {
50 rawUsername: "username@example.com",
51 allowedDomains: []string{"example.org"},
52 },
53 {
54 rawUsername: "username",
55 allowedDomains: []string{"example.org"},
56 perDomain: true,
57 },
58 {
59 rawUsername: "username@example.com",
60 allowedDomains: []string{"example.org"},
61 perDomain: true,
62 },
63 {
64 rawUsername: "username@EXAMPLE.Org",
65 allowedDomains: []string{"exaMPle.org"},
66 perDomain: true,
67 loginName: "username@EXAMPLE.Org",
68 },
69 {
70 rawUsername: "username@example.org",
71 allowedDomains: []string{"example.org"},
72 perDomain: true,
73 loginName: "username@example.org",
74 },
75 }
76
77 for _, case_ := range cases {
78 t.Run(fmt.Sprintf("%+v", case_), func(t *testing.T) {
79 loginName, allowed := CheckDomainAuth(case_.rawUsername, case_.perDomain, case_.allowedDomains)
80 if case_.loginName != "" && !allowed {
81 t.Fatalf("Unexpected authentication fail")
82 }
83 if case_.loginName == "" && allowed {

Callers

nothing calls this directly

Calls 2

CheckDomainAuthFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected