(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")))))