From 1aa5acda7cbbfa00a6b4cde56c6963fa684f391b Mon Sep 17 00:00:00 2001 From: Piotr Szarmanski Date: Fri, 4 Aug 2023 19:39:32 +0200 Subject: New HTTP backend. --- extra/http/http-tests.lisp | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 extra/http/http-tests.lisp (limited to 'extra/http/http-tests.lisp') 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"))))) + + + + + -- cgit v1.2.3