shrub/tests/sys/vane/eyre.hoon

2352 lines
62 KiB
Plaintext
Raw Normal View History

2020-05-14 10:22:39 +03:00
/+ *test
2020-05-08 08:29:25 +03:00
/= eyre-raw /sys/vane/eyre
2018-09-20 02:29:36 +03:00
::
!:
2020-12-06 11:38:37 +03:00
=/ eyre-gate (eyre-raw ~nul)
2019-11-14 06:38:13 +03:00
=/ eyre-id '~.eyre_0v4.elsnk.20412.0h04v.50lom.5lq0o'
2018-09-20 02:29:36 +03:00
::
|%
++ test-init
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-20 02:29:36 +03:00
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
2018-09-20 02:29:36 +03:00
expected-moves=~
==
::
results1
::
2021-09-25 16:16:39 +03:00
++ test-overwrite-bindings
2018-09-20 02:29:36 +03:00
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-20 02:29:36 +03:00
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
2018-09-20 02:29:36 +03:00
expected-moves=~
==
:: app1 binds successfully
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-20 02:29:36 +03:00
now=~1111.1.2
scry=scry-provides-code
call-args=[duct=~[/app1] ~ [%connect [~ /] %app1]]
expected-moves=[duct=~[/app1] %give %bound %.y [~ /]]~
2018-09-20 02:29:36 +03:00
==
2021-09-25 16:16:39 +03:00
:: app2 tries to bind to the same path and succeeds
2018-09-20 02:29:36 +03:00
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-20 02:29:36 +03:00
now=~1111.1.3
scry=scry-provides-code
call-args=[duct=~[/app2] ~ [%connect [~ /] %app2]]
2021-09-25 16:16:39 +03:00
expected-moves=[duct=~[/app2] %give %bound %.y [~ /]]~
2018-09-20 02:29:36 +03:00
==
::
;: weld
results1
results2
results3
==
::
++ test-remove-binding
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-20 02:29:36 +03:00
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
2018-09-20 02:29:36 +03:00
expected-moves=~
==
:: app1 binds successfully
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-20 02:29:36 +03:00
now=~1111.1.2
scry=scry-provides-code
call-args=[duct=~[/app1] ~ [%connect [~ /] %app1]]
expected-moves=[duct=~[/app1] %give %bound %.y [~ /]]~
2018-09-20 02:29:36 +03:00
==
:: app1 unbinds
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-20 02:29:36 +03:00
now=~1111.1.3
scry=scry-provides-code
call-args=[duct=~[/app1] ~ [%disconnect [~ /]]]
2018-09-20 02:29:36 +03:00
expected-moves=~
==
:: app2 binds successfully
::
2020-05-08 08:29:25 +03:00
=^ results4 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-20 02:29:36 +03:00
now=~1111.1.4
scry=scry-provides-code
call-args=[duct=~[/app2] ~ [%connect [~ /] %app2]]
expected-moves=[duct=~[/app2] %give %bound %.y [~ /]]~
2018-09-20 02:29:36 +03:00
==
::
;: weld
results1
results2
results3
results4
==
::
++ test-host-matching
;: weld
::
%+ expect-eq
!>(%.y)
2020-05-08 08:29:25 +03:00
!>((host-matches:eyre-gate ~ `'example.com'))
::
%+ expect-eq
!>(%.y)
2020-05-08 08:29:25 +03:00
!>((host-matches:eyre-gate ~ ~))
::
%+ expect-eq
!>(%.n)
2020-05-08 08:29:25 +03:00
!>((host-matches:eyre-gate `'example.com' ~))
::
%+ expect-eq
!>(%.y)
2020-05-08 08:29:25 +03:00
!>((host-matches:eyre-gate `'example.com' `'example.com'))
::
%+ expect-eq
!>(%.n)
2020-05-08 08:29:25 +03:00
!>((host-matches:eyre-gate `'example.com' `'blah.com'))
==
2018-09-21 02:36:04 +03:00
:: tests that when we have no match, that we fall back to the built-in 404
2018-09-20 02:29:36 +03:00
::
2018-09-21 02:36:04 +03:00
++ test-builtin-four-oh-four
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-21 02:36:04 +03:00
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
2018-09-21 02:36:04 +03:00
expected-moves=~
==
:: when there's no configuration and nothing matches, expect 404
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-21 02:36:04 +03:00
now=~1111.1.1
scry=scry-provides-code
2018-09-21 02:36:04 +03:00
^= call-args
:* duct=~[/http-blah] ~
%request
2018-09-21 02:36:04 +03:00
%.n
[%ipv4 .192.168.1.1]
[%'GET' '/' ~ ~]
2018-09-21 02:36:04 +03:00
==
^= expectec-moves
2020-05-08 08:29:25 +03:00
^- (list move:eyre-gate)
2018-09-21 02:36:04 +03:00
:~ :* duct=~[/http-blah]
%give
%response
2018-09-21 02:36:04 +03:00
%start
::
%+ complete-http-start-event
:- 404
['content-type' 'text/html']~
2020-05-08 08:29:25 +03:00
[~ (error-page:eyre-gate 404 %.n '/' ~)]
2018-09-21 02:36:04 +03:00
== ==
==
::
;: weld
results1
results2
==
::
++ test-basic-app-request
2018-09-20 02:29:36 +03:00
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-20 02:29:36 +03:00
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
2018-09-20 02:29:36 +03:00
expected-moves=~
==
:: app1 binds successfully
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-20 02:29:36 +03:00
now=~1111.1.2
scry=scry-provides-code
call-args=[duct=~[/app1] ~ [%connect [~ /] %app1]]
expected-moves=[duct=~[/app1] %give %bound %.y [~ /]]~
2018-09-20 02:29:36 +03:00
==
2018-09-21 02:36:04 +03:00
:: outside requests a path that app1 has bound to
2018-09-20 02:29:36 +03:00
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
2018-09-20 02:29:36 +03:00
now=~1111.1.3
scry=scry-provides-code
2018-09-21 02:36:04 +03:00
^= call-args
:* duct=~[/http-blah] ~
%request
2018-09-21 02:36:04 +03:00
%.n
[%ipv4 .192.168.1.1]
[%'GET' '/' ~ ~]
2018-09-21 02:36:04 +03:00
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
2018-09-21 02:36:04 +03:00
^- tang
::
2019-11-14 06:38:13 +03:00
?. ?=([* * ~] moves)
2018-09-21 02:36:04 +03:00
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
::
2020-05-08 08:29:25 +03:00
=/ move-1=move:eyre-gate i.moves
=/ move-2=move:eyre-gate i.t.moves
2018-09-21 02:36:04 +03:00
::
%+ weld
2019-11-14 06:38:13 +03:00
(expect-eq !>(~[/http-blah]) !>(duct.move-1))
%+ weld
(expect-eq !>(~[/http-blah]) !>(duct.move-2))
::
%+ weld
%+ expect-gall-deal
:+ /watch-response/[eyre-id]
[~nul ~nul]
:* %app1 %watch
/http-response/[eyre-id]
==
card.move-1
2018-09-21 02:36:04 +03:00
::
%+ expect-gall-deal
2019-11-14 06:38:13 +03:00
:+ /run-app-request/[eyre-id] [~nul ~nul]
2018-09-21 02:36:04 +03:00
:* %app1 %poke %handle-http-request
2019-11-14 06:38:13 +03:00
!>([eyre-id %.n %.n [%ipv4 .192.168.1.1] [%'GET' '/' ~ ~]])
2018-09-21 02:36:04 +03:00
==
2019-11-14 06:38:13 +03:00
card.move-2
2018-09-20 02:29:36 +03:00
==
2019-11-14 06:38:13 +03:00
:: theoretical outside response
::
2020-05-08 08:29:25 +03:00
=^ results4 eyre-gate
%- eyre-take :*
eyre-gate
2019-11-14 06:38:13 +03:00
now=~1111.1.4
scry=scry-provides-code
^= take-args
:* wire=/watch-response/[eyre-id] duct=~[/http-blah]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
:* %gall %unto %fact
2019-11-14 06:38:13 +03:00
%http-response-header
!>([200 ['content-type' 'text/html']~])
==
==
^= expected-move
:~ :* duct=~[/http-blah] %give %response
[%start [200 ['content-type' 'text/html']~] ~ %.n]
== == ==
2020-01-04 00:06:42 +03:00
2018-09-20 02:29:36 +03:00
;: weld
results1
results2
results3
2019-11-14 06:38:13 +03:00
:: results4
2018-09-20 02:29:36 +03:00
==
::
++ test-app-error
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
expected-moves=~
==
:: app1 binds successfully
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call :*
eyre-gate
now=~1111.1.2
scry=scry-provides-code
call-args=[duct=~[/app1] ~ [%connect [~ /] %app1]]
expected-moves=[duct=~[/app1] %give %bound %.y [~ /]]~
==
:: outside requests a path that app1 has bound to
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
now=~1111.1.3
scry=scry-provides-code
^= call-args
:* duct=~[/http-blah] ~
%request
%.n
[%ipv4 .192.168.1.1]
[%'GET' '/' ~ ~]
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
^- tang
::
2019-11-14 06:38:13 +03:00
?. ?=([* * ~] moves)
[[%leaf "wrong number of moves: {<(lent moves)>}"] >moves< ~]
::
::
2020-05-08 08:29:25 +03:00
=/ move-1=move:eyre-gate i.moves
=/ move-2=move:eyre-gate i.t.moves
::
%+ weld
2019-11-14 06:38:13 +03:00
(expect-eq !>(~[/http-blah]) !>(duct.move-1))
%+ weld
(expect-eq !>(~[/http-blah]) !>(duct.move-2))
::
%+ weld
%+ expect-gall-deal
:+ /watch-response/[eyre-id]
[~nul ~nul]
:* %app1 %watch
/http-response/[eyre-id]
==
card.move-1
::
%+ expect-gall-deal
2019-11-14 06:38:13 +03:00
:+ /run-app-request/[eyre-id]
[~nul ~nul]
:* %app1 %poke %handle-http-request
!>([eyre-id %.n %.n [%ipv4 .192.168.1.1] [%'GET' '/' ~ ~]])
==
card.move-2
==
:: the poke fails. we should relay this to the client
::
2020-05-08 08:29:25 +03:00
=^ results4 eyre-gate
%- eyre-take :*
eyre-gate
now=~1111.1.4
scry=scry-provides-code
^= take-args
:* wire=/run-app-request/app1 duct=~[/http-blah]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
:* %gall %unto %poke-ack ~
:~ [%leaf "/~zod/...../app1:<[1 1].[1 20]>"]
== ==
==
^= expected-move
2019-11-14 06:38:13 +03:00
:~ :* duct=~[/http-blah] %pass
/watch-response/[eyre-id]
2019-11-19 07:36:21 +03:00
%g %deal [~nul ~nul] %app1 %leave ~
2019-11-14 06:38:13 +03:00
==
::
:* duct=~[/http-blah] %give %response
%start
::
%+ complete-http-start-event
:- 500
['content-type' 'text/html']~
2020-05-08 08:29:25 +03:00
[~ (internal-server-error:eyre-gate %.n '/' ~)]
== == ==
::
;: weld
results1
results2
results3
results4
==
::
2018-09-25 00:16:15 +03:00
++ test-multipart-app-request
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-25 00:16:15 +03:00
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
2018-09-25 00:16:15 +03:00
expected-moves=~
==
:: app1 binds successfully
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-25 00:16:15 +03:00
now=~1111.1.2
scry=scry-provides-code
call-args=[duct=~[/app1] ~ [%connect [~ /] %app1]]
expected-moves=[duct=~[/app1] %give %bound %.y [~ /]]~
2018-09-25 00:16:15 +03:00
==
:: outside requests a path that app1 has bound to
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
2018-09-25 00:16:15 +03:00
now=~1111.1.3
scry=scry-provides-code
2018-09-25 00:16:15 +03:00
^= call-args
:* duct=~[/http-blah] ~
%request
2018-09-25 00:16:15 +03:00
%.n
[%ipv4 .192.168.1.1]
[%'GET' '/' ~ ~]
2018-09-25 00:16:15 +03:00
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
2018-09-25 00:16:15 +03:00
^- tang
::
2019-11-14 06:38:13 +03:00
?. ?=([* * ~] moves)
2018-09-25 00:16:15 +03:00
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
::
2020-05-08 08:29:25 +03:00
=/ move-1=move:eyre-gate i.moves
=/ move-2=move:eyre-gate i.t.moves
2018-09-25 00:16:15 +03:00
::
%+ weld
2019-11-14 06:38:13 +03:00
(expect-eq !>(~[/http-blah]) !>(duct.move-1))
%+ weld
(expect-eq !>(~[/http-blah]) !>(duct.move-2))
::
%+ weld
%+ expect-gall-deal
:+ /watch-response/[eyre-id]
[~nul ~nul]
:* %app1 %watch
/http-response/[eyre-id]
==
card.move-1
2018-09-25 00:16:15 +03:00
::
%+ expect-gall-deal
2019-11-14 06:38:13 +03:00
:+ /run-app-request/[eyre-id] [~nul ~nul]
2018-09-25 00:16:15 +03:00
:* %app1 %poke %handle-http-request
2019-11-14 06:38:13 +03:00
!>([eyre-id %.n %.n [%ipv4 .192.168.1.1] [%'GET' '/' ~ ~]])
2018-09-25 00:16:15 +03:00
==
2019-11-14 06:38:13 +03:00
card.move-2
2018-09-25 00:16:15 +03:00
==
:: theoretical outside response
::
2020-05-08 08:29:25 +03:00
=^ results4 eyre-gate
%- eyre-take :*
eyre-gate
2018-09-25 00:16:15 +03:00
now=~1111.1.4
scry=scry-provides-code
2018-09-25 00:16:15 +03:00
^= take-args
2019-11-14 06:38:13 +03:00
:* wire=/watch-response/[eyre-id] duct=~[/http-blah]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
:* %gall %unto %fact
2019-11-14 06:38:13 +03:00
%http-response-header
!>([200 ['content-type' 'text/html']~])
==
2018-09-25 00:16:15 +03:00
==
^= expected-move
:~ :* duct=~[/http-blah] %give %response
2019-11-14 06:38:13 +03:00
[%start [200 ['content-type' 'text/html']~] ~ %.n]
2018-09-25 00:16:15 +03:00
== == ==
:: theoretical outside response
::
2020-05-08 08:29:25 +03:00
=^ results5 eyre-gate
%- eyre-take :*
eyre-gate
2018-09-25 00:16:15 +03:00
now=~1111.1.4
scry=scry-provides-code
2018-09-25 00:16:15 +03:00
^= take-args
2019-11-14 06:38:13 +03:00
:* wire=/watch-response/[eyre-id] duct=~[/http-blah]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
:* %gall %unto %fact
2019-11-14 06:38:13 +03:00
%http-response-data
!>(`(as-octs:mimes:html 'ya!'))
==
2018-09-25 00:16:15 +03:00
==
^= expected-move
:~ :* duct=~[/http-blah] %give %response
2019-11-14 06:38:13 +03:00
[%continue `[3 'ya!'] %.n]
2018-09-25 00:16:15 +03:00
== == ==
::
;: weld
results1
results2
results3
results4
results5
==
2018-09-27 02:18:40 +03:00
:: tests an app redirecting to the login handler, which then receives a post
:: and redirects back to app
::
++ test-login-handler-full-path
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-27 02:18:40 +03:00
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
2018-09-27 02:18:40 +03:00
expected-moves=~
==
:: app1 binds successfully
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call :*
eyre-gate
2018-09-27 02:18:40 +03:00
now=~1111.1.2
scry=scry-provides-code
call-args=[duct=~[/app1] ~ [%connect [~ /'~landscape'] %app1]]
expected-moves=[duct=~[/app1] %give %bound %.y [~ /'~landscape']]~
2018-09-27 02:18:40 +03:00
==
:: outside requests a path that app1 has bound to
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
2018-09-27 02:18:40 +03:00
now=~1111.1.3
scry=scry-provides-code
2018-09-27 02:18:40 +03:00
^= call-args
:* duct=~[/http-blah] ~
%request
2018-09-27 02:18:40 +03:00
%.n
[%ipv4 .192.168.1.1]
[%'GET' '/~landscape/inner-path' ~ ~]
2018-09-27 02:18:40 +03:00
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
2018-09-27 02:18:40 +03:00
^- tang
::
2019-11-14 06:38:13 +03:00
?. ?=([* * ~] moves)
2018-09-27 02:18:40 +03:00
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
::
2020-05-08 08:29:25 +03:00
=/ move-1=move:eyre-gate i.moves
=/ move-2=move:eyre-gate i.t.moves
2018-09-27 02:18:40 +03:00
::
%+ weld
2019-11-14 06:38:13 +03:00
(expect-eq !>(~[/http-blah]) !>(duct.move-1))
%+ weld
(expect-eq !>(~[/http-blah]) !>(duct.move-2))
::
%+ weld
%+ expect-gall-deal
:+ /watch-response/[eyre-id]
[~nul ~nul]
:* %app1 %watch
/http-response/[eyre-id]
==
card.move-1
2018-09-27 02:18:40 +03:00
::
%+ expect-gall-deal
2019-11-14 06:38:13 +03:00
:+ /run-app-request/[eyre-id] [~nul ~nul]
2018-09-27 02:18:40 +03:00
:* %app1 %poke %handle-http-request
2019-11-14 06:38:13 +03:00
!>([eyre-id %.n %.n [%ipv4 .192.168.1.1] [%'GET' '/~landscape/inner-path' ~ ~]])
2018-09-27 02:18:40 +03:00
==
2019-11-14 06:38:13 +03:00
card.move-2
2018-09-27 02:18:40 +03:00
==
:: app then gives a redirect to Eyre
::
2020-05-08 08:29:25 +03:00
=^ results4 eyre-gate
%- eyre-take :*
eyre-gate
2018-09-27 02:18:40 +03:00
now=~1111.1.4
scry=scry-provides-code
2018-09-27 02:18:40 +03:00
^= take-args
2019-11-14 06:38:13 +03:00
:* wire=/watch-response/[eyre-id] duct=~[/http-blah]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
:* %gall %unto %fact
2019-11-14 06:38:13 +03:00
%http-response-header
!>([303 ['location' '/~/login?redirect=/~landscape/inner-path']~])
==
2018-09-27 02:18:40 +03:00
==
^= expected-move
:~ :* duct=~[/http-blah] %give %response
[%start [303 ['location' '/~/login?redirect=/~landscape/inner-path']~] ~ %.n]
2018-09-27 02:18:40 +03:00
== == ==
:: the browser then fetches the login page
::
2020-05-08 08:29:25 +03:00
=^ results5 eyre-gate
%- perform-authentication :*
2020-05-08 08:29:25 +03:00
eyre-gate
now=~1111.1.5
scry=scry-provides-code
2018-09-27 02:18:40 +03:00
==
:: going back to the original url will acknowledge the authentication cookie
::
2020-05-08 08:29:25 +03:00
=^ results6 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
now=~1111.1.5..1.0.0
scry=scry-provides-code
^= call-args
2020-12-08 03:47:06 +03:00
^- [=duct (unit goof) wrapped-task=(hobo task:eyre-gate)]
:* duct=~[/http-blah] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'GET'
'/~landscape/inner-path'
['cookie' cookie-value]~
~
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
^- tang
::
2019-11-14 06:38:13 +03:00
?. ?=([* * ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
::
2020-05-08 08:29:25 +03:00
=/ move-1=move:eyre-gate i.moves
=/ move-2=move:eyre-gate i.t.moves
::
%+ weld
2019-11-14 06:38:13 +03:00
(expect-eq !>(~[/http-blah]) !>(duct.move-1))
%+ weld
(expect-eq !>(~[/http-blah]) !>(duct.move-2))
::
%+ weld
%+ expect-gall-deal
:+ /watch-response/[eyre-id]
[~nul ~nul]
:* %app1 %watch
/http-response/[eyre-id]
==
card.move-1
::
:: expect authenticated=%.y in the handle below
::
%+ expect-gall-deal
2019-11-14 06:38:13 +03:00
:+ /run-app-request/[eyre-id] [~nul ~nul]
:* %app1 %poke %handle-http-request
!> :*
2019-11-14 06:38:13 +03:00
eyre-id
%.y
%.n
[%ipv4 .192.168.1.1]
:* %'GET'
'/~landscape/inner-path'
['cookie' cookie-value]~
~
== ==
==
2019-11-14 06:38:13 +03:00
card.move-2
==
2018-09-27 02:18:40 +03:00
::
;: weld
results1
results2
results3
results4
results5
results6
==
2018-09-25 00:16:15 +03:00
::
++ test-generator
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
expected-moves=~
==
:: gen1 binds successfully
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call :*
eyre-gate
now=~1111.1.2
scry=scry-provides-code
call-args=[duct=~[/gen1] ~ [%serve [~ /] [%base /gen/handler/hoon ~]]]
expected-moves=[duct=~[/gen1] %give %bound %.y [~ /]]~
==
:: outside requests a path that app1 has bound to
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-call :*
eyre-gate
now=~1111.1.3
scry=scry-provides-code
^= call-args
:* duct=~[/http-blah] ~
%request
%.n
[%ipv4 .192.168.1.1]
[%'GET' '/' ~ ~]
==
2020-05-08 08:29:25 +03:00
^= expected-moves
:~ :+ ~[/http-blah] %give
[%response %start [404 headers=~] data=~ complete=%.y]
==
==
::
;: weld
results1
results2
results3
==
::
2018-10-04 00:05:36 +03:00
++ test-simplified-url-parser
;: weld
%+ expect-eq
!> `[[%site 'localhost'] [~ 8.000]]
2020-05-08 08:29:25 +03:00
!> (rush 'localhost:8000' simplified-url-parser:eyre-gate)
2018-10-04 00:05:36 +03:00
::
%+ expect-eq
!> `[[%ip .192.168.1.1] ~]
2020-05-08 08:29:25 +03:00
!> (rush '192.168.1.1' simplified-url-parser:eyre-gate)
2018-10-04 00:05:36 +03:00
==
::
2018-11-16 00:43:10 +03:00
++ test-parse-channel-request
;: weld
%+ expect-eq
!> `[%ack 5]~
2020-05-08 08:29:25 +03:00
!> %- parse-channel-request:eyre-gate
(need (de-json:html '[{"action": "ack", "event-id": 5}]'))
2018-11-16 00:43:10 +03:00
::
%+ expect-eq
!> `[%poke 0 ~nec %app1 %app-type [%n '5']]~
2020-05-08 08:29:25 +03:00
!> %- parse-channel-request:eyre-gate
2018-11-16 00:43:10 +03:00
%- need %- de-json:html
'''
[{"action": "poke",
"id": 0,
2018-11-16 00:43:10 +03:00
"ship": "nec",
"app": "app1",
"mark": "app-type",
"json": 5}]
'''
::
%+ expect-eq
!> `[%subscribe 1 ~sampyl-sipnym %hall /this/path]~
2020-05-08 08:29:25 +03:00
!> %- parse-channel-request:eyre-gate
2018-11-16 00:43:10 +03:00
%- need %- de-json:html
'''
[{"action": "subscribe",
"id": 1,
2018-11-16 00:43:10 +03:00
"ship": "sampyl-sipnym",
"app": "hall",
"path": "/this/path"}]
'''
::
%+ expect-eq
!> `[%unsubscribe 2 1]~
2020-05-08 08:29:25 +03:00
!> %- parse-channel-request:eyre-gate
2018-11-16 00:43:10 +03:00
%- need %- de-json:html
'''
[{"action": "unsubscribe",
"id": 2,
"subscription": 1}]
2018-11-16 00:43:10 +03:00
'''
::
%+ expect-eq
!> ~
2020-05-08 08:29:25 +03:00
!> %- parse-channel-request:eyre-gate
2018-11-16 00:43:10 +03:00
%- need %- de-json:html
'[{"noaction": "noaction"}]'
::
%+ expect-eq
!> ~
2020-05-08 08:29:25 +03:00
!> %- parse-channel-request:eyre-gate
2018-11-16 00:43:10 +03:00
%- need %- de-json:html
'[{"action": "bad-action"}]'
::
%+ expect-eq
!> ~
2020-05-08 08:29:25 +03:00
!> %- parse-channel-request:eyre-gate
2018-11-16 00:43:10 +03:00
%- need %- de-json:html
'[{"action": "ack", "event-id": 5}, {"action": "bad-action"}]'
2018-11-16 00:43:10 +03:00
::
%+ expect-eq
!> :- ~
:~ [%ack 9]
[%poke 3 ~bud %wut %wut-type [%a [%n '2'] [%n '1'] ~]]
2018-11-16 00:43:10 +03:00
==
2020-05-08 08:29:25 +03:00
!> %- parse-channel-request:eyre-gate
2018-11-16 00:43:10 +03:00
%- need %- de-json:html
'''
[{"action": "ack", "event-id": 9},
2018-11-16 00:43:10 +03:00
{"action": "poke",
"id": 3,
2018-11-16 00:43:10 +03:00
"ship": "bud",
"app": "wut",
"mark": "wut-type",
"json": [2, 1]}]
'''
==
::
++ test-channel-reject-unauthenticated
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
expected-moves=~
==
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call :*
eyre-gate
now=~1111.1.2
scry=scry-provides-code
^= call-args
:* duct=~[/http-blah] ~
%request
%.n
[%ipv4 .192.168.1.1]
[%'PUT' '/~/channel/1234567890abcdef' ~ ~]
==
^= expected-moves
2020-05-08 08:29:25 +03:00
^- (list move:eyre-gate)
:~ :* duct=~[/http-blah]
%give
%response
%start
::
%+ complete-http-start-event
:- 403
['content-type' 'text/html']~
:- ~
2020-05-08 08:29:25 +03:00
%- error-page:eyre-gate :*
403
%.n
'/~/channel/1234567890abcdef'
~
==
== ==
==
::
;: weld
results1
results2
==
::
++ test-channel-open-never-used-expire
=^ results1 eyre-gate (perform-init-start-channel eyre-gate *roof)
:: the behn timer wakes us up; we cancel our subscription
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-take-with-comparator :*
eyre-gate
now=(add ~1111.1.2 ~h12)
scry=scry-provides-code
^= take-args
:* wire=/channel/timeout/'0123456789abcdef' duct=~[/http-blah]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%behn %wake ~]
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
^- tang
::
?. ?=([^ ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
%+ expect-gall-deal
:* /channel/subscription/'0123456789abcdef'/1/~nul/two
2019-11-14 06:38:13 +03:00
[~nul ~nul] %two %leave ~
==
card.i.moves
==
::
;: weld
results1
results2
==
::
++ test-channel-results-before-open
:: common initialization
::
=^ results1 eyre-gate (perform-init-start-channel eyre-gate *roof)
:: poke gets a success message
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m1)
scry=scry-provides-code
^= take-args
2018-11-21 21:34:22 +03:00
:* wire=/channel/poke/'0123456789abcdef'/'0' duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %poke-ack ~]
==
moves=~
==
:: subscription gets a success message
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m1)
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %watch-ack ~]
==
moves=~
==
:: subscription gets a result
::
2020-05-08 08:29:25 +03:00
=^ results4 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m2)
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %fact %json !>(`json`[%a [%n '1'] [%n '2'] ~])]
==
moves=~
==
:: open up the channel
::
:: send the channel a poke and a subscription request
::
2020-05-08 08:29:25 +03:00
=^ results5 eyre-gate
%- eyre-call :*
eyre-gate
2018-11-22 00:37:26 +03:00
now=(add ~1111.1.2 ~m3)
scry=scry-provides-code
^= call-args
:* duct=~[/http-get-open] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'GET'
'/~/channel/0123456789abcdef'
['cookie' cookie-value]~
~
==
^= expected-moves
2020-05-08 08:29:25 +03:00
^- (list move:eyre-gate)
:~ :* duct=~[/http-get-open]
%pass
/channel/heartbeat/'0123456789abcdef'
[%b %wait ~1111.1.2..00.03.20]
==
:* duct=~[/http-get-open]
%give
%response
%start
2020-10-01 04:20:18 +03:00
:- 200
:~ ['content-type' 'text/event-stream']
['cache-control' 'no-cache']
['connection' 'keep-alive']
['set-cookie' cookie-string]
==
::
:- ~
%- as-octs:mimes:html
'''
id: 0
data: {"ok":"ok","id":0,"response":"poke"}
id: 1
data: {"ok":"ok","id":1,"response":"subscribe"}
id: 2
data: {"json":[1,2],"id":1,"response":"diff"}
'''
::
complete=%.n
==
2018-11-22 00:37:26 +03:00
:: opening the channel cancels the timeout timer
::
2018-11-21 21:34:22 +03:00
:* duct=~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
[%b %rest ~1111.1.2..12.00.00]
== == ==
2018-11-22 00:37:26 +03:00
:: we get a cancel when we notice the client has disconnected
::
2020-05-08 08:29:25 +03:00
=^ results6 eyre-gate
%- eyre-call :*
eyre-gate
2018-11-22 00:37:26 +03:00
now=(add ~1111.1.2 ~m4)
scry=scry-provides-code
call-args=[duct=~[/http-get-open] ~ %cancel-request ~]
2018-11-22 00:37:26 +03:00
^= expected-moves
2020-05-08 08:29:25 +03:00
^- (list move:eyre-gate)
:: closing the channel cancels the sse heartbeat
:: (initialized in results5 above) and restarts the timeout timer
2018-11-22 00:37:26 +03:00
::
:~ :* duct=~[/http-get-open] %pass
/channel/heartbeat/'0123456789abcdef'
%b %rest :(add ~1111.1.2 ~m3 ~s20)
==
:* duct=~[/http-get-open] %pass
2018-11-22 00:37:26 +03:00
/channel/timeout/'0123456789abcdef'
%b %wait :(add ~1111.1.2 ~h12 ~m4)
== ==
==
::
;: weld
results1
results2
results3
results4
results5
2018-11-22 00:37:26 +03:00
results6
==
::
::
++ test-channel-second-get-updates-timer
:: common initialization
::
=^ results1 eyre-gate (perform-init-start-channel eyre-gate *roof)
2018-11-22 00:37:26 +03:00
:: perform another poke to a different app
::
:: Since we haven't connected with a GET, the old timer should be canceled
:: and a new one should be set.
:: send the channel a poke and a subscription request
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
2018-11-22 00:37:26 +03:00
now=(add ~1111.1.2 ~m1)
scry=scry-provides-code
2018-11-22 00:37:26 +03:00
^= call-args
:* duct=~[/http-put-request] ~
%request
2018-11-22 00:37:26 +03:00
%.n
[%ipv4 .192.168.1.1]
%'PUT'
'/~/channel/0123456789abcdef'
['cookie' cookie-value]~
2018-11-22 00:37:26 +03:00
::
:- ~
%- as-octs:mimes:html
'''
[{"action": "poke",
"id": 2,
"ship": "nul",
"app": "eight",
"mark": "a",
"json": 9}]
'''
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
2018-11-22 00:37:26 +03:00
^- tang
::
?. ?=([^ ^ ^ ^ ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
;: weld
%+ expect-gall-deal
:* /channel/poke/'0123456789abcdef'/'2'
[~nul ~nul] %eight
2019-11-14 06:38:13 +03:00
%poke-as %a %json !>([%n '9'])
2018-11-22 00:37:26 +03:00
==
card.i.moves
::
%+ expect-eq
2020-09-28 19:27:21 +03:00
!> put-204-response
2018-11-22 00:37:26 +03:00
!> i.t.moves
::
%+ expect-eq
!> :* ~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
%b %rest (add ~1111.1.2 ~h12)
==
!> i.t.t.moves
::
%+ expect-eq
!> :* ~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
%b %wait :(add ~1111.1.2 ~h12 ~m1)
==
!> i.t.t.t.moves
== ==
::
;: weld
results1
results2
==
::
++ test-channel-unsubscribe-stops-events
:: common initialization
::
=^ results1 eyre-gate (perform-init-start-channel eyre-gate *roof)
:: poke gets a success message
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m1)
scry=scry-provides-code
^= take-args
:* wire=/channel/poke/'0123456789abcdef'/'0' duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %poke-ack ~]
==
moves=~
==
:: subscription gets a success message
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m2)
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %watch-ack ~]
==
moves=~
==
:: sending an unsubscribe sends an unsubscribe to gall
::
2020-05-08 08:29:25 +03:00
=^ results4 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
now=(add ~1111.1.2 ~m3)
scry=scry-provides-code
^= call-args
:* duct=~[/http-put-request] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'PUT'
'/~/channel/0123456789abcdef'
['cookie' cookie-value]~
::
:- ~
%- as-octs:mimes:html
'''
[{"action": "unsubscribe",
"id": 2,
"subscription": 1}
]
'''
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
^- tang
::
?. ?=([^ ^ ^ ^ ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
;: weld
:: we want to cancel the subscription id on which we originally subscribed
::
%+ expect-gall-deal
:* /channel/subscription/'0123456789abcdef'/'1'/~nul/two
2019-11-14 06:38:13 +03:00
[~nul ~nul] %two %leave ~
==
card.i.moves
::
%+ expect-eq
2020-09-28 19:27:21 +03:00
!> put-204-response
!> i.t.moves
::
%+ expect-eq
!> :* ~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
%b %rest (add ~1111.1.2 ~h12)
==
!> i.t.t.moves
::
%+ expect-eq
!> :* ~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
%b %wait :(add ~1111.1.2 ~h12 ~m3)
==
!> i.t.t.t.moves
== ==
::
;: weld
results1
results2
results3
results4
==
::
++ test-channel-double-subscription-works
:: common initialization
::
=^ results1 eyre-gate (perform-init-start-channel eyre-gate *roof)
:: poke gets a success message
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m1)
scry=scry-provides-code
^= take-args
:* wire=/channel/poke/'0123456789abcdef'/'0' duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %poke-ack ~]
==
moves=~
==
:: subscription gets a success message
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m2)
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %watch-ack ~]
==
moves=~
==
:: now make a second subscription from the client on the same path
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
now=(add ~1111.1.2 ~m3)
scry=scry-provides-code
^= call-args
:* duct=~[/http-put-request] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'PUT'
'/~/channel/0123456789abcdef'
['cookie' cookie-value]~
::
:- ~
%- as-octs:mimes:html
'''
[{"action": "subscribe",
"id": 2,
"ship": "nul",
"app": "two",
"path": "/one/two/three"}
]
'''
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
^- tang
::
?. ?=([^ ^ ^ ^ ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
;: weld
%+ expect-gall-deal
:* /channel/subscription/'0123456789abcdef'/'2'/~nul/two
[~nul ~nul] %two
%watch /one/two/three
==
card.i.moves
::
%+ expect-eq
2020-09-28 19:27:21 +03:00
!> put-204-response
!> i.t.moves
::
%+ expect-eq
!> :* ~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
%b %rest (add ~1111.1.2 ~h12)
==
!> i.t.t.moves
::
%+ expect-eq
!> :* ~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
%b %wait :(add ~1111.1.2 ~h12 ~m3)
==
!> i.t.t.t.moves
== ==
:: subscription gets a result (on the id 1)
::
2020-05-08 08:29:25 +03:00
=^ results4 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m2)
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %fact %json !>(`json`[%a [%n '1'] [%n '2'] ~])]
==
moves=~
==
:: subscription gets a result (on the id 2)
::
2020-05-08 08:29:25 +03:00
=^ results5 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m2)
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'2'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %fact %json !>(`json`[%a [%n '1'] [%n '2'] ~])]
==
moves=~
==
:: open up the channel
::
2020-05-08 08:29:25 +03:00
=^ results6 eyre-gate
%- eyre-call :*
eyre-gate
now=(add ~1111.1.2 ~m3)
scry=scry-provides-code
^= call-args
:* duct=~[/http-get-open] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'GET'
'/~/channel/0123456789abcdef'
['cookie' cookie-value]~
~
==
^= expected-moves
2020-05-08 08:29:25 +03:00
^- (list move:eyre-gate)
:~ :* duct=~[/http-get-open]
%pass
/channel/heartbeat/'0123456789abcdef'
[%b %wait ~1111.1.2..00.03.20]
==
:* duct=~[/http-get-open]
%give
%response
%start
:- 200
:~ ['content-type' 'text/event-stream']
['cache-control' 'no-cache']
['connection' 'keep-alive']
['set-cookie' cookie-string]
==
::
:- ~
%- as-octs:mimes:html
'''
id: 0
data: {"ok":"ok","id":0,"response":"poke"}
id: 1
data: {"ok":"ok","id":1,"response":"subscribe"}
id: 2
data: {"json":[1,2],"id":1,"response":"diff"}
id: 3
data: {"json":[1,2],"id":2,"response":"diff"}
'''
::
complete=%.n
==
:: opening the channel cancels the timeout timer
::
:* duct=~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
[%b %rest ~1111.1.2..12.03.00]
== == ==
:: we can close the first channel without closing the second
::
2020-05-08 08:29:25 +03:00
=^ results7 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
now=(add ~1111.1.2 ~m3)
scry=scry-provides-code
^= call-args
:* duct=~[/http-put-request] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'PUT'
'/~/channel/0123456789abcdef'
['cookie' cookie-value]~
::
:- ~
%- as-octs:mimes:html
'''
[{"action": "unsubscribe",
"id": 3,
"subscription": 1}
]
'''
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
^- tang
::
?. ?=([^ ^ ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
;: weld
%+ expect-gall-deal
:* /channel/subscription/'0123456789abcdef'/'1'/~nul/two
2019-11-14 06:38:13 +03:00
[~nul ~nul] %two %leave ~
==
card.i.moves
::
%+ expect-eq
2020-09-28 19:27:21 +03:00
!> put-204-response
!> i.t.moves
== ==
:: gall responds on the second subscription.
::
:: This just tests that closing one of the two subscriptions doesn't
:: unsubscribe to the other.
::
2020-05-08 08:29:25 +03:00
=^ results8 eyre-gate
%- eyre-take-with-comparator :*
eyre-gate
now=(add ~1111.1.2 ~m2)
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'2'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %fact %json !>(`json`[%a [%n '1'] [%n '2'] ~])]
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
^- tang
::
?. ?=([^ ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
%+ expect-eq
!> :* ~[/http-get-open] %give %response %continue
:- ~
%- as-octs:mimes:html
'''
id: 4
data: {"json":[1,2],"id":2,"response":"diff"}
'''
complete=%.n
==
!> i.moves
==
::
;: weld
results1
results2
results3
results4
results5
results6
results7
results8
==
::
++ test-prune-events
=/ q=(qeu [id=@ud @ud channel-event:eyre]) ~
=. q (~(put to q) [0 0 *channel-event:eyre])
=. q (~(put to q) [1 0 *channel-event:eyre])
=. q (~(put to q) [2 0 *channel-event:eyre])
=. q (~(put to q) [3 1 *channel-event:eyre])
=. q (~(put to q) [4 1 *channel-event:eyre])
::
=^ a q (prune-events:eyre-gate q 3)
::
%+ expect-eq
!>
:- (~(gas by *(map @ud @ud)) ~[0^3 1^1])
[~ [4 1 *channel-event:eyre]]
!>([a ~(top to q)])
::
++ test-subtract-acked-events
=/ a (~(gas by *(map @ud @ud)) ~[0^3 1^1])
=/ u (~(gas by *(map @ud @ud)) ~[0^4 2^1])
=/ e (~(gas by *(map @ud @ud)) ~[0^1 2^1])
=/ r (subtract-acked-events:eyre-gate a u)
(expect-eq !>(e) !>(r))
::
++ test-channel-sends-unacknowledged-events-on-reconnection
:: common initialization
::
=^ results1 eyre-gate (perform-init-start-channel eyre-gate *roof)
:: poke gets a success message
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m1)
scry=scry-provides-code
^= take-args
:* wire=/channel/poke/'0123456789abcdef'/'0' duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %poke-ack ~]
==
moves=~
==
:: subscription gets a success message
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m2)
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %watch-ack ~]
==
moves=~
==
:: opens the http channel
::
2020-05-08 08:29:25 +03:00
=^ results4 eyre-gate
%- eyre-call :*
eyre-gate
now=(add ~1111.1.2 ~m3)
scry=scry-provides-code
^= call-args
2020-12-08 03:47:06 +03:00
^- [duct (unit goof) (hobo task:eyre-gate)]
:* duct=~[/http-get-open] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'GET'
'/~/channel/0123456789abcdef'
['cookie' cookie-value]~
~
==
^= expected-moves
2020-05-08 08:29:25 +03:00
^- (list move:eyre-gate)
:~ :* duct=~[/http-get-open]
%pass
/channel/heartbeat/'0123456789abcdef'
[%b %wait ~1111.1.2..00.03.20]
==
:* duct=~[/http-get-open]
%give
%response
%start
:- 200
:~ ['content-type' 'text/event-stream']
['cache-control' 'no-cache']
['connection' 'keep-alive']
['set-cookie' cookie-string]
==
::
:- ~
%- as-octs:mimes:html
'''
id: 0
data: {"ok":"ok","id":0,"response":"poke"}
id: 1
data: {"ok":"ok","id":1,"response":"subscribe"}
'''
::
complete=%.n
==
:: opening the channel cancels the timeout timer
::
:* duct=~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
[%b %rest :(add ~1111.1.2 ~h12)]
== == ==
:: first subscription result gets sent to the user
::
2020-05-08 08:29:25 +03:00
=^ results5 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m4)
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %fact %json !>(`json`[%a [%n '1'] ~])]
==
^= moves
2020-05-08 08:29:25 +03:00
^- (list move:eyre-gate)
:~ :* duct=~[/http-get-open]
%give
%response
%continue
:- ~
%- as-octs:mimes:html
'''
id: 2
data: {"json":[1],"id":1,"response":"diff"}
'''
complete=%.n
== == ==
:: the client now acknowledges up to event 1
::
:: send the channel a poke and a subscription request
::
2020-05-08 08:29:25 +03:00
=^ results6 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
now=(add ~1111.1.2 ~m5)
scry=scry-provides-code
^= call-args
:* duct=~[/http-put-request] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'PUT'
'/~/channel/0123456789abcdef'
['cookie' cookie-value]~
::
:- ~
%- as-octs:mimes:html
'''
[{"action": "ack",
"event-id": 1}
]
'''
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
^- tang
::
?. ?=([^ ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
%+ expect-eq
2020-09-28 19:27:21 +03:00
!> put-204-response
!> i.moves
==
:: the client connection is detected to be broken
::
2020-05-08 08:29:25 +03:00
=^ results7 eyre-gate
%- eyre-call :*
eyre-gate
now=(add ~1111.1.2 ~m6)
scry=scry-provides-code
call-args=[duct=~[/http-get-open] ~ %cancel-request ~]
^= expected-moves
2020-05-08 08:29:25 +03:00
^- (list move:eyre-gate)
:: closing the channel cancels the sse heartbeat
:: (initialized in results4 above) and restarts the timeout timer
::
:~ :* duct=~[/http-get-open] %pass
/channel/heartbeat/'0123456789abcdef'
%b %rest :(add ~1111.1.2 ~m3 ~s20)
==
:* duct=~[/http-get-open] %pass
/channel/timeout/'0123456789abcdef'
%b %wait :(add ~1111.1.2 ~h12 ~m6)
== ==
==
:: another subscription result while the user is disconnected
::
2020-05-08 08:29:25 +03:00
=^ results8 eyre-gate
%- eyre-take :*
eyre-gate
now=(add ~1111.1.2 ~m7)
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %fact %json !>(`json`[%a [%n '2'] ~])]
==
moves=~
==
:: the client now retries to connect
::
:: Because the client has acknowledged up to event 1, we should start the connection by
:: resending events 2 and 3.
::
2020-05-08 08:29:25 +03:00
=^ results9 eyre-gate
%- eyre-call :*
eyre-gate
now=(add ~1111.1.2 ~m8)
scry=scry-provides-code
^= call-args
:* duct=~[/http-get-open] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'GET'
'/~/channel/0123456789abcdef'
['cookie' cookie-value]~
~
==
^= expected-moves
2020-05-08 08:29:25 +03:00
^- (list move:eyre-gate)
:~ :* duct=~[/http-get-open]
%pass
/channel/heartbeat/'0123456789abcdef'
[%b %wait ~1111.1.2..00.08.20]
==
:* duct=~[/http-get-open]
%give
%response
%start
:- 200
:~ ['content-type' 'text/event-stream']
['cache-control' 'no-cache']
['connection' 'keep-alive']
['set-cookie' cookie-string]
==
::
:- ~
%- as-octs:mimes:html
'''
id: 2
data: {"json":[1],"id":1,"response":"diff"}
id: 3
data: {"json":[2],"id":1,"response":"diff"}
'''
::
complete=%.n
==
:: opening the channel cancels the timeout timer
::
:* duct=~[/http-get-open] %pass
/channel/timeout/'0123456789abcdef'
:: add ~m6 because that was the time of the last GET
::
[%b %rest :(add ~1111.1.2 ~m6 ~h12)]
== == ==
::
;: weld
results1
results2
results3
results4
results5
results6
results7
results8
results9
==
::
++ test-channel-subscription-clogged
:: common initialization
::
=^ tested-elsewhere eyre-gate
(perform-init-start-channel eyre-gate *roof)
::
=/ now=@da :(add ~1111.1.2 clog-timeout:eyre-gate ~s1)
:: subscription gets a success message
::
=^ tested-elsewhere eyre-gate
%: eyre-take
eyre-gate
now
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %watch-ack ~]
==
moves=~
==
:: opens the http channel
::
=^ tested-elsewhere eyre-gate
%: eyre-call
eyre-gate
now
scry=scry-provides-code
^= call-args
2020-12-08 03:47:06 +03:00
^- [duct (unit goof) (hobo task:eyre-gate)]
:* duct=~[/http-get-open] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'GET'
'/~/channel/0123456789abcdef'
['cookie' cookie-value]~
~
==
^= expected-moves
~ ::NOTE tested elsewhere
==
:: user gets sent multiple subscription results
::
=/ max=@ud clog-threshold:eyre-gate
=/ cur=@ud 0
|- =* loop-fact $
?. =(cur max)
=^ tested-elsewhere eyre-gate
%: eyre-take
eyre-gate
now
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %fact %json !>(`json`[%a [%n '1'] ~])]
==
^= moves
~ ::NOTE tested elsewhere
==
loop-fact(cur +(cur))
:: the next subscription result should trigger a clog
::
=^ results1 eyre-gate
%: eyre-take
eyre-gate
now
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %fact %json !>(`json`[%a [%n '1'] ~])]
==
^= moves
:~ :* duct=~[/http-get-open]
%give
%response
%continue
:- ~
%- as-octt:mimes:html
"""
id: {((d-co:co 1) +(clog-threshold:eyre-gate))}
data: \{"json":[1],"id":1,"response":"diff"}
"""
complete=%.n
==
:* duct=~[/http-put-request] %pass
/channel/subscription/'0123456789abcdef'/'1'/~nul/two
%g %deal [~nul ~nul] %two %leave ~
==
:* duct=~[/http-get-open]
%give
%response
%continue
:- ~
%- as-octt:mimes:html
"""
id: {((d-co:co 1) (add 2 clog-threshold:eyre-gate))}
data: \{"id":1,"response":"quit"}
"""
complete=%.n
==
==
==
:: subsequent subscription updates, which might have gotten sent out during
:: the same event in which a clog triggered, should be silently ignored
::
=^ results2 eyre-gate
%: eyre-take
eyre-gate
now
scry=scry-provides-code
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1'/~nul/two
duct=~[/http-put-request]
2020-12-06 11:38:37 +03:00
^- sign:eyre-gate
2020-12-08 06:12:20 +03:00
[%gall %unto %fact %json !>(`json`[%a [%n '1'] ~])]
==
^= moves
~
==
(weld results1 results2)
::
++ test-born-sends-pending-cancels
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
expected-moves=~
==
:: app1 binds successfully
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call :*
eyre-gate
now=~1111.1.2
scry=scry-provides-code
call-args=[duct=~[/app1] ~ [%connect [~ /] %app1]]
expected-moves=[duct=~[/app1] %give %bound %.y [~ /]]~
==
:: start a request to app1
::
:: outside requests a path that app1 has bound to
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
now=~1111.1.3
scry=scry-provides-code
^= call-args
:* duct=~[/http-blah] ~
%request
%.n
[%ipv4 .192.168.1.1]
[%'GET' '/' ~ ~]
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
^- tang
::
2019-11-14 06:38:13 +03:00
?. ?=([* * ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
2020-05-08 08:29:25 +03:00
=/ move-1=move:eyre-gate i.moves
=/ move-2=move:eyre-gate i.t.moves
::
2019-11-14 06:38:13 +03:00
%+ weld
(expect-eq !>(~[/http-blah]) !>(duct.move-1))
%+ weld
(expect-eq !>(~[/http-blah]) !>(duct.move-2))
::
%+ weld
2019-11-14 06:38:13 +03:00
%+ expect-gall-deal
:+ /watch-response/[eyre-id]
[~nul ~nul]
:* %app1 %watch
/http-response/[eyre-id]
==
card.move-1
::
%+ expect-gall-deal
2019-11-14 06:38:13 +03:00
:+ /run-app-request/[eyre-id] [~nul ~nul]
:* %app1 %poke %handle-http-request
2019-11-14 06:38:13 +03:00
!>([eyre-id %.n %.n [%ipv4 .192.168.1.1] [%'GET' '/' ~ ~]])
==
2019-11-14 06:38:13 +03:00
card.move-2
==
:: but app1 doesn't respond before our urbit gets shut down. ensure we send
:: cancels on open connections.
::
2020-05-08 08:29:25 +03:00
=^ results4 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
now=~1111.1.4
scry=scry-provides-code
call-args=[duct=~[/born] ~ [%born ~]]
^= expected-moves
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
^- tang
::
?. ?=([^ ^ ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
:: we don't care about the first one, which is just a static
:: configuration move.
::
2020-05-08 08:29:25 +03:00
=/ move=move:eyre-gate i.t.moves
=/ =duct duct.move
2020-12-08 03:47:06 +03:00
=/ card=(wind note:eyre-gate gift:eyre-gate) card.move
::
%+ weld
(expect-eq !>(~[/http-blah]) !>(duct))
::
%+ expect-gall-deal
2019-11-14 06:38:13 +03:00
:+ /watch-response/[eyre-id] [~nul ~nul]
[%app1 %leave ~]
card
==
::
;: weld
results1
results2
results3
results4
==
::
2020-05-08 08:29:25 +03:00
++ eyre-call
|= $: eyre-gate=_eyre-gate
2018-09-20 02:29:36 +03:00
now=@da
scry=roof
2020-12-08 03:47:06 +03:00
call-args=[=duct dud=(unit goof) wrapped-task=(hobo task:eyre-gate)]
2020-05-08 08:29:25 +03:00
expected-moves=(list move:eyre-gate)
2018-09-20 02:29:36 +03:00
==
2020-05-08 08:29:25 +03:00
^- [tang _eyre-gate]
2018-09-20 02:29:36 +03:00
::
2020-05-08 08:29:25 +03:00
=/ eyre-core
2020-12-06 11:38:37 +03:00
(eyre-gate now=now eny=`@uvJ`0xdead.beef scry=scry)
2018-09-20 02:29:36 +03:00
::
2020-05-08 08:29:25 +03:00
=^ moves eyre-gate
2020-12-06 11:38:37 +03:00
(call:eyre-core [duct dud wrapped-task]:call-args)
2018-09-20 02:29:36 +03:00
::
=/ output=tang
%+ expect-eq
!> expected-moves
!> moves
::
2020-05-08 08:29:25 +03:00
[output eyre-gate]
2018-09-21 02:36:04 +03:00
::
2020-05-08 08:29:25 +03:00
++ eyre-call-with-comparator
|= $: eyre-gate=_eyre-gate
2018-09-21 02:36:04 +03:00
now=@da
scry=roof
2020-12-08 03:47:06 +03:00
call-args=[=duct dud=(unit goof) wrapped-task=(hobo task:eyre-gate)]
2020-05-08 08:29:25 +03:00
move-comparator=$-((list move:eyre-gate) tang)
2018-09-21 02:36:04 +03:00
==
2020-05-08 08:29:25 +03:00
^- [tang _eyre-gate]
2018-09-21 02:36:04 +03:00
::
2020-12-06 11:38:37 +03:00
=/ eyre-core (eyre-gate now=now eny=`@uvJ`0xdead.beef scry=scry)
2018-09-21 02:36:04 +03:00
::
2020-12-06 11:38:37 +03:00
=^ moves eyre-gate (call:eyre-core [duct dud wrapped-task]:call-args)
2018-09-21 02:36:04 +03:00
::
=/ output=tang (move-comparator moves)
::
2020-05-08 08:29:25 +03:00
[output eyre-gate]
2018-09-21 02:36:04 +03:00
::
2020-05-08 08:29:25 +03:00
++ eyre-take
|= $: eyre-gate=_eyre-gate
2018-09-24 21:48:19 +03:00
now=@da
scry=roof
2020-12-06 11:38:37 +03:00
take-args=[=wire =duct =sign:eyre-gate]
2020-05-08 08:29:25 +03:00
expected-moves=(list move:eyre-gate)
2018-09-24 21:48:19 +03:00
==
2020-05-08 08:29:25 +03:00
^- [tang _eyre-gate]
2018-09-24 21:48:19 +03:00
::
2020-12-06 11:38:37 +03:00
=/ eyre-core (eyre-gate now=now eny=`@uvJ`0xdead.beef scry=scry)
2018-09-24 21:48:19 +03:00
::
2020-12-06 11:38:37 +03:00
=^ moves eyre-gate (take:eyre-core [wire duct ~ sign]:take-args)
2018-09-24 21:48:19 +03:00
::
=/ output=tang
%+ expect-eq
!> expected-moves
!> moves
::
2020-05-08 08:29:25 +03:00
[output eyre-gate]
2018-09-24 21:48:19 +03:00
::
2020-05-08 08:29:25 +03:00
++ eyre-take-with-comparator
|= $: eyre-gate=_eyre-gate
2018-09-24 21:48:19 +03:00
now=@da
scry=roof
2020-12-06 11:38:37 +03:00
take-args=[=wire =duct =sign:eyre-gate]
2020-05-08 08:29:25 +03:00
move-comparator=$-((list move:eyre-gate) tang)
2018-09-24 21:48:19 +03:00
==
2020-05-08 08:29:25 +03:00
^- [tang _eyre-gate]
2018-09-24 21:48:19 +03:00
::
2020-12-06 11:38:37 +03:00
=/ eyre-core (eyre-gate now=now eny=`@uvJ`0xdead.beef scry=scry)
2018-09-24 21:48:19 +03:00
::
2020-12-08 03:47:06 +03:00
=^ moves eyre-gate (take:eyre-core [wire duct ~ sign]:take-args)
2018-09-24 21:48:19 +03:00
::
=/ output=tang (move-comparator moves)
::
2020-05-08 08:29:25 +03:00
[output eyre-gate]
2018-09-24 21:48:19 +03:00
::
2018-09-21 02:36:04 +03:00
++ expect-gall-deal
2019-11-19 07:36:21 +03:00
|= $: expected=[wire=path id=sock app=term =deal:gall]
2020-12-08 03:47:06 +03:00
actual=(wind note:eyre-gate gift:eyre-gate)
2018-09-21 02:36:04 +03:00
==
^- tang
::
?. ?=(%pass -.actual)
[%leaf "bad move, not a %pass: {<actual>}"]~
::
%+ weld
(expect-eq !>(wire.expected) !>(p.actual))
::
2020-05-08 08:29:25 +03:00
=/ note=note:eyre-gate q.actual
2019-11-19 07:36:21 +03:00
?. ?=([%g %deal *] note)
2018-09-21 02:36:04 +03:00
[%leaf "bad move, not a %deal: {<actual>}"]~
::
%+ weld
2019-11-14 06:38:13 +03:00
(expect-eq !>(id.expected) !>(p.note))
2018-09-21 02:36:04 +03:00
::
%+ weld
2019-11-14 06:38:13 +03:00
(expect-eq !>(app.expected) !>(q.note))
2018-09-21 02:36:04 +03:00
::
2019-11-14 06:38:13 +03:00
?: ?=([%poke *] deal.expected)
?. ?=([%poke *] r.note)
[%leaf "expected %poke, actual {<r.note>}"]~
::
%+ weld
2019-11-14 06:38:13 +03:00
(expect-eq !>(p.cage.deal.expected) !>(p.cage.r.note))
:: compare the payload vases
::
2019-11-14 06:38:13 +03:00
(expect-eq q.cage.deal.expected q.cage.r.note)
::
2019-11-14 06:38:13 +03:00
?: ?=([%poke-as *] deal.expected)
?. ?=([%poke-as *] r.note)
[%leaf "expected %poke-as, actual {<r.note>}"]~
:: compare the mark type
::
%+ weld
2019-11-14 06:38:13 +03:00
(expect-eq !>(mark.deal.expected) !>(mark.r.note))
:: compare the cage mark
::
%+ weld
2019-11-14 06:38:13 +03:00
(expect-eq !>(p.cage.deal.expected) !>(p.cage.r.note))
:: compare the payload vases
::
2019-11-14 06:38:13 +03:00
(expect-eq q.cage.deal.expected q.cage.r.note)
::
?: ?=([%watch *] deal.expected)
?. ?=([%watch *] r.note)
[%leaf "expected %watch, actual {<r.note>}"]~
2019-11-14 06:38:13 +03:00
:: compare the path
::
(expect-eq !>(path.deal.expected) !>(path.r.note))
::
2019-11-14 06:38:13 +03:00
?: ?=([%watch-as *] deal.expected)
?. ?=([%watch-as *] r.note)
[%leaf "expected %watch-as, actual {<r.note>}"]~
:: compare the result mark
::
%+ weld
2019-11-14 06:38:13 +03:00
(expect-eq !>(mark.deal.expected) !>(mark.r.note))
:: compare the path
::
2019-11-14 06:38:13 +03:00
(expect-eq !>(path.deal.expected) !>(path.r.note))
::
2019-11-14 06:38:13 +03:00
?: ?=([%leave *] deal.expected)
?. ?=([%leave *] r.note)
[%leaf "expected %leave, actual {<r.note>}"]~
::
~
:: todo: handle other deals
2018-09-21 02:36:04 +03:00
::
[%leaf "unexpected %deal type"]~
:: +perform-authentication: goes through the authentication flow
::
++ perform-authentication
2020-05-08 08:29:25 +03:00
|= $: eyre-gate=_eyre-gate
start-now=@da
scry=roof
==
2020-05-08 08:29:25 +03:00
^- [tang _eyre-gate]
:: the browser then fetches the login page
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
now=start-now
scry=scry-provides-code
^= call-args
:* duct=~[/http-blah] ~
%request
%.n
[%ipv4 .192.168.1.1]
[%'GET' '/~/login?redirect=/~landscape/inner-path' ~ ~]
==
^= expected-moves
2020-05-08 08:29:25 +03:00
^- (list move:eyre-gate)
:~ :* duct=~[/http-blah]
%give
%response
%start
::
%+ complete-http-start-event
:- 200
['content-type' 'text/html']~
[~ (login-page:eyre-gate `'/~landscape/inner-path' ~nul %.n)]
== ==
==
:: a response post redirects back to the application, setting cookie
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- eyre-call :*
eyre-gate
now=(add start-now ~m1)
scry=scry-provides-code
^= call-args
:* duct=~[/http-blah] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'POST'
'/~/login'
~
:- ~
%- as-octs:mimes:html
'password=lidlut-tabwed-pillex-ridrup&redirect=/~landscape'
==
^= expected-moves
2020-05-08 08:29:25 +03:00
^- (list move:eyre-gate)
:~ ::NOTE this ~d7 is tied to the eyre-internal +session-timeout...
:- duct=~[/http-blah]
[%pass p=/sessions/expire q=[%b [%wait p=(add start-now ~d7.m1)]]]
::
:* duct=~[/http-blah]
%give
%response
%start
:- 303
:~ ['location' '/~landscape']
['set-cookie' cookie-string]
==
~
complete=%.y
== ==
==
::
2020-05-08 08:29:25 +03:00
:_ eyre-gate
(weld results1 results2)
:: performs all initialization and an initial PUT.
::
++ perform-init-start-channel
2020-05-08 08:29:25 +03:00
|= $: eyre-gate=_eyre-gate
scry=roof
==
2020-05-08 08:29:25 +03:00
^- [tang _eyre-gate]
::
2020-05-08 08:29:25 +03:00
=^ results1 eyre-gate
%- eyre-call :*
eyre-gate
now=~1111.1.1
scry=scry-provides-code
call-args=[duct=~[/init] ~ [%init ~]]
expected-moves=~
==
:: ensure there's an authenticated session
::
2020-05-08 08:29:25 +03:00
=^ results2 eyre-gate
%- perform-authentication :*
2020-05-08 08:29:25 +03:00
eyre-gate
now=~1111.1.2
scry=scry-provides-code
==
:: send the channel a poke and a subscription request
::
2020-05-08 08:29:25 +03:00
=^ results3 eyre-gate
%- eyre-call-with-comparator :*
eyre-gate
now=~1111.1.2
scry=scry-provides-code
^= call-args
2018-11-21 21:34:22 +03:00
:* duct=~[/http-put-request] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'PUT'
'/~/channel/0123456789abcdef'
['cookie' cookie-value]~
::
:- ~
%- as-octs:mimes:html
'''
[{"action": "poke",
"id": 0,
"ship": "nul",
"app": "one",
"mark": "a",
"json": 5},
{"action": "subscribe",
"id": 1,
"ship": "nul",
"app": "two",
"path": "/one/two/three"}
]
'''
==
^= comparator
2020-05-08 08:29:25 +03:00
|= moves=(list move:eyre-gate)
^- tang
::
?. ?=([^ ^ ^ ^ ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
;: weld
%+ expect-gall-deal
:* /channel/poke/'0123456789abcdef'/'0'
[~nul ~nul] %one
2019-11-14 06:38:13 +03:00
%poke-as %a %json !>([%n '5'])
==
card.i.moves
::
%+ expect-gall-deal
:* /channel/subscription/'0123456789abcdef'/'1'/~nul/two
[~nul ~nul] %two
%watch /one/two/three
==
card.i.t.moves
::
%+ expect-eq
2020-09-28 19:27:21 +03:00
!> put-204-response
!> i.t.t.moves
::
%+ expect-eq
2018-11-21 21:34:22 +03:00
!> :* ~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
%b %wait (add ~1111.1.2 ~h12)
==
!> i.t.t.t.moves
== ==
::
2020-05-08 08:29:25 +03:00
:_ eyre-gate
:(weld results1 results2 results3)
::
++ scry-provides-code ^- roof
2020-12-08 06:12:20 +03:00
|= [gang =view =beam]
^- (unit (unit cage))
2021-09-17 07:51:19 +03:00
?: =(%gd view) ``noun+!>(%base)
2020-12-08 06:12:20 +03:00
?: &(=(%ca view) =(/gen/handler/hoon s.beam))
2020-05-08 08:29:25 +03:00
:+ ~ ~
vase+!>(!>(|=(* |=(* [[%404 ~] ~]))))
2020-12-08 06:12:20 +03:00
?: &(=(%cb view) =(/json s.beam))
:^ ~ ~ %dais
!> ^- dais:clay
|_ sam=vase
++ diff !!
++ form !!
++ join !!
++ mash !!
++ pact !!
++ vale |=(=noun !>(;;(json noun)))
--
::
2020-12-08 06:12:20 +03:00
?> =(%j view)
?> =(~nul p.beam)
?> =(%code q.beam)
?> =(%da -.r.beam)
?> =(/~nul s.beam)
:: This is the default code for a fakeship.
::
[~ ~ %noun !>(.~lidlut-tabwed-savheb-loslux)]
:: produce the body of a %start http-event with the correct content-length
::
++ complete-http-start-event
|= [response-header:http data=(unit octs)]
=- [[status-code -] data %.y]
?~ data headers
%+ weld headers
['content-length' (crip ((d-co:co 1) p.u.data))]~
2020-09-28 19:27:21 +03:00
:: produce the 204 response to a put request
::
2020-09-28 19:27:21 +03:00
++ put-204-response
:* ~[/http-put-request]
%give
%response
%start
2020-09-28 19:27:21 +03:00
[204 ['set-cookie' cookie-string]~]
~
%.y
==
::
++ cookie-value
'urbauth-~nul=0v3.q0p7t.mlkkq.cqtto.p0nvi.2ieea'
::
++ cookie-string
%^ cat 3 cookie-value
'; Path=/; Max-Age=604800'
2018-09-20 02:29:36 +03:00
--