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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
;; webid-oidc, 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/>.
(use-modules (webid-oidc cache)
(webid-oidc testing)
((webid-oidc parameters) #:prefix p:)
(web uri)
(web request)
(web response)
(srfi srfi-19)
(ice-9 optargs)
(ice-9 receive))
(with-test-environment
"cache-valid"
(lambda ()
(define response-not-stored
(build-response #:headers `((cache-control . (no-store)))))
(define response-not-cached
(build-response #:headers `((cache-control . (no-cache)))))
(define response-with-expires
(build-response #:headers `((expires . ,(time-utc->date (make-time time-utc 0 120))))))
(define response-with-overriden-expires
(build-response #:headers `((expires . ,(time-utc->date (make-time time-utc 0 120)))
(cache-control . (private (max-age . 100)))
(date . ,(time-utc->date (make-time time-utc 0 10))))))
(define response-without-max-age
(build-response #:headers `((cache-control . (private))
(date . ,(time-utc->date (make-time time-utc 0 10))))))
(define response-with-heuristic-max-age
(build-response #:headers `((cache-control . (private))
(last-modified . ,(time-utc->date (make-time time-utc 0 10)))
(date . ,(time-utc->date (make-time time-utc 0 30))))))
;; response-not-stored: never valid.
(parameterize ((p:current-date 0))
(when (valid? response-not-stored)
(exit 1)))
(parameterize ((p:current-date 100))
(when (valid? response-not-stored)
(exit 2)))
;; response-not-cached: never valid.
(parameterize ((p:current-date 0))
(when (valid? response-not-cached)
(exit 3)))
(parameterize ((p:current-date 100))
(when (valid? response-not-cached)
(exit 4)))
;; response-with-expires: valid at 110, invalid at 130.
(parameterize ((p:current-date 110))
(unless (valid? response-with-expires)
(exit 5)))
(parameterize ((p:current-date 130))
(when (valid? response-with-expires)
(exit 6)))
;; response-with-overriden-expires: valid at 105, invalid at 115
(parameterize ((p:current-date 105))
(unless (valid? response-with-overriden-expires)
(exit 7)))
(parameterize ((p:current-date 115))
(when (valid? response-with-overriden-expires)
(exit 8)))
;; response-without-max-age: not valid, cannot get a heuristic
(parameterize ((p:current-date 10))
(when (valid? response-without-max-age)
(exit 9)))
;; response-with-heuristic-max-age: the heuristic max age is 2, so
;; it is valid at 31 but not at 33.
(parameterize ((p:current-date 31))
(unless (valid? response-with-heuristic-max-age)
(exit 10)))
(parameterize ((p:current-date 33))
(when (valid? response-with-heuristic-max-age)
(exit 11)))))
|