mirror of
https://github.com/bitwarden/server
synced 2026-02-12 22:44:00 +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>
61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.Utilities;
|
|
|
|
namespace Bit.Core.Entities;
|
|
|
|
/// <summary>
|
|
/// PlayItem is a join table tracking entities created during automated testing.
|
|
/// A `PlayId` is supplied by the clients in the `x-play-id` header to inform the server
|
|
/// that any data created should be associated with the play, and therefore cleaned up with it.
|
|
/// </summary>
|
|
public class PlayItem : ITableObject<Guid>
|
|
{
|
|
public Guid Id { get; set; }
|
|
[MaxLength(256)]
|
|
public required string PlayId { get; init; }
|
|
public Guid? UserId { get; init; }
|
|
public Guid? OrganizationId { get; init; }
|
|
public DateTime CreationDate { get; init; }
|
|
|
|
/// <summary>
|
|
/// Generates and sets a new COMB GUID for the Id property.
|
|
/// </summary>
|
|
public void SetNewId()
|
|
{
|
|
Id = CoreHelpers.GenerateComb();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new PlayItem record associated with a User.
|
|
/// </summary>
|
|
/// <param name="user">The user entity created during the play.</param>
|
|
/// <param name="playId">The play identifier from the x-play-id header.</param>
|
|
/// <returns>A new PlayItem instance tracking the user.</returns>
|
|
public static PlayItem Create(User user, string playId)
|
|
{
|
|
return new PlayItem
|
|
{
|
|
PlayId = playId,
|
|
UserId = user.Id,
|
|
CreationDate = DateTime.UtcNow
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new PlayItem record associated with an Organization.
|
|
/// </summary>
|
|
/// <param name="organization">The organization entity created during the play.</param>
|
|
/// <param name="playId">The play identifier from the x-play-id header.</param>
|
|
/// <returns>A new PlayItem instance tracking the organization.</returns>
|
|
public static PlayItem Create(Organization organization, string playId)
|
|
{
|
|
return new PlayItem
|
|
{
|
|
PlayId = playId,
|
|
OrganizationId = organization.Id,
|
|
CreationDate = DateTime.UtcNow
|
|
};
|
|
}
|
|
}
|