;; disfluid, implementation of the Solid specification
;; Copyright (C) 2020, 2021 Vivien Kraus
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Affero General Public License for more details.
;; You should have received a copy of the GNU Affero General Public License
;; along with this program. If not, see .
(define-module (tests client-manifest-fraudulent)
#:use-module (webid-oidc client-manifest)
#:use-module (webid-oidc cache)
#:use-module (webid-oidc testing)
#:use-module ((webid-oidc parameters) #:prefix p:)
#:use-module (webid-oidc errors)
#:use-module (web uri)
#:use-module (srfi srfi-19)
#:use-module (web response)
#:use-module (ice-9 optargs)
#:use-module (ice-9 receive)
#:use-module (oop goops)
#:declarative? #t
#:duplicates (merge-generics))
;; In this example, the client_id of the oidcRegistration does not
;; match the base URI.
(with-test-environment
"client-manifest-fraudulent"
(lambda ()
(define what-to-respond
(build-response #:headers '((content-type text/turtle))))
(define what-to-respond-body
"{
\"client_id\" : \"https://app.example.com/id#app\",
\"redirect_uris\" : [\"https://app.example.com/callback\"],
\"client_name\" : \"Solid Application Name\",
\"client_uri\" : \"https://app.example.com/\",
\"logo_uri\" : \"https://app.example.com/logo.png\",
\"tos_uri\" : \"https://app.example.com/tos.html\",
\"scope\" : \"openid profile offline_access\",
\"grant_types\" : [\"refresh_token\",\"authorization_code\"],
\"response_types\" : [\"code\"],
\"default_max_age\" : 60000,
\"require_auth_time\" : true
}")
(define headers-to-expect
'())
(define uri-to-expect
(string->uri "https://fraudulent-app.example.com/id#app"))
(define* (respond uri #:key (headers '()))
(when (string? uri)
(set! uri (string->uri uri)))
(unless (equal? uri uri-to-expect)
(exit 1))
(unless (equal? headers headers-to-expect)
(exit 2))
(values what-to-respond what-to-respond-body))
(parameterize ((p:anonymous-http-request respond))
(use-cache
(lambda ()
(with-exception-handler
(lambda (error)
(unless (inconsistent-client-manifest? error)
(exit 3)))
(lambda ()
(parameterize ((p:current-date 0))
(make
#:client-id "https://fraudulent-app.example.com/id#app"))
(exit 4))
#:unwind? #t
#:unwind-for-type &inconsistent-client-manifest))))))