Fosi Fossil Service
Small teams. Open source. Built on Fossil.

CaaS / Lamina

Unified Management for Fossil Repositories

Public | Owner: CaaS | Default branch: trunk | Last update: 2026-10-25 00:41

Artifact 1304c9df7b730a12c573724e997ce23a026cd1c001bb88de09a88f16b019d715:


(defmodule lamina_proxy_tests
  (export all)
  (include-lib "eunit/include/eunit.hrl"))

(defun split-resp-headers-strips-set-cookie-and-hop-by-hop_test ()
  (let (((tuple hdrs cookies)
         (h_proxy:split-resp-headers
          (list (tuple "Location" "/nigfossil/")
                (tuple "Set-Cookie" "fossil=abc; Path=/nigfossil; HttpOnly")
                (tuple "set-cookie" "sid=1; Path=/")
                (tuple "Content-Length" "12")
                (tuple "Content-Type" "text/html")))))
    (if (and (=:= #"/nigfossil/" (maps:get #"location" hdrs))
             (=:= #"text/html" (maps:get #"content-type" hdrs))
             (not (maps:is_key #"set-cookie" hdrs))
             (not (maps:is_key #"content-length" hdrs))
             (=:= 2 (length cookies)))
        'ok
        (erlang:error (list "split-resp-headers failed" hdrs cookies)))))

(defun allowed-req-header-forwards-referer-and-origin_test ()
  (if (and (h_proxy:allowed-req-header #"referer")
           (h_proxy:allowed-req-header #"origin")
           (h_proxy:allowed-req-header #"cookie")
           (not (h_proxy:allowed-req-header #"x-forwarded-for")))
      'ok
      (erlang:error "proxy header allowlist should keep Referer/Origin")))

(defun cookie-opts-keeps-cowboy-fields-from-set-cookie_test ()
  (let ((parsed (cow_cookie:parse_set_cookie
                 #"fossil=abc; Path=/nigfossil; HttpOnly; Secure; SameSite=Lax; Max-Age=3600")))
    (case parsed
      (`#(ok ,_name ,_value ,attrs)
       (let ((opts (h_proxy:cookie-opts attrs)))
         (if (and (=:= #"/nigfossil" (maps:get 'path opts))
                  (=:= 'true (maps:get 'http_only opts))
                  (=:= 'true (maps:get 'secure opts))
                  (=:= 'lax (maps:get 'same_site opts))
                  (not (maps:is_key 'max_age opts))
                  (not (maps:is_key 'expires opts)))
             'ok
             (erlang:error (list "cookie-opts failed" attrs opts)))))
      (other (erlang:error (list "parse_set_cookie failed" other))))))

(defun put-cookie-uses-cowboy-resp-cookies_test ()
  (let ((req (h_proxy:put-cookie
              "fossil-login=deadbeef; Path=/nigfossil; HttpOnly; SameSite=Lax"
              #M())))
    (let ((cookies (maps:get 'resp_cookies req #M())))
      (if (maps:is_key #"fossil-login" cookies)
          'ok
          (erlang:error (list "cookie was not stored" req))))))

Clone

You can clone this repository with the following command:

fossil clone https://fosi.dev/CaaS/Lamina

Contribute

The best way to contribute is through e-mail. See the project documentation for more details.