-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathauth_test.go
More file actions
104 lines (93 loc) · 2.02 KB
/
auth_test.go
File metadata and controls
104 lines (93 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"net/smtp"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoginAuth(t *testing.T) {
auth := LoginAuth("testuser", "testpass")
assert.NotNil(t, auth)
// Type assertion to ensure we get the right type
loginAuth, ok := auth.(*loginAuth)
assert.True(t, ok)
assert.Equal(t, "testuser", loginAuth.username)
assert.Equal(t, "testpass", loginAuth.password)
}
func TestLoginAuthStart(t *testing.T) {
auth := &loginAuth{
username: "testuser",
password: "testpass",
}
method, resp, err := auth.Start(&smtp.ServerInfo{})
assert.NoError(t, err)
assert.Equal(t, "LOGIN", method)
assert.Empty(t, resp)
}
func TestLoginAuthNext(t *testing.T) {
auth := &loginAuth{
username: "testuser",
password: "testpass",
}
tests := []struct {
name string
serverMsg string
more bool
expected string
expectErr bool
}{
{
name: "username prompt - User Name",
serverMsg: "User Name",
more: true,
expected: "testuser",
expectErr: false,
},
{
name: "username prompt - Username:",
serverMsg: "Username:",
more: true,
expected: "testuser",
expectErr: false,
},
{
name: "password prompt - Password",
serverMsg: "Password",
more: true,
expected: "testpass",
expectErr: false,
},
{
name: "password prompt - Password:",
serverMsg: "Password:",
more: true,
expected: "testpass",
expectErr: false,
},
{
name: "unknown server response",
serverMsg: "Unknown Prompt",
more: true,
expected: "",
expectErr: true,
},
{
name: "more is false",
serverMsg: "anything",
more: false,
expected: "",
expectErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resp, err := auth.Next([]byte(tt.serverMsg), tt.more)
if tt.expectErr {
assert.Error(t, err)
assert.Contains(t, err.Error(), "unknown server response")
} else {
assert.NoError(t, err)
assert.Equal(t, tt.expected, string(resp))
}
})
}
}