]> gitweb.factorcode.org Git - factor.git/blob - basis/smtp/smtp-tests.factor
Merge branch 'master' of git://repo.or.cz/factor/jcg
[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 ;
4 IN: smtp.tests
5
6 [ t ] [
7     <email>
8     dup clone "a" "b" set-header drop
9     headers>> assoc-empty?
10 ] unit-test
11
12 { 0 0 } [ [ ] with-smtp-connection ] must-infer-as
13
14 [ "hello\nworld" validate-address ] must-fail
15
16 [ "slava@factorcode.org" ]
17 [ "slava@factorcode.org" validate-address ] unit-test
18
19 [ { "hello" "." "world" } validate-message ] must-fail
20
21 [ "hello\r\nworld\r\n.\r\n" ] [
22     "hello\nworld" [ send-body ] with-string-writer
23 ] unit-test
24
25 [ "500 syntax error" check-response ] must-fail
26
27 [ ] [ "220 success" check-response ] unit-test
28
29 [ "220 success" ] [
30     "220 success" [ receive-response ] with-string-reader
31 ] unit-test
32
33 [ "220 the end" ] [
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         { "From" "Doug <erg@factorcode.org>" }
50         { "Subject" "Factor rules" }
51         { "To" "Slava <slava@factorcode.org>, Ed <dharmatech@factorcode.org>" }
52     }
53     { "slava@factorcode.org" "dharmatech@factorcode.org" }
54     "erg@factorcode.org"
55 ] [
56     <email>
57         "Factor rules" >>subject
58         {
59             "Slava <slava@factorcode.org>"
60             "Ed <dharmatech@factorcode.org>"
61         } >>to
62         "Doug <erg@factorcode.org>" >>from
63     prepare
64     dup headers>> >alist sort-keys [
65         drop { "Date" "Message-Id" } member? not
66     ] assoc-filter
67     over to>>
68     rot from>>
69 ] unit-test
70
71 [ ] [ [ 4321 mock-smtp-server ] "SMTP server" spawn drop ] unit-test
72
73 [ ] [ yield ] unit-test
74
75 [ ] [
76     [
77         "localhost" 4321 <inet> smtp-server set
78
79         <email>
80             "Hi guys\nBye guys" >>body
81             "Factor rules" >>subject
82             {
83                 "Slava <slava@factorcode.org>"
84                 "Ed <dharmatech@factorcode.org>"
85             } >>to
86             "Doug <erg@factorcode.org>" >>from
87         send-email
88     ] with-scope
89 ] unit-test
90
91 [ ] [ yield ] unit-test