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