summaryrefslogtreecommitdiff
path: root/src/couch/test/exunit/same_site_cookie_tests.exs
blob: bad32ada47157f06c470d4a1d0ae1e22f0d12687 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
defmodule SameSiteCookieTests do
  use CouchTestCase

  @moduletag :authentication

  def get_cookie(user, pass) do
    resp = Couch.post("/_session", body: %{:username => user, :password => pass})

    true = resp.body["ok"]
    resp.headers[:"set-cookie"]
  end

  @tag config: [{"admins", "jan", "apple"}, {"couch_httpd_auth", "same_site", "None"}]
  test "Set same_site None" do
    cookie = get_cookie("jan", "apple")
    assert cookie =~ "; SameSite=None"
  end

  @tag config: [{"admins", "jan", "apple"}, {"couch_httpd_auth", "same_site", ""}]
  test "same_site not set" do
    cookie = get_cookie("jan", "apple")
    assert cookie
    refute cookie =~ "; SameSite="
  end

  @tag config: [{"admins", "jan", "apple"}, {"couch_httpd_auth", "same_site", "Strict"}]
  test "Set same_site Strict" do
    cookie = get_cookie("jan", "apple")
    assert cookie =~ "; SameSite=Strict"
  end

  @tag config: [{"admins", "jan", "apple"}, {"couch_httpd_auth", "same_site", "Lax"}]
  test "Set same_site Lax" do
    cookie = get_cookie("jan", "apple")
    assert cookie =~ "; SameSite=Lax"
  end

  @tag config: [{"admins", "jan", "apple"}, {"couch_httpd_auth", "same_site", "Invalid"}]
  test "Set same_site invalid" do
    cookie = get_cookie("jan", "apple")
    assert cookie
    refute cookie =~ "; SameSite="
  end
end