1 IN: furnace.sessions.tests
\r
2 USING: tools.test http furnace.sessions furnace.actions
\r
3 http.server http.server.responses math namespaces make kernel
\r
4 accessors io.sockets io.servers.connection prettyprint
\r
5 io.streams.string io.files splitting destructors sequences db
\r
6 db.tuples db.sqlite continuations urls math.parser furnace ;
\r
10 [ [ save-session-after ] [ session set ] bi ] dip call
\r
11 ] with-destructors ; inline
\r
17 M: foo init-session* drop 0 "x" sset ;
\r
19 M: foo call-responder*
\r
22 "x" sget number>string "text/html" <content> ;
\r
24 : url-responder-mock-test
\r
29 "id" get session-id-key set-query-param
\r
32 { } sessions get call-responder
\r
33 [ write-response-body drop ] with-string-writer
\r
34 ] with-destructors ;
\r
36 : sessions-mock-test
\r
40 "cookies" get >>cookies
\r
41 dup url>> "/" >>path drop
\r
43 { } sessions get call-responder
\r
44 [ write-response-body drop ] with-string-writer
\r
45 ] with-destructors ;
\r
49 [ [ ] "text/plain" <content> exit-with ] >>display ;
\r
51 [ "auth-test.db" temp-file sqlite-db delete-file ] ignore-errors
\r
53 "auth-test.db" temp-file sqlite-db [
\r
55 <request> init-request
\r
56 session ensure-table
\r
58 "127.0.0.1" 1234 <inet4> remote-address set
\r
68 123 >>id session set
\r
71 [ ] [ 3 "x" sset ] unit-test
\r
73 [ 9 ] [ "x" sget sq ] unit-test
\r
75 [ ] [ "x" [ 1- ] schange ] unit-test
\r
77 [ 4 ] [ "x" sget sq ] unit-test
\r
79 [ t ] [ session get changed?>> ] unit-test
\r
84 get-session session?
\r
90 dup [ 5 "a" sset ] with-session
\r
91 dup [ "a" sget , ] with-session
\r
92 dup [ "x" sget , ] with-session
\r
99 get-session [ "x" sget ] with-session
\r
105 dup get-session [ 5 "a" sset ] with-session
\r
106 dup get-session [ "a" sget , ] with-session
\r
107 dup get-session [ "x" sget , ] with-session
\r
120 dup url>> "/" >>path drop
\r
122 { "etc" } sessions get call-responder response set
\r
123 [ "1" ] [ [ response get write-response-body drop ] with-string-writer ] unit-test
\r
128 [ ] [ response get cookies>> "cookies" set ] unit-test
\r
130 [ "2" ] [ sessions-mock-test ] unit-test
\r
131 [ "3" ] [ sessions-mock-test ] unit-test
\r
132 [ "4" ] [ sessions-mock-test ] unit-test
\r
139 "id" get session-id-key set-query-param
\r
144 { } <exiting-action> <sessions>
\r
146 ] with-destructors response set
\r
149 [ "text/plain" ] [ response get content-type>> ] unit-test
\r
151 [ f ] [ response get cookies>> empty? ] unit-test
\r