forked from foxcpp/maddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimap_test.go
96 lines (81 loc) · 2.14 KB
/
imap_test.go
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
//go:build integration && cgo && !nosqlite3
// +build integration,cgo,!nosqlite3
package tests_test
import (
"testing"
"github.com/foxcpp/maddy/tests"
)
func TestIMAPEndpointAuthMap(tt *testing.T) {
tt.Parallel()
t := tests.NewT(tt)
t.DNS(nil)
t.Port("imap")
t.Config(`
storage.imapsql test_store {
driver sqlite3
dsn imapsql.db
}
imap tcp://127.0.0.1:{env:TEST_PORT_imap} {
tls off
auth_map email_localpart
auth pass_table static {
entry "user" "bcrypt:$2a$10$E.AuCH3oYbaRrETXfXwc0.4jRAQBbanpZiCfudsJz9bHzLr/qj6ti" # password: 123
}
storage &test_store
}
`)
t.Run(1)
defer t.Close()
imapConn := t.Conn("imap")
defer imapConn.Close()
imapConn.ExpectPattern(`\* OK *`)
imapConn.Writeln(". LOGIN [email protected] 123")
imapConn.ExpectPattern(". OK *")
imapConn.Writeln(". SELECT INBOX")
imapConn.ExpectPattern(`\* *`)
imapConn.ExpectPattern(`\* *`)
imapConn.ExpectPattern(`\* *`)
imapConn.ExpectPattern(`\* *`)
imapConn.ExpectPattern(`\* *`)
imapConn.ExpectPattern(`\* *`)
imapConn.ExpectPattern(`. OK *`)
}
func TestIMAPEndpointStorageMap(tt *testing.T) {
tt.Parallel()
t := tests.NewT(tt)
t.DNS(nil)
t.Port("imap")
t.Config(`
storage.imapsql test_store {
driver sqlite3
dsn imapsql.db
}
imap tcp://127.0.0.1:{env:TEST_PORT_imap} {
tls off
storage_map email_localpart
auth_map email_localpart
auth pass_table static {
entry "user" "bcrypt:$2a$10$z9SvUwUjkY8wKOWd9IbISeEmbJua2cXRPqw7s2BnLXJuc6pIMPncK" # password: 123
}
storage &test_store
}
`)
t.Run(1)
defer t.Close()
imapConn := t.Conn("imap")
defer imapConn.Close()
imapConn.ExpectPattern(`\* OK *`)
imapConn.Writeln(". LOGIN [email protected] 123")
imapConn.ExpectPattern(". OK *")
imapConn.Writeln(". CREATE testbox")
imapConn.ExpectPattern(". OK *")
imapConn2 := t.Conn("imap")
defer imapConn2.Close()
imapConn2.ExpectPattern(`\* OK *`)
imapConn2.Writeln(". LOGIN [email protected] 123")
imapConn2.ExpectPattern(". OK *")
imapConn2.Writeln(`. LIST "" "*"`)
imapConn2.Expect(`* LIST (\HasNoChildren) "." INBOX`)
imapConn2.Expect(`* LIST (\HasNoChildren) "." "testbox"`)
imapConn2.ExpectPattern(". OK *")
}