]> gitweb.factorcode.org Git - factor.git/blob - basis/smtp/smtp-tests.factor
smtp: removing unused test.
[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 [ "aGVsbG8Kd29ybGQ=\r\n.\r\n" ] [
15     T{ email { body "hello\nworld" } } [ send-body ] with-string-writer
16 ] unit-test
17
18 [ { "500 syntax error" } <response> check-response ]
19 [ smtp-error? ] must-fail-with
20
21 [ ] [ { "220 success" } <response> check-response ] unit-test
22
23 [ T{ response f 220 { "220 success" } } ] [
24     "220 success" [ receive-response ] with-string-reader
25 ] unit-test
26
27 [
28     T{ response f 220 {
29         "220-a multiline response"
30         "250-another line"
31         "220 the end"
32     } }
33 ] [
34     "220-a multiline response\r\n250-another line\r\n220 the end"
35     [ receive-response ] with-string-reader
36 ] unit-test
37
38 [ ] [
39     "220-a multiline response\r\n250-another line\r\n220 the end"
40     [ get-ok ] with-string-reader
41 ] unit-test
42
43 [
44     "Subject:\r\nsecurity hole" validate-header
45 ] must-fail
46
47 [
48     {
49         { "Content-Transfer-Encoding" "base64" }
50         { "Content-Type" "text/plain; charset=UTF-8" }
51         { "From" "Doug <erg@factorcode.org>" }
52         { "MIME-Version" "1.0" }
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