Get things compiling, and refactor auth in tests.

This commit is contained in:
Elliot Glaysher 2018-11-15 15:27:49 -08:00
parent 7f64ac3b1f
commit bc1c868e1b
2 changed files with 111 additions and 88 deletions

View File

@ -776,22 +776,19 @@
?~ body.http-request
%^ return-static-data-on-duct 400 'text/html'
(internal-server-error %.y url.http-request ~)
:: parse the incoming body as a json array of +channel-request items
:: if the incoming body isn't json, this is a bad request, 400.
::
=/ request-json=(unit json) ~
::(de-json:html u.body.http-request)
:: if the json doesn't parse, this is a bad request, 400.
::
?~ request-json
?~ maybe-json=(de-json:html q.u.body.http-request)
%^ return-static-data-on-duct 400 'text/html'
(internal-server-error %.y url.http-request ~)
:: parse the json into an array of +channel-request items
::
?~ maybe-requests=(parse-channel-request u.maybe-json)
%^ return-static-data-on-duct 400 'text/html'
(internal-server-error %.y url.http-request ~)
:: while weird, the request list could be empty
::
=/ requests=(list channel-request)
~
::
:: (parse-channel-request request-json)
?: =(~ requests)
?: =(~ u.maybe-requests)
%^ return-static-data-on-duct 400 'text/html'
(internal-server-error %.y url.http-request ~)
:: check for the existence of the uid
@ -803,17 +800,18 @@
::
=/ expiration-time=@da (add now channel-timeout)
%_ ..on-put-request
:: session.channel-state.state
:: %+ ~(put by session.channel-state.state) uid
:: [`expiration-time 0 ~ ~ ~]
session.channel-state.state
%+ ~(put by session.channel-state.state) uid
[`expiration-time 0 ~ ~ ~]
::
moves
:_ moves
^- move
[duct %pass /timeout/[uid] %b %wait expiration-time]
[duct %pass /channel/timeout/[uid] %b %wait expiration-time]
==
:: for each request, execute the action passed in
::
=+ requests=u.maybe-requests
|-
?~ requests
[moves state]
@ -826,7 +824,7 @@
::
:: =. moves
:: :_ moves
:: :^ duct %pass /channel-poke/[uid]
:: :^ duct %pass /channel/poke/[uid]
:: =, i.requests
:: [%g %deal [our ship] app %peel mark %json !>(json)]
::
@ -847,21 +845,20 @@
=/ session
(~(got by session.channel-state.state) uid)
::
:_ state
:: %_ state
:: session.channel-state
:: (~(del by session.channel-state) uid)
:: ==
:_ %_ state
session.channel-state
(~(del by session.channel-state.state) uid)
==
:: produce a list of moves which cancels every gall subscription
::
:: %+ turn subscriptions.session
:: |= [ship=@p app=term =wire =path]
:: ^- move
:: :: todo: double check this; which duct should we be canceling on? does
:: :: gall strongly bind to a duct as a cause like ford does?
:: ::
:: [duct %pass [%g %deal [our ship] app %pull ~]]
~
%+ turn subscriptions.session
|= [ship=@p app=term =wire =path]
^- move
:: todo: double check this; which duct should we be canceling on? does
:: gall strongly bind to a duct as a cause like ford does?
::
:^ duct %pass /channel/subscribe/[uid]
[%g %deal [our ship] app %pull ~]
--
:: +handle-ford-response: translates a ford response for the outside world
::

View File

@ -464,71 +464,17 @@
:: the browser then fetches the login page
::
=^ results5 light-gate
%- light-call :*
%- perform-authentication :*
light-gate
now=~1111.1.5
scry=*sley
^= call-args
:* duct=~[/http-blah] ~
%inbound-request
%.n
[%ipv4 .192.168.1.1]
[%'GET' '/~/login?redirect=/~landscape/inner-path' ~ ~]
==
^= expected-moves
^- (list move:light-gate)
:~ :* duct=~[/http-blah]
%give
%http-response
%start
200
:~ ['content-type' 'text/html']
['content-length' '348']
==
[~ (login-page:light-gate `'/~landscape/inner-path')]
complete=%.y
== ==
==
:: a response post redirects back to the application, setting cookie
::
=^ results6 light-gate
%- light-call :*
light-gate
now=~1111.1.6
scry=*sley
^= call-args
:* duct=~[/http-blah] ~
%inbound-request
%.n
[%ipv4 .192.168.1.1]
%'POST'
'/~/login'
~
:- ~
%- as-octs:mimes:html
'password=lidlut-tabwed-pillex-ridrup&redirect=/~landscape'
==
^= expected-moves
^- (list move:light-gate)
:~ :* duct=~[/http-blah]
%give
%http-response
%start
307
:~ ['location' '/~landscape']
:- 'set-cookie'
'urbauth=0v3.q0p7t.mlkkq.cqtto.p0nvi.2ieea; Path=/; Max-Age=86400'
==
~
complete=%.y
== ==
==
:: going back to the original url will acknowledge the authentication cookie
::
=^ results7 light-gate
=^ results6 light-gate
%- light-call-with-comparator :*
light-gate
now=~1111.1.6..1.0.0
now=~1111.1.5..1.0.0
scry=*sley
^= call-args
^- [=duct type=* wrapped-task=(hobo task:able:light-gate)]
@ -561,7 +507,15 @@
:+ /run-app/app1 [~nul ~nul]
^- cush:gall
:* %app1 %poke %handle-http-request
!>([%.y %.n [%ipv4 .192.168.1.1] ['GET' '/~landscape/inner-path' ~ ~]])
!> :*
%.y
%.n
[%ipv4 .192.168.1.1]
:* %'GET'
'/~landscape/inner-path'
['cookie' 'urbauth=0v3.q0p7t.mlkkq.cqtto.p0nvi.2ieea']~
~
== ==
==
card
==
@ -729,7 +683,6 @@
"path": "/other"}]
'''
::
:: after lunch, check error conditions and multipart requests.
%+ expect-eq
!> ~
!> %- parse-channel-request:light-gate
@ -872,4 +825,77 @@
:: compare the payload vases
::
(expect-eq q.p.q.data.expected q.p.q.data.note)
:: +perform-authentication: goes through the authentication flow
::
++ perform-authentication
|= $: light-gate=_light-gate
start-now=@da
scry=sley
==
^- [tang _light-gate]
:: the browser then fetches the login page
::
=^ results1 light-gate
%- light-call :*
light-gate
now=start-now
scry=*sley
^= call-args
:* duct=~[/http-blah] ~
%inbound-request
%.n
[%ipv4 .192.168.1.1]
[%'GET' '/~/login?redirect=/~landscape/inner-path' ~ ~]
==
^= expected-moves
^- (list move:light-gate)
:~ :* duct=~[/http-blah]
%give
%http-response
%start
200
:~ ['content-type' 'text/html']
['content-length' '348']
==
[~ (login-page:light-gate `'/~landscape/inner-path')]
complete=%.y
== ==
==
:: a response post redirects back to the application, setting cookie
::
=^ results2 light-gate
%- light-call :*
light-gate
now=(add start-now ~m1)
scry=*sley
^= call-args
:* duct=~[/http-blah] ~
%inbound-request
%.n
[%ipv4 .192.168.1.1]
%'POST'
'/~/login'
~
:- ~
%- as-octs:mimes:html
'password=lidlut-tabwed-pillex-ridrup&redirect=/~landscape'
==
^= expected-moves
^- (list move:light-gate)
:~ :* duct=~[/http-blah]
%give
%http-response
%start
307
:~ ['location' '/~landscape']
:- 'set-cookie'
'urbauth=0v3.q0p7t.mlkkq.cqtto.p0nvi.2ieea; Path=/; Max-Age=86400'
==
~
complete=%.y
== ==
==
::
:_ light-gate
(weld results1 results2)
--