Test_Session_Fresh_Flag_Bug() — fiber Function Reference
Architecture documentation for the Test_Session_Fresh_Flag_Bug() function in session_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 414018fe_88f0_9d73_472d_54e1d7c95904["Test_Session_Fresh_Flag_Bug()"] 397e6e82_749b_4ef2_9365_02be671c59f7["session_test.go"] 414018fe_88f0_9d73_472d_54e1d7c95904 -->|defined in| 397e6e82_749b_4ef2_9365_02be671c59f7 style 414018fe_88f0_9d73_472d_54e1d7c95904 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/session/session_test.go lines 1572–1618
func Test_Session_Fresh_Flag_Bug(t *testing.T) {
t.Parallel()
store := NewStore()
app := fiber.New()
// Test Case 1: First call with no session cookie - should be fresh
ctx1 := app.AcquireCtx(&fasthttp.RequestCtx{})
sess1, err := store.Get(ctx1)
require.NoError(t, err)
require.True(t, sess1.Fresh(), "First session should be fresh (no cookie provided)")
sessionID := sess1.ID()
require.NoError(t, sess1.Save())
sess1.Release()
app.ReleaseCtx(ctx1)
// Test Case 2: Second call with session cookie - should NOT be fresh
ctx2 := app.AcquireCtx(&fasthttp.RequestCtx{})
ctx2.Request().Header.SetCookie("session_id", sessionID)
sess2, err := store.Get(ctx2)
require.NoError(t, err)
require.False(t, sess2.Fresh(), "Existing session should not be fresh")
require.Equal(t, sessionID, sess2.ID())
// Test Case 3: Call getSession() again in the same request
// This simulates what happens when CSRF middleware calls store operations
// The session ID is now in context locals from the first getSession() call
sess3, err := store.getSession(ctx2)
require.NoError(t, err)
require.False(t, sess3.Fresh(), "Session should still not be fresh on second getSession() call in same request")
require.Equal(t, sessionID, sess3.ID())
sess2.Release()
sess3.Release()
app.ReleaseCtx(ctx2)
// Test Case 4: Expired session - should generate new ID and be fresh
ctx3 := app.AcquireCtx(&fasthttp.RequestCtx{})
ctx3.Request().Header.SetCookie("session_id", "expired-or-nonexistent-id")
sess4, err := store.Get(ctx3)
require.NoError(t, err)
require.True(t, sess4.Fresh(), "New session (after expired/missing data) should be fresh")
require.NotEqual(t, "expired-or-nonexistent-id", sess4.ID(), "Should have generated a new session ID")
sess4.Release()
app.ReleaseCtx(ctx3)
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_Session_Fresh_Flag_Bug() do?
Test_Session_Fresh_Flag_Bug() is a function in the fiber codebase, defined in middleware/session/session_test.go.
Where is Test_Session_Fresh_Flag_Bug() defined?
Test_Session_Fresh_Flag_Bug() is defined in middleware/session/session_test.go at line 1572.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free