MCPcopy
hub / github.com/gofiber/fiber / TestSharedState_KeyNamespacingWithOverlappingPrefixes

Function TestSharedState_KeyNamespacingWithOverlappingPrefixes

shared_state_test.go:285–302  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

283}
284
285func TestSharedState_KeyNamespacingWithOverlappingPrefixes(t *testing.T) {
286 t.Parallel()
287
288 store := newSharedStateMemoryStorage(t)
289 shortPrefixApp := New(Config{AppName: "app", SharedStorage: store})
290 longPrefixApp := New(Config{AppName: "app-one", SharedStorage: store})
291
292 err := longPrefixApp.SharedState().Set("session:123", []byte("victim-secret"), time.Minute)
293 require.NoError(t, err)
294
295 err = shortPrefixApp.SharedState().Set("one-session:123", []byte("attacker-value"), time.Minute)
296 require.NoError(t, err)
297
298 data, found, err := longPrefixApp.SharedState().Get("session:123")
299 require.NoError(t, err)
300 require.True(t, found)
301 require.Equal(t, []byte("victim-secret"), data)
302}
303
304func TestSharedState_StorageErrorsArePropagated(t *testing.T) {
305 t.Parallel()

Callers

nothing calls this directly

Calls 5

SharedStateMethod · 0.80
NewFunction · 0.70
SetMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected