tangled
alpha
login
or
join now
keii.dev
/
wisp
3
fork
atom
🧚 A practical web framework for Gleam
3
fork
atom
overview
issues
pulls
pipelines
Test cookie helper
Louis Pilfold
2 years ago
123767c4
4376512c
+26
-37
3 changed files
expand all
collapse all
unified
split
src
wisp.gleam
test
wisp
testing_test.gleam
wisp_test.gleam
+3
-16
src/wisp.gleam
···
1802
1802
|> request.get_cookies
1803
1803
|> list.key_find(name),
1804
1804
)
1805
1805
-
case security {
1805
1805
+
use value <- result.try(case security {
1806
1806
PlainText -> base.decode64(value)
1807
1807
Signed -> verify_signed_message(request, value)
1808
1808
-
}
1809
1809
-
|> result.try(bit_string.to_string)
1808
1808
+
})
1809
1809
+
bit_string.to_string(value)
1810
1810
}
1811
1811
-
1812
1812
-
/// Get all the cookies for a request.
1813
1813
-
///
1814
1814
-
/// Any malformed cookies will be ignored, as specified in RFC6265.
1815
1815
-
///
1816
1816
-
/// # Examples
1817
1817
-
///
1818
1818
-
/// ```gleam
1819
1819
-
/// wisp.get_cookies(request)
1820
1820
-
/// // -> [#("accepted", "1"), #("group", "A")]
1821
1821
-
/// ```
1822
1822
-
///
1823
1823
-
pub const get_cookies = request.get_cookies
1824
1811
1825
1812
//
1826
1813
// Testing
+23
test/wisp/testing_test.gleam
···
581
581
#("accept", "application/json"),
582
582
])
583
583
}
584
584
+
585
585
+
pub fn set_cookie_plain_text_test() {
586
586
+
let req =
587
587
+
testing.get("/", [])
588
588
+
|> testing.set_cookie("abc", "1234", wisp.PlainText)
589
589
+
|> testing.set_cookie("def", "5678", wisp.PlainText)
590
590
+
req.headers
591
591
+
|> should.equal([#("cookie", "abc=MTIzNA; def=NTY3OA")])
592
592
+
}
593
593
+
594
594
+
pub fn set_cookie_signed_test() {
595
595
+
let req =
596
596
+
testing.get("/", [])
597
597
+
|> testing.set_cookie("abc", "1234", wisp.Signed)
598
598
+
|> testing.set_cookie("def", "5678", wisp.Signed)
599
599
+
req.headers
600
600
+
|> should.equal([
601
601
+
#(
602
602
+
"cookie",
603
603
+
"abc=SFM1MTI.MTIzNA.QWGuB_lZLssnh71rC6R5_WOr8MDr8dxE3C_2JvLRAAC4ad4SnmQk0Fl_6_RrtmzdH2O3WaNPExkJsuwBixtWIA; def=SFM1MTI.NTY3OA.R3HRe5woa1qwxvjRUC5ggQVd3hTqGCXIk_4ybU35SXPtGvLrFpHBXWGIjyG5QeuEk9j3jnWIL3ct18olJiSCMw",
604
604
+
),
605
605
+
])
606
606
+
}
-21
test/wisp_test.gleam
···
968
968
out
969
969
|> should.equal(message)
970
970
}
971
971
-
972
972
-
pub fn get_cookies_test() {
973
973
-
let request =
974
974
-
testing.get(
975
975
-
"/",
976
976
-
[
977
977
-
#("cookie", "id=123; flash=hi-there; other=456"),
978
978
-
#("cookie", "wibble=789; id=456"),
979
979
-
],
980
980
-
)
981
981
-
982
982
-
request
983
983
-
|> wisp.get_cookies
984
984
-
|> should.equal([
985
985
-
#("id", "123"),
986
986
-
#("flash", "hi-there"),
987
987
-
#("other", "456"),
988
988
-
#("wibble", "789"),
989
989
-
#("id", "456"),
990
990
-
])
991
991
-
}