(t *testing.T)
| 40 | } |
| 41 | |
| 42 | func 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 | } |
nothing calls this directly
no test coverage detected