maddy

Fork https://github.com/foxcpp/maddy

git clone git://git.lin.moe/go/maddy.git

 1//go:build integration && cgo && !nosqlite3
 2// +build integration,cgo,!nosqlite3
 3
 4package tests_test
 5
 6import (
 7	"testing"
 8
 9	"github.com/foxcpp/maddy/tests"
10)
11
12func TestIMAPEndpointAuthMap(tt *testing.T) {
13	tt.Parallel()
14	t := tests.NewT(tt)
15
16	t.DNS(nil)
17	t.Port("imap")
18	t.Config(`
19		storage.imapsql test_store {
20			driver sqlite3
21			dsn imapsql.db
22		}
23
24		imap tcp://127.0.0.1:{env:TEST_PORT_imap} {
25			tls off
26
27			auth_map email_localpart
28			auth pass_table static {
29				entry "user" "bcrypt:$2a$10$E.AuCH3oYbaRrETXfXwc0.4jRAQBbanpZiCfudsJz9bHzLr/qj6ti" # password: 123
30			}
31			storage &test_store
32		}
33	`)
34	t.Run(1)
35	defer t.Close()
36
37	imapConn := t.Conn("imap")
38	defer imapConn.Close()
39	imapConn.ExpectPattern(`\* OK *`)
40	imapConn.Writeln(". LOGIN user@example.org 123")
41	imapConn.ExpectPattern(". OK *")
42	imapConn.Writeln(". SELECT INBOX")
43	imapConn.ExpectPattern(`\* *`)
44	imapConn.ExpectPattern(`\* *`)
45	imapConn.ExpectPattern(`\* *`)
46	imapConn.ExpectPattern(`\* *`)
47	imapConn.ExpectPattern(`\* *`)
48	imapConn.ExpectPattern(`\* *`)
49	imapConn.ExpectPattern(`. OK *`)
50}
51
52func TestIMAPEndpointStorageMap(tt *testing.T) {
53	tt.Parallel()
54	t := tests.NewT(tt)
55
56	t.DNS(nil)
57	t.Port("imap")
58	t.Config(`
59		storage.imapsql test_store {
60			driver sqlite3
61			dsn imapsql.db
62		}
63
64		imap tcp://127.0.0.1:{env:TEST_PORT_imap} {
65			tls off
66
67			storage_map email_localpart
68
69			auth_map email_localpart
70			auth pass_table static {
71				entry "user" "bcrypt:$2a$10$z9SvUwUjkY8wKOWd9IbISeEmbJua2cXRPqw7s2BnLXJuc6pIMPncK" # password: 123
72			}
73			storage &test_store
74		}
75	`)
76	t.Run(1)
77	defer t.Close()
78
79	imapConn := t.Conn("imap")
80	defer imapConn.Close()
81	imapConn.ExpectPattern(`\* OK *`)
82	imapConn.Writeln(". LOGIN user@example.org 123")
83	imapConn.ExpectPattern(". OK *")
84	imapConn.Writeln(". CREATE testbox")
85	imapConn.ExpectPattern(". OK *")
86
87	imapConn2 := t.Conn("imap")
88	defer imapConn2.Close()
89	imapConn2.ExpectPattern(`\* OK *`)
90	imapConn2.Writeln(". LOGIN user@example.com 123")
91	imapConn2.ExpectPattern(". OK *")
92	imapConn2.Writeln(`. LIST "" "*"`)
93	imapConn2.Expect(`* LIST (\HasNoChildren) "." INBOX`)
94	imapConn2.Expect(`* LIST (\HasNoChildren) "." "testbox"`)
95	imapConn2.ExpectPattern(". OK *")
96}