]> gitweb.factorcode.org Git - factor.git/blob - basis/smtp/smtp-tests.factor
Add support for AUTH PLAIN to smtp library
[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" check-response ] must-fail
22
23 [ ] [ "220 success" check-response ] unit-test
24
25 [ "220 success" ] [
26     "220 success" [ receive-response ] with-string-reader
27 ] unit-test
28
29 [ "220 the end" ] [
30     "220-a multiline response\r\n250-another line\r\n220 the end"
31     [ receive-response ] with-string-reader
32 ] unit-test
33
34 [ ] [
35     "220-a multiline response\r\n250-another line\r\n220 the end"
36     [ get-ok ] with-string-reader
37 ] unit-test
38
39 [
40     "Subject:\r\nsecurity hole" validate-header
41 ] must-fail
42
43 [
44     {
45         { "From" "Doug <erg@factorcode.org>" }
46         { "Subject" "Factor rules" }
47         { "To" "Slava <slava@factorcode.org>, Ed <dharmatech@factorcode.org>" }
48     }
49     { "slava@factorcode.org" "dharmatech@factorcode.org" }
50     "erg@factorcode.org"
51 ] [
52     <email>
53         "Factor rules" >>subject
54         {
55             "Slava <slava@factorcode.org>"
56             "Ed <dharmatech@factorcode.org>"
57         } >>to
58         "Doug <erg@factorcode.org>" >>from
59     [
60         email>headers sort-keys [
61             drop { "Date" "Message-Id" } member? not
62         ] assoc-filter
63     ]
64     [ to>> [ extract-email ] map ]
65     [ from>> extract-email ] tri
66 ] unit-test
67
68 <promise> "p" set
69
70 [ ] [ "p" get mock-smtp-server ] unit-test
71
72 [ ] [
73     [
74         "localhost" "p" get ?promise <inet> smtp-server set
75
76         <email>
77             "Hi guys\nBye guys" >>body
78             "Factor rules" >>subject
79             {
80                 "Slava <slava@factorcode.org>"
81                 "Ed <dharmatech@factorcode.org>"
82             } >>to
83             "Doug <erg@factorcode.org>" >>from
84         send-email
85     ] with-scope
86 ] unit-test