|
1 | | -(in-package :io.github.cl-sdk.wst.test) |
| 1 | +(defpackage #:io.github.cl-sdk.wst.session.csrf.test |
| 2 | + (:use #:cl #:fiveam #:io.github.cl-sdk.wst.session.csrf)) |
2 | 3 |
|
3 | | -(5am:def-suite wst.session-csrf.suite |
| 4 | +(in-package #:io.github.cl-sdk.wst.session.csrf.test) |
| 5 | + |
| 6 | +(def-suite session-csrf-suite |
4 | 7 | :description "Tests for the wst.session.csrf package.") |
5 | 8 |
|
6 | | -(5am:in-suite wst.session-csrf.suite) |
| 9 | +(in-suite session-csrf-suite) |
7 | 10 |
|
8 | 11 | (defclass test-csrf-context () |
9 | 12 | ((csrf-token :initform nil |
10 | 13 | :accessor test-csrf-context-token))) |
11 | 14 |
|
12 | | -(defmethod io.github.cl-sdk.wst.session.csrf:session-csrf-token ((obj test-csrf-context) &key &allow-other-keys) |
| 15 | +(defmethod session-csrf-token ((obj test-csrf-context) &key &allow-other-keys) |
13 | 16 | (test-csrf-context-token obj)) |
14 | 17 |
|
15 | | -(defmethod io.github.cl-sdk.wst.session.csrf:add-session-csrf-token ((obj test-csrf-context) key &key &allow-other-keys) |
| 18 | +(defmethod add-session-csrf-token ((obj test-csrf-context) key &key &allow-other-keys) |
16 | 19 | (setf (test-csrf-context-token obj) key)) |
17 | 20 |
|
18 | | -(defmethod io.github.cl-sdk.wst.session.csrf:remove-session-csrf-token ((obj test-csrf-context) &key &allow-other-keys) |
| 21 | +(defmethod remove-session-csrf-token ((obj test-csrf-context) &key &allow-other-keys) |
19 | 22 | (setf (test-csrf-context-token obj) nil)) |
20 | 23 |
|
21 | | -(defmethod io.github.cl-sdk.wst.session.csrf:verify-session-csrf-token ((obj test-csrf-context) key &key &allow-other-keys) |
| 24 | +(defmethod verify-session-csrf-token ((obj test-csrf-context) key &key &allow-other-keys) |
22 | 25 | (let ((stored (test-csrf-context-token obj))) |
23 | 26 | (and stored key (string= stored key)))) |
24 | 27 |
|
25 | 28 | (5am:def-test session-csrf-token-lifecycle () |
26 | 29 | (let ((context (make-instance 'test-csrf-context))) |
27 | | - (5am:is-false (io.github.cl-sdk.wst.session.csrf:session-csrf-token context)) |
28 | | - (5am:is-false (io.github.cl-sdk.wst.session.csrf:verify-session-csrf-token context "csrf-1")) |
| 30 | + (5am:is-false (session-csrf-token context)) |
| 31 | + (5am:is-false (verify-session-csrf-token context "csrf-1")) |
29 | 32 |
|
30 | 33 | (5am:is (string= "csrf-1" |
31 | | - (io.github.cl-sdk.wst.session.csrf:add-session-csrf-token context "csrf-1"))) |
| 34 | + (add-session-csrf-token context "csrf-1"))) |
32 | 35 | (5am:is (string= "csrf-1" |
33 | | - (io.github.cl-sdk.wst.session.csrf:session-csrf-token context))) |
34 | | - (5am:is-true (io.github.cl-sdk.wst.session.csrf:verify-session-csrf-token context "csrf-1")) |
35 | | - (5am:is-false (io.github.cl-sdk.wst.session.csrf:verify-session-csrf-token context "csrf-2")) |
| 36 | + (session-csrf-token context))) |
| 37 | + (5am:is-true (verify-session-csrf-token context "csrf-1")) |
| 38 | + (5am:is-false (verify-session-csrf-token context "csrf-2")) |
36 | 39 |
|
37 | | - (5am:is-false (io.github.cl-sdk.wst.session.csrf:remove-session-csrf-token context)) |
38 | | - (5am:is-false (io.github.cl-sdk.wst.session.csrf:session-csrf-token context)) |
39 | | - (5am:is-false (io.github.cl-sdk.wst.session.csrf:verify-session-csrf-token context "csrf-1")))) |
| 40 | + (5am:is-false (remove-session-csrf-token context)) |
| 41 | + (5am:is-false (session-csrf-token context)) |
| 42 | + (5am:is-false (verify-session-csrf-token context "csrf-1")))) |
40 | 43 |
|
41 | 44 | (5am:def-test session-csrf-token-can-be-replaced () |
42 | 45 | (let ((context (make-instance 'test-csrf-context))) |
43 | | - (io.github.cl-sdk.wst.session.csrf:add-session-csrf-token context "csrf-old") |
44 | | - (5am:is-true (io.github.cl-sdk.wst.session.csrf:verify-session-csrf-token context "csrf-old")) |
| 46 | + (add-session-csrf-token context "csrf-old") |
| 47 | + (5am:is-true (verify-session-csrf-token context "csrf-old")) |
45 | 48 |
|
46 | | - (io.github.cl-sdk.wst.session.csrf:add-session-csrf-token context "csrf-new") |
47 | | - (5am:is-false (io.github.cl-sdk.wst.session.csrf:verify-session-csrf-token context "csrf-old")) |
48 | | - (5am:is-true (io.github.cl-sdk.wst.session.csrf:verify-session-csrf-token context "csrf-new")))) |
| 49 | + (add-session-csrf-token context "csrf-new") |
| 50 | + (5am:is-false (verify-session-csrf-token context "csrf-old")) |
| 51 | + (5am:is-true (verify-session-csrf-token context "csrf-new")))) |
0 commit comments