mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 03:17:04 +00:00
enhanced cookie security and management
Former-commit-id: a97b0b33e87749a2e8c32e63269fcc60fa326ff3
This commit is contained in:
@@ -7,25 +7,25 @@ import (
|
||||
"github.com/kataras/iris/v12/httptest"
|
||||
)
|
||||
|
||||
func TestCookiesBasic(t *testing.T) {
|
||||
func TestSecureCookie(t *testing.T) {
|
||||
app := newApp()
|
||||
e := httptest.New(t, app, httptest.URL("http://example.com"))
|
||||
|
||||
cookieName, cookieValue := "my_cookie_name", "my_cookie_value"
|
||||
|
||||
// Test Set A Cookie.
|
||||
// Test set a Cookie.
|
||||
t1 := e.GET(fmt.Sprintf("/cookies/%s/%s", cookieName, cookieValue)).Expect().Status(httptest.StatusOK)
|
||||
// note that this will not work because it doesn't always returns the same value:
|
||||
// cookieValueEncoded, _ := sc.Encode(cookieName, cookieValue)
|
||||
t1.Cookie(cookieName).Value().NotEqual(cookieValue) // validate cookie's existence and value is not on its raw form.
|
||||
t1.Body().Contains(cookieValue)
|
||||
|
||||
// Test Retrieve A Cookie.
|
||||
// Test retrieve a Cookie.
|
||||
t2 := e.GET(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
t2.Body().Equal(cookieValue)
|
||||
|
||||
// Test Remove A Cookie.
|
||||
t3 := e.DELETE(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
// Test remove a Cookie.
|
||||
t3 := e.GET(fmt.Sprintf("/cookies/remove/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
t3.Body().Contains(cookieName)
|
||||
|
||||
t4 := e.GET(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
|
||||
Reference in New Issue
Block a user