summaryrefslogtreecommitdiff
path: root/tests/server-content.scm
blob: b53e399589d79698215376460b9c2f6949e7a83d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
;; 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 <https://www.gnu.org/licenses/>.

(define-module (tests server-content)
  #:use-module (webid-oidc server resource content)
  #:use-module (webid-oidc fetch)
  #:use-module (webid-oidc testing)
  #:use-module (webid-oidc errors)
  #:use-module (web uri)
  #:use-module (web response)
  #:use-module (rnrs bytevectors)
  #:use-module (ice-9 optargs)
  #:use-module (ice-9 receive)
  #:use-module (oop goops)
  #:duplicates (merge-generics)
  #:declarative? #t)

(with-test-environment
 "server-content"
 (lambda ()
   (false-if-exception
    ;; This is the etag of the root with the seed of the test
    (delete-file "tests/server-content.home/disfluid/server/content/6/8OMG_V5x-KmI6TI"))
   (false-if-exception
    ;; This is the etag of /wtf
    (delete-file "tests/server-content.home/disfluid/server/content/X/hqM_2Avn5_egTzs"))
   (parameterize ((current-content-cache (make <content-cache>)))
     (let ((/
            (make <content>
              #:content-type 'text/turtle
              #:contained '("/whatever" "/you" "/want")
              #:static-content "# This is the content of the root"))
           (/wtf
            (make <content>
              #:content-type 'text/plain
              #:static-content "This is the content of the wtf")))
       (unless (equal? (static-content /wtf)
                       (string->utf8 "This is the content of the wtf"))
         (exit 1))
       (delete-content /wtf)
       ;; Reload it with cache, it should still be available
       (set! /wtf (make <content> #:etag (etag /wtf)))
       ;; Reload it without session, and it should fail
       (parameterize ((current-content-cache #f))
         (when (false-if-exception (make <content> #:etag (etag /wtf)))
           (exit 2)))
       (unless (eq? (content-type /wtf) 'text/plain)
         (exit 3))
       (unless (eq? (content-type /) 'text/turtle)
         (exit 4))
       (unless (equal? (contained /) '("/whatever" "/you" "/want"))
         (exit 5))
       (unless (equal? (static-content /)
                       (string->utf8 "# This is the content of the root"))
         (exit 6))))))