summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVivien Kraus <vivien@planete-kraus.eu>2021-09-12 22:57:58 +0200
committerVivien Kraus <vivien@planete-kraus.eu>2021-09-14 16:06:43 +0200
commit328b4957d05fc9b0f9ff87f2a4932ae0296ab069 (patch)
tree2d44b7896c91f9934b470fd6bb54141ddc4dc714 /tests
parent6a83b79c4de5986ad61a552c2612b7cce0105cda (diff)
Restructure the client API
The client API had several problems: - using records instead of GOOPS means that we aren’t flexible enough to introduce accounts protected by a password, for a multi-user application; - saving the user database to disk means we can’t have a proper immutable API; - it was difficult to predict when the users database would change, and inform the user interface about this change; - it had two different ways to negociate an access token, one when we had a refresh token and one when we did not; - it was supposed to either use account objects or a subject / issuer pair, now we only use account objects.
Diffstat (limited to 'tests')
-rw-r--r--tests/client-workflow.scm53
1 files changed, 25 insertions, 28 deletions
diff --git a/tests/client-workflow.scm b/tests/client-workflow.scm
index 15f480a..b0c0c2f 100644
--- a/tests/client-workflow.scm
+++ b/tests/client-workflow.scm
@@ -30,12 +30,16 @@
(ice-9 optargs)
(ice-9 receive)
(ice-9 hash-table)
- (ice-9 match))
+ (ice-9 match)
+ (oop goops))
;; In this example, a user firsts requests an account, then logs in
;; with a refresh token, then logs out, but we can still revive per
;; account, then the refresh token gets banned.
+(define <client:client> client:<client>)
+(define <client:account> client:<account>)
+
(define (display-log simulation)
(format (current-error-port) "Log:\n")
(for-each
@@ -53,7 +57,8 @@
(with-test-environment
"client-workflow"
(lambda ()
- (let ((simulation (sim:make-simulation)))
+ (let ((simulation (sim:make-simulation))
+ (account #f))
(sim:add-server! simulation
(string->uri "https://server@client-workflow.scm")
(string->uri "https://server@client-workflow.scm/alice#me"))
@@ -63,21 +68,24 @@
(string->uri "https://client@client-workflow.scm/authorized")
"Client workflow test"
(string->uri "https://client@client-workflow.scm/about"))
- (let ((client (client:make-client
- (string->uri "https://client@client-workflow.scm/id")
- (jwk:generate-key #:n-size 2048)
- (string->uri "https://client@client-workflow.scm/authorized"))))
+ (parameterize ((client:client
+ (make <client:client>
+ #:client-id "https://client@client-workflow.scm/id"
+ #:redirect-uri
+ (string->uri "https://client@client-workflow.scm/authorized")))
+ (client:anonymous-http-request
+ (cute sim:request simulation <...>)))
(parameterize ((p:current-date 0)
(client:authorization-process
(lambda* (uri #:key issuer)
(sim:grant-authorization simulation uri))))
- (receive (response response-body)
- (let ((handler
- (client:request client #f
- (string->uri "https://server@client-workflow.scm")
- #:http-request (cute sim:request simulation <...>))))
- (handler (build-request (string->uri "https://server@client-workflow.scm/"))
- #f))
+ (receive (new-account response response-body)
+ (begin
+ (set! account
+ (make <client:account> #:issuer "https://server@client-workflow.scm"))
+ (client:request account
+ (string->uri "https://server@client-workflow.scm/")))
+ (set! account new-account)
(unless (eqv? (response-code response) 200)
;; Only Alice can read that resource.
(exit 3)))
@@ -140,14 +148,9 @@
(exit 4)))))
;; 1 hour later, the access token should have expired.
(parameterize ((p:current-date 3600))
- (receive (response response-body)
- (let ((handler
- (client:request client
- (string->uri "https://server@client-workflow.scm/alice#me")
- (string->uri "https://server@client-workflow.scm")
- #:http-request (cute sim:request simulation <...>))))
- (handler (build-request (string->uri "https://server@client-workflow.scm/"))
- #f))
+ (receive (new-account response response-body)
+ (client:request account (string->uri "https://server@client-workflow.scm/"))
+ (set! account new-account)
(unless (eqv? (response-code response) 200)
;; Only Alice can read that resource.
(exit 5)))
@@ -210,13 +213,7 @@
(unless (client:refresh-token-expired? error)
(exit 7)))
(lambda ()
- (let ((handler
- (client:request client
- (string->uri "https://server@client-workflow.scm/alice#me")
- (string->uri "https://server@client-workflow.scm")
- #:http-request (cute sim:request simulation <...>))))
- (handler (build-request (string->uri "https://server@client-workflow.scm/"))
- #f))
+ (client:request account (string->uri "https://server@client-workflow.scm/"))
(exit 8))
#:unwind? #t
#:unwind-for-type client:&refresh-token-expired)