Skip to content
Tracon

ApiKeyStoreContract

Namespace Tracon.Testing.Contracts.Storage · Assembly Tracon.Testing.Contracts.Xunit.dll

Behavior tests for the IApiKeyStore contract.

public abstract class ApiKeyStoreContract : TenantIsolationContract<IApiKeyStore>, IAsyncLifetime, IAsyncDisposable
Inheritance
object ← StoreCancellationContract<IApiKeyStore> ← TenantIsolationContract<IApiKeyStore> ← ApiKeyStoreContract
Implements
IAsyncLifetime, IAsyncDisposable
Inherited Members
TenantIsolationContract<IApiKeyStore>.TenantA, TenantIsolationContract<IApiKeyStore>.TenantB, TenantIsolationContract<IApiKeyStore>.UseAmbientTenant(MutableTenantContext), TenantIsolationContract<IApiKeyStore>.SeedAsync(string, string, CancellationToken), TenantIsolationContract<IApiKeyStore>.ExistsAsync(string, object), TenantIsolationContract<IApiKeyStore>.CountAsync(string, CancellationToken), TenantIsolationContract<IApiKeyStore>.TryDeleteAsync(string, object), TenantIsolationContract<IApiKeyStore>.TryOverwriteAsync(string, string), TenantIsolationContract<IApiKeyStore>.CancellableReadAsync(CancellationToken), TenantIsolationContract<IApiKeyStore>.CancellableWriteAsync(CancellationToken), TenantIsolationContract<IApiKeyStore>.WroteAnythingAsync(), TenantIsolationContract<IApiKeyStore>.Tenant_cannot_read_another_tenants_record(), TenantIsolationContract<IApiKeyStore>.Tenant_reads_its_own_record(), TenantIsolationContract<IApiKeyStore>.Tenant_does_not_see_another_tenants_record_in_the_list(), TenantIsolationContract<IApiKeyStore>.Tenant_cannot_delete_another_tenants_record(), TenantIsolationContract<IApiKeyStore>.Same_name_lives_independently_across_two_tenants(), TenantIsolationContract<IApiKeyStore>.AmbientTenant, StoreCancellationContract<IApiKeyStore>.CreateStoreAsync(), StoreCancellationContract<IApiKeyStore>.InitializeAsync(), StoreCancellationContract<IApiKeyStore>.DisposeAsync(), StoreCancellationContract<IApiKeyStore>.OnDisposeAsync(), StoreCancellationContract<IApiKeyStore>.CancellableReadAsync(CancellationToken), StoreCancellationContract<IApiKeyStore>.CancellableWriteAsync(CancellationToken), StoreCancellationContract<IApiKeyStore>.WroteAnythingAsync(), StoreCancellationContract<IApiKeyStore>.Canceled_token_throws_on_read(), StoreCancellationContract<IApiKeyStore>.The_write_this_contract_checks_can_be_read_back(), StoreCancellationContract<IApiKeyStore>.Canceled_token_throws_on_write_and_leaves_no_trace(), StoreCancellationContract<IApiKeyStore>.Store, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

In this contract, the raw key value is visible only in the ApiKeyCreationResult.PlaintextKey returned by IApiKeyStore.CreateAsync; no read path (IApiKeyStore.ListAsync, IApiKeyStore.FindByHashAsync) returns the raw value or its hash.

protected ApiKeyStoreContract()
[Fact]
public Task Active_scope_is_found_system_wide()

Task

[Fact]
public Task Cannot_revoke_another_tenants_key()

Task

Reports how many records the given tenant sees through the listing endpoint.

protected override ValueTask<int> CountAsync(string tenantId, CancellationToken cancellationToken)

tenantId string

The reading tenant.

cancellationToken CancellationToken

The token every store call inside the hook must be handed; see TenantIsolationContract.SeedAsync.

ValueTask<int>

The number of records seen.

Reports whether the record is visible from the given tenant’s viewpoint.

protected override ValueTask<bool> ExistsAsync(string tenantId, object key)

tenantId string

The reading tenant.

key object

The key returned by TenantIsolationContract.SeedAsync.

ValueTask<bool>

true if the record is visible.

[Fact]
public Task Expiration_is_read_back()

Task

Finding_another_tenants_key_by_hash_returns_the_correct_tenant()

Section titled “ Finding_another_tenants_key_by_hash_returns_the_correct_tenant()”
[Fact]
public Task Finding_another_tenants_key_by_hash_returns_the_correct_tenant()

Task

[Fact]
public Task Found_by_hash_of_the_raw_value()

Task

[Fact]
public Task Last_used_timestamp_is_updated()

Task

Revoked_key_carries_RevokedAt_and_appears_inactive()

Section titled “ Revoked_key_carries_RevokedAt_and_appears_inactive()”
[Fact]
public Task Revoked_key_carries_RevokedAt_and_appears_inactive()

Task

[Fact]
public Task Revoked_keys_scope_is_no_longer_active()

Task

[Fact]
public Task Same_key_cannot_be_revoked_twice()

Task

[Fact]
public Task Saved_key_is_read_back()

Task

SeedAsync(string, string, CancellationToken)

Section titled “ SeedAsync(string, string, CancellationToken)”

Writes a sample record for the given tenant.

protected override ValueTask<object> SeedAsync(string tenantId, string name, CancellationToken cancellationToken)

tenantId string

The tenant that owns the record.

name string

The name distinguishing the record. The same name may be used by two tenants.

cancellationToken CancellationToken

The token every store call inside the hook must be handed. The cancellation contract calls this hook with a token that is already cancelled, so a hook that drops the token reports a store as sound when it is not.

ValueTask<object>

The key to use for reading the record back.

Attempts to delete the record on behalf of the given tenant.

protected override ValueTask<bool?> TryDeleteAsync(string tenantId, object key)

tenantId string

The tenant attempting the delete.

key object

The key returned by TenantIsolationContract.SeedAsync.

ValueTask<bool?>

true if the delete succeeded, false if the record was not found; null if the store does not offer deletion.

[Fact]
public Task Unknown_hash_is_not_found()

Task