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

Function TestCreateSASL

internal/auth/sasl_test.go:42–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestCreateSASL(t *testing.T) {
43 a := SASLAuth{
44 Log: testutils.Logger(t, "saslauth"),
45 Plain: []module.PlainAuth{
46 &mockAuth{
47 db: map[string]bool{
48 "user1": true,
49 },
50 },
51 },
52 }
53
54 t.Run("XWHATEVER", func(t *testing.T) {
55 srv := a.CreateSASL("XWHATEVER", &net.TCPAddr{}, func(string, ContextData) error { return nil })
56 _, _, err := srv.Next([]byte(""))
57 if err == nil {
58 t.Error("No error for XWHATEVER use")
59 }
60 })
61
62 t.Run("PLAIN", func(t *testing.T) {
63 srv := a.CreateSASL("PLAIN", &net.TCPAddr{}, func(id string, data ContextData) error {
64 if id != "user1" {
65 t.Fatal("Wrong auth. identities passed to callback:", id)
66 }
67 return nil
68 })
69
70 _, _, err := srv.Next([]byte("\x00user1\x00aa"))
71 if err != nil {
72 t.Error("Unexpected error:", err)
73 }
74 })
75
76 t.Run("PLAIN with authorization identity", func(t *testing.T) {
77 srv := a.CreateSASL("PLAIN", &net.TCPAddr{}, func(id string, data ContextData) error {
78 if id != "user1" {
79 t.Fatal("Wrong authorization identity passed:", id)
80 }
81 return nil
82 })
83
84 _, _, err := srv.Next([]byte("user1\x00user1\x00aa"))
85 if err != nil {
86 t.Error("Unexpected error:", err)
87 }
88 })
89}

Callers

nothing calls this directly

Calls 5

CreateSASLMethod · 0.95
LoggerFunction · 0.92
RunMethod · 0.45
NextMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected