@@ -11,103 +11,51 @@ const (
11
11
testHost = "smtp.example.com"
12
12
)
13
13
14
- var testAuth = & plainAuth {
15
- username : testUser ,
16
- password : testPwd ,
17
- host : testHost ,
18
- }
19
-
20
- type plainAuthTest struct {
14
+ type authTest struct {
21
15
auths []string
22
16
challenges []string
23
17
tls bool
24
- wantProto string
25
18
wantData []string
26
19
wantError bool
27
20
}
28
21
29
22
func TestNoAdvertisement (t * testing.T ) {
30
- testPlainAuth (t , & plainAuthTest {
31
- auths : []string {},
32
- challenges : []string {"Username:" , "Password:" },
33
- tls : false ,
34
- wantProto : "PLAIN" ,
35
- wantError : true ,
23
+ testLoginAuth (t , & authTest {
24
+ auths : []string {},
25
+ tls : false ,
26
+ wantError : true ,
36
27
})
37
28
}
38
29
39
30
func TestNoAdvertisementTLS (t * testing.T ) {
40
- testPlainAuth (t , & plainAuthTest {
31
+ testLoginAuth (t , & authTest {
41
32
auths : []string {},
42
33
challenges : []string {"Username:" , "Password:" },
43
34
tls : true ,
44
- wantProto : "PLAIN" ,
45
- wantData : []string {"\x00 " + testUser + "\x00 " + testPwd },
46
- })
47
- }
48
-
49
- func TestPlain (t * testing.T ) {
50
- testPlainAuth (t , & plainAuthTest {
51
- auths : []string {"PLAIN" },
52
- challenges : []string {"Username:" , "Password:" },
53
- tls : false ,
54
- wantProto : "PLAIN" ,
55
- wantData : []string {"\x00 " + testUser + "\x00 " + testPwd },
56
- })
57
- }
58
-
59
- func TestPlainTLS (t * testing.T ) {
60
- testPlainAuth (t , & plainAuthTest {
61
- auths : []string {"PLAIN" },
62
- challenges : []string {"Username:" , "Password:" },
63
- tls : true ,
64
- wantProto : "PLAIN" ,
65
- wantData : []string {"\x00 " + testUser + "\x00 " + testPwd },
66
- })
67
- }
68
-
69
- func TestPlainAndLogin (t * testing.T ) {
70
- testPlainAuth (t , & plainAuthTest {
71
- auths : []string {"PLAIN" , "LOGIN" },
72
- challenges : []string {"Username:" , "Password:" },
73
- tls : false ,
74
- wantProto : "PLAIN" ,
75
- wantData : []string {"\x00 " + testUser + "\x00 " + testPwd },
76
- })
77
- }
78
-
79
- func TestPlainAndLoginTLS (t * testing.T ) {
80
- testPlainAuth (t , & plainAuthTest {
81
- auths : []string {"PLAIN" , "LOGIN" },
82
- challenges : []string {"Username:" , "Password:" },
83
- tls : true ,
84
- wantProto : "PLAIN" ,
85
- wantData : []string {"\x00 " + testUser + "\x00 " + testPwd },
35
+ wantData : []string {"" , testUser , testPwd },
86
36
})
87
37
}
88
38
89
39
func TestLogin (t * testing.T ) {
90
- testPlainAuth (t , & plainAuthTest {
91
- auths : []string {"LOGIN" },
40
+ testLoginAuth (t , & authTest {
41
+ auths : []string {"PLAIN" , " LOGIN" },
92
42
challenges : []string {"Username:" , "Password:" },
93
43
tls : false ,
94
- wantProto : "LOGIN" ,
95
44
wantData : []string {"" , testUser , testPwd },
96
45
})
97
46
}
98
47
99
48
func TestLoginTLS (t * testing.T ) {
100
- testPlainAuth (t , & plainAuthTest {
49
+ testLoginAuth (t , & authTest {
101
50
auths : []string {"LOGIN" },
102
51
challenges : []string {"Username:" , "Password:" },
103
52
tls : true ,
104
- wantProto : "LOGIN" ,
105
53
wantData : []string {"" , testUser , testPwd },
106
54
})
107
55
}
108
56
109
- func testPlainAuth (t * testing.T , test * plainAuthTest ) {
110
- auth := & plainAuth {
57
+ func testLoginAuth (t * testing.T , test * authTest ) {
58
+ auth := & loginAuth {
111
59
username : testUser ,
112
60
password : testPwd ,
113
61
host : testHost ,
@@ -119,13 +67,13 @@ func testPlainAuth(t *testing.T, test *plainAuthTest) {
119
67
}
120
68
proto , toServer , err := auth .Start (server )
121
69
if err != nil && ! test .wantError {
122
- t .Fatalf ("plainAuth .Start(): %v" , err )
70
+ t .Fatalf ("loginAuth .Start(): %v" , err )
123
71
}
124
72
if err != nil && test .wantError {
125
73
return
126
74
}
127
- if proto != test . wantProto {
128
- t .Errorf ("invalid protocol, got %q, want %q " , proto , test . wantProto )
75
+ if proto != "LOGIN" {
76
+ t .Errorf ("invalid protocol, got %q, want LOGIN " , proto )
129
77
}
130
78
131
79
i := 0
@@ -134,10 +82,6 @@ func testPlainAuth(t *testing.T, test *plainAuthTest) {
134
82
t .Errorf ("Invalid response, got %q, want %q" , got , test .wantData [i ])
135
83
}
136
84
137
- if proto == "PLAIN" {
138
- return
139
- }
140
-
141
85
for _ , challenge := range test .challenges {
142
86
i ++
143
87
if i >= len (test .wantData ) {
@@ -146,7 +90,7 @@ func testPlainAuth(t *testing.T, test *plainAuthTest) {
146
90
147
91
toServer , err = auth .Next ([]byte (challenge ), true )
148
92
if err != nil {
149
- t .Fatalf ("plainAuth .Auth(): %v" , err )
93
+ t .Fatalf ("loginAuth .Auth(): %v" , err )
150
94
}
151
95
got = string (toServer )
152
96
if got != test .wantData [i ] {
0 commit comments