mirror of
https://github.com/bitwarden/server
synced 2026-02-14 23:45:11 +00:00
We want to reduce the amount of business critical test data in the company. One way of doing that is to generate test data on demand prior to client side testing. Clients will request a scene to be set up with a JSON body set of options, specific to a given scene. Successful seed requests will be responded to with a mangleMap which maps magic strings present in the request to the mangled, non-colliding versions inserted into the database. This way, the server is solely responsible for understanding uniqueness requirements in the database. scenes also are able to return custom data, depending on the scene. For example, user creation would benefit from a return value of the userId for further test setup on the client side. Clients will indicate they are running tests by including a unique header, x-play-id which specifies a unique testing context. The server uses this PlayId as the seed for any mangling that occurs. This allows the client to decide it will reuse a given PlayId if the test context builds on top of previously executed tests. When a given context is no longer needed, the API user will delete all test data associated with the PlayId by calling a delete endpoint. --------- Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
Play Services
Overview
The Play services provide automated testing infrastructure for tracking and cleaning up test data in development environments. A "Play" is a test session that groups entities (users, organizations, etc.) created during testing to enable bulk cleanup via the SeederAPI.
How It Works
- Test client sends
x-play-idheader with a unique Play identifier PlayIdMiddlewareextracts the header and sets it onIPlayIdService- Repositories check
IPlayIdService.InPlay()when creating entities IPlayItemServicerecords PlayItem entries for tracked entities- SeederAPI uses PlayItem records to bulk delete all entities associated with a PlayId
Play services are only active in Development environments.
Classes
IPlayIdService- Interface for managing Play identifiers in the current request scopeIPlayItemService- Interface for tracking entities created during a Play sessionPlayIdService- Default scoped implementation for tracking Play sessions per HTTP requestNeverPlayIdServices- No-op implementation used as fallback when no HttpContext is availablePlayIdSingletonService- Singleton wrapper that allows singleton services to access scoped PlayIdService via HttpContextPlayItemService- Implementation that records PlayItem entries for entities created during Play sessions