Class SignedInAsAttribute

Namespace
ProtoTest.Http
Assembly
ProtoTest.Http.dll

Declares the user a test signs in as, for example [SignedInAs("alice", "admin", "billing")]. The identity is published to the test's execution context (read it with context.SignedInUser()) and rides the existing HTTP auth lifecycle: REST, GraphQL and gRPC requests carry it to the application, and the protocol's Auth entity names the declaration among its authenticators. The shipped app-side authentication (AddTestUserAuthentication in ProtoTest.AspNetCore) turns it into the application's ClaimsPrincipal; without an in-process application the shipped transport stays inert, the request is sent unchanged and the auth:user entity records the reason.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class SignedInAsAttribute : ProtoAttribute
Inheritance
SignedInAsAttribute
Inherited Members
Extension Methods

Examples

[ProtoTest]
[SignedInAs("alice", "Administrator", Claims = new[] { "tenant=northstar" })]
public async Task AdministratorsCanCreateProjects() { ... }

Remarks

The declaration is orthogonal to [Auth<T>] - it names who the test acts as, not how a request is authenticated - so a method-level [SignedInAs] rides along with a class-level authenticator instead of replacing it.

Constructors

SignedInAsAttribute(string, params string[])

Declares the identity; roles follow the name.

public SignedInAsAttribute(string name = "test-user", params string[] roles)

Parameters

name string
roles string[]

Fields

DefaultName

The name a bare [SignedInAs] signs in as.

public const string DefaultName = "test-user"

Field Value

string

Properties

Claims

Gets claims in type=value form, for example new[] { "tenant=northstar" }. The auth:user trace entity records only the claim types; embedded test source or captured content can still contain a value.

public string[] Claims { get; init; }

Property Value

string[]

Name

Gets the user name.

public string Name { get; }

Property Value

string

Roles

Gets the user's roles.

public IReadOnlyList<string> Roles { get; }

Property Value

IReadOnlyList<string>

Methods

BeforeTestAsync(ProtoExecutionContext)

Executed asynchronously before the decorated test or class tests execute.

public override Task BeforeTestAsync(ProtoExecutionContext context)

Parameters

context ProtoExecutionContext

Returns

Task