Test_Encrypt_Cookie_Custom_Encryptor() — fiber Function Reference
Architecture documentation for the Test_Encrypt_Cookie_Custom_Encryptor() function in encryptcookie_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 1c7e488f_f8fa_9bad_b715_427558635993["Test_Encrypt_Cookie_Custom_Encryptor()"] ac3bbef3_a1d3_d68b_64fb_619088dde10d["encryptcookie_test.go"] 1c7e488f_f8fa_9bad_b715_427558635993 -->|defined in| ac3bbef3_a1d3_d68b_64fb_619088dde10d style 1c7e488f_f8fa_9bad_b715_427558635993 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/encryptcookie/encryptcookie_test.go lines 337–385
func Test_Encrypt_Cookie_Custom_Encryptor(t *testing.T) {
t.Parallel()
testKey := GenerateKey(32)
app := fiber.New()
app.Use(New(Config{
Key: testKey,
Encryptor: func(_, decryptedString, _ string) (string, error) {
return base64.StdEncoding.EncodeToString([]byte(decryptedString)), nil
},
Decryptor: func(_, encryptedString, _ string) (string, error) {
decodedBytes, err := base64.StdEncoding.DecodeString(encryptedString)
return string(decodedBytes), err
},
}))
app.Get("/", func(c fiber.Ctx) error {
return c.SendString("value=" + c.Cookies("test"))
})
app.Post("/", func(c fiber.Ctx) error {
c.Cookie(&fiber.Cookie{
Name: "test",
Value: "SomeThing",
})
return nil
})
h := app.Handler()
ctx := &fasthttp.RequestCtx{}
ctx.Request.Header.SetMethod(fiber.MethodPost)
h(ctx)
require.Equal(t, 200, ctx.Response.StatusCode())
encryptedCookie := fasthttp.Cookie{}
encryptedCookie.SetKey("test")
require.True(t, ctx.Response.Header.Cookie(&encryptedCookie), "Get cookie value")
decodedBytes, err := base64.StdEncoding.DecodeString(string(encryptedCookie.Value()))
require.NoError(t, err)
require.Equal(t, "SomeThing", string(decodedBytes))
ctx = &fasthttp.RequestCtx{}
ctx.Request.Header.SetMethod(fiber.MethodGet)
ctx.Request.Header.SetCookie("test", string(encryptedCookie.Value()))
h(ctx)
require.Equal(t, 200, ctx.Response.StatusCode())
require.Equal(t, "value=SomeThing", string(ctx.Response.Body()))
}
Domain
Subdomains
Source
Frequently Asked Questions
What does Test_Encrypt_Cookie_Custom_Encryptor() do?
Test_Encrypt_Cookie_Custom_Encryptor() is a function in the fiber codebase, defined in middleware/encryptcookie/encryptcookie_test.go.
Where is Test_Encrypt_Cookie_Custom_Encryptor() defined?
Test_Encrypt_Cookie_Custom_Encryptor() is defined in middleware/encryptcookie/encryptcookie_test.go at line 337.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free