]> gitweb.factorcode.org Git - factor.git/blob - basis/smtp/smtp-tests.factor
Fix smtp tests
[factor.git] / basis / smtp / smtp-tests.factor
1 USING: smtp tools.test io.streams.string io.sockets threads
2 smtp.server kernel sequences namespaces logging accessors
3 assocs sorting smtp.private concurrency.promises ;
4 IN: smtp.tests
5
6 \ send-email must-infer
7
8 { 0 0 } [ [ ] with-smtp-connection ] must-infer-as
9
10 [ "hello\nworld" validate-address ] must-fail
11
12 [ "slava@factorcode.org" ]
13 [ "slava@factorcode.org" validate-address ] unit-test
14
15 [ { "hello" "." "world" } validate-message ] must-fail
16
17 [ "hello\r\nworld\r\n.\r\n" ] [
18     "hello\nworld" [ send-body ] with-string-writer
19 ] unit-test
20
21 [ { "500 syntax error" } <response> check-response ]
22 [ smtp-error? ] must-fail-with
23
24 [ ] [ { "220 success" } <response> check-response ] unit-test
25
26 [ T{ response f 220 { "220 success" } } ] [
27     "220 success" [ receive-response ] with-string-reader
28 ] unit-test
29
30 [
31     T{ response f 220 {
32         "220-a multiline response"
33         "250-another line"
34         "220 the end"
35     } }
36 ] [
37     "220-a multiline response\r\n250-another line\r\n220 the end"
38     [ receive-response ] with-string-reader
39 ] unit-test
40
41 [ ] [
42     "220-a multiline response\r\n250-another line\r\n220 the end"
43     [ get-ok ] with-string-reader
44 ] unit-test
45
46 [
47     "Subject:\r\nsecurity hole" validate-header
48 ] must-fail
49
50 [
51     {
52         { "From" "Doug <erg@factorcode.org>" }
53         { "Subject" "Factor rules" }
54         { "To" "Slava <slava@factorcode.org>, Ed <dharmatech@factorcode.org>" }
55     }
56     { "slava@factorcode.org" "dharmatech@factorcode.org" }
57     "erg@factorcode.org"
58 ] [
59     <email>
60         "Factor rules" >>subject
61         {
62             "Slava <slava@factorcode.org>"
63             "Ed <dharmatech@factorcode.org>"
64         } >>to
65         "Doug <erg@factorcode.org>" >>from
66     [
67         email>headers sort-keys [
68             drop { "Date" "Message-Id" } member? not
69         ] assoc-filter
70     ]
71     [ to>> [ extract-email ] map ]
72     [ from>> extract-email ] tri
73 ] unit-test
74
75 <promise> "p" set
76
77 [ ] [ "p" get mock-smtp-server ] unit-test
78
79 [ ] [
80     <secure-config> f >>verify [
81         "localhost" "p" get ?promise <inet> smtp-server set
82         no-auth smtp-auth set
83         os unix? [ smtp-tls? on ] when
84
85         <email>
86             "Hi guys\nBye guys" >>body
87             "Factor rules" >>subject
88             {
89                 "Slava <slava@factorcode.org>"
90                 "Ed <dharmatech@factorcode.org>"
91             } >>to
92             "Doug <erg@factorcode.org>" >>from
93         send-email
94     ] with-secure-context
95 ] unit-test