summaryrefslogtreecommitdiff
path: root/extra/http/http-tests.lisp
diff options
context:
space:
mode:
authorPiotr Szarmanski2023-08-04 19:39:32 +0200
committerPiotr Szarmanski2023-08-04 19:39:32 +0200
commit1aa5acda7cbbfa00a6b4cde56c6963fa684f391b (patch)
tree96e3399e1673ad80db5027121804786889e62688 /extra/http/http-tests.lisp
parent6b3457b35cbcea4e28d3482263a36ae6db39fc8f (diff)
New HTTP backend.
Diffstat (limited to 'extra/http/http-tests.lisp')
-rw-r--r--extra/http/http-tests.lisp72
1 files changed, 72 insertions, 0 deletions
diff --git a/extra/http/http-tests.lisp b/extra/http/http-tests.lisp
new file mode 100644
index 0000000..38dfac8
--- /dev/null
+++ b/extra/http/http-tests.lisp
@@ -0,0 +1,72 @@
+(defpackage #:eris-http-tests
+ (:use #:common-lisp #:serapeum #:fiveam #:eris-http-server #:eris-http-client))
+
+(in-package :eris-http-tests)
+
+
+(defun make-temporary-dir ()
+ (let* ((tmpdir (uiop:temporary-directory))
+ (tmp-tmpdir (make-pathname
+ :directory (serapeum:append1
+ (pathname-directory tmpdir)
+ (ironclad:byte-array-to-hex-string (ironclad:random-data 10)))
+ :defaults tmpdir)))
+ (ensure-directories-exist tmp-tmpdir)
+ tmp-tmpdir))
+
+(defmacro with-temporary-dir (sym &body expr)
+ `(let ((,sym (make-temporary-dir)))
+ (unwind-protect
+ (progn ,@expr)
+ (uiop:delete-directory-tree ,sym :validate t))))
+
+(defmacro with-clack (handler &body expr)
+ (alexandria:with-gensyms (v)
+ `(let ((,v (clack:clackup ,handler)))
+ (unwind-protect (progn ,@expr)
+ (progn (format t "STOPPING CLACK ~%") (clack:stop ,v))))))
+
+;; (base64:string-to-base64-string "test:test")
+(alexandria:define-constant auth '("dGVzdDp0ZXN0") :test #'equal)
+
+(def-suite* eris-http-tests)
+
+(test basic-http-rw
+ (with-temporary-dir tdir
+ (with-clack (eris-handler tdir :auth auth)
+ (let ((backend (make-instance 'http-backend :endpoint "http://127.0.0.1:5000/uri-res/"
+ :auth '("test" . "test"))))
+ (for-all ((buffer (gen-buffer :length (gen-integer :min 1 :max 80000))))
+ (is (equalp (alexandria:read-stream-content-into-byte-vector
+ (eris:fetch-data
+ (eris:store-data buffer backend)
+ backend))
+ buffer))
+ (is (equalp (alexandria:read-stream-content-into-byte-vector
+ (eris:fetch-data
+ (eris:store-data (make-array 40000 :element-type 'octet :initial-element 2) backend)
+ backend))
+ (make-array 40000 :element-type 'octet :initial-element 2))))))))
+
+(test bad-inputs
+ (with-temporary-dir tdir
+ (with-clack (eris-handler tdir :auth auth)
+ (signals error
+ (dexador:get "http://127.0.0.1:5000/lole"))
+ (signals error
+ (dexador:get "http://127.0.0.1:5000/../../"))
+ (signals error
+ (dexador:get "http://127.0.0.1:5000/uri-res/N2R?urn:blake2b:../../passwd"))
+ (signals error
+ (dexador:get "http://127.0.0.1:5000/uri-res/N2R?urn:blake2b:not"))
+ (signals error
+ (dexador:get "http://127.0.0.1:5000/uri-res/random-data"))
+ (signals error
+ (dexador:get "http://127.0.0.1:5000/../../../shadow"))
+ (signals error
+ (dexador:get "http://127.0.0.1:5000/uri-res/../something")))))
+
+
+
+
+