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