1 USING: tools.test http furnace.sessions furnace.actions
2 http.server http.server.responses math namespaces make kernel
3 accessors io.sockets io.servers prettyprint
4 io.streams.string io.files io.files.temp io.directories
5 splitting destructors sequences db db.tuples db.sqlite
6 continuations urls math.parser furnace furnace.utilities ;
7 IN: furnace.sessions.tests
9 : with-session ( session quot -- )
11 [ [ save-session-after ] [ session set ] bi ] dip call
12 ] with-destructors ; inline
18 M: foo init-session* drop 0 "x" sset ;
20 M: foo call-responder*
23 "x" sget number>string <html-content> ;
25 : url-responder-mock-test ( -- string )
30 "id" get session-id-key set-query-param
33 { } sessions get call-responder
34 [ write-response-body drop ] with-string-writer
37 : sessions-mock-test ( -- string )
41 "cookies" get >>cookies
42 dup url>> "/" >>path drop
44 { } sessions get call-responder
45 [ write-response-body drop ] with-string-writer
48 : <exiting-action> ( -- action )
50 [ [ ] <text-content> exit-with ] >>display ;
52 [ "auth-test.db" temp-file delete-file ] ignore-errors
54 "auth-test.db" temp-file <sqlite-db> [
56 <request> "GET" >>method init-request
59 "127.0.0.1" 1234 <inet4> remote-address set
72 [ ] [ 3 "x" sset ] unit-test
74 [ 9 ] [ "x" sget sq ] unit-test
76 [ ] [ "x" [ 1 - ] schange ] unit-test
78 [ 4 ] [ "x" sget sq ] unit-test
80 [ t ] [ session get changed?>> ] unit-test
91 dup [ 5 "a" sset ] with-session
92 dup [ "a" sget , ] with-session
93 dup [ "x" sget , ] with-session
100 get-session [ "x" sget ] with-session
106 dup get-session [ 5 "a" sset ] with-session
107 dup get-session [ "a" sget , ] with-session
108 dup get-session [ "x" sget , ] with-session
121 dup url>> "/" >>path drop
123 { "etc" } sessions get call-responder response set
124 [ "1" ] [ [ response get write-response-body drop ] with-string-writer ] unit-test
129 [ ] [ response get cookies>> "cookies" set ] unit-test
131 [ "2" ] [ sessions-mock-test ] unit-test
132 [ "3" ] [ sessions-mock-test ] unit-test
133 [ "4" ] [ sessions-mock-test ] unit-test
140 "id" get session-id-key set-query-param
145 { } <exiting-action> <sessions>
147 ] with-destructors response set
150 [ "text/plain" ] [ response get content-type>> ] unit-test
152 [ f ] [ response get cookies>> empty? ] unit-test