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