passwordless-server
passwordless-server copied to clipboard
Add some tests
Added Tests to SharedManagementServiceTests for CreateApiKeyAsync method
and I like to know what should I use instead of
https://github.com/bitwarden/passwordless-server/blob/1f47bf111e4f4e6bb2aaee632006219e8cd135b8/src/Service/Storage/Ef/DbTenantFactory.cs#L14
In your tests, you need to use the ITenantStorageFactory, and mock it to return an ITenantStorage mock.
Then for
var tenantStorageMock = new Mock<ITenantStorage>(); you can mock any method to return something you choose.
Directly using the ITenantStorage anywhere in your application assumes the public key or private key are valid and have populated the relevant claim to instantiate ITenantStorage with TenantProvider. But you don't have to worry about TenantProvider as it is being populated automatically from the claims once authenticated.
When API keys are being validated, you will always have to use the factory for this reason.
What do you mean you want to know what you'd like instead of the factory method?
[Obsolete("Use injected ITenantStorage instead when not calling from ManagementKey scope.")]
its obsolete
What do you mean you want to know what you'd like instead of the factory method?
[Obsolete("Use injected
ITenantStorageinstead when not calling fromManagementKeyscope.")] its obsolete
See my comment above :-)
What do you mean you want to know what you'd like instead of the factory method?
[Obsolete("Use injected
ITenantStorageinstead when not calling fromManagementKeyscope.")] its obsoleteSee my comment above :-)
thanks
@jonashendrickx can you review this?
@jonashendrickx can you review this?
Can you run dotnet format in your working directory and push again?
Looks good overall, you could theoretically also verify you're calling StoreApiKey with the parameters you expect to be passed. I've gotten bitten often enough by mappings that were wrong.
It could look like:
storageMock.Verify(x => x.StoreApiKeyAsync(It.Is<string>(p => p == pk), It.Is<string>(p => p == publicKey), It.Is<PublicKeyScopes[]>(p => p == scopes)), Times.Once);
@jonashendrickx can you review this?
Can you run
dotnet formatin your working directory and push again?Looks good overall, you could theoretically also verify you're calling
StoreApiKeywith the parameters you expect to be passed. I've gotten bitten often enough by mappings that were wrong.It could look like:
storageMock.Verify(x => x.StoreApiKeyAsync(It.Is<string>(p => p == pk), It.Is<string>(p => p == publicKey), It.Is<PublicKeyScopes[]>(p => p == scopes)), Times.Once);
@jonashendrickx
I don't have the pk and publicKey in arrange level of test, the guid is generated inside of SetupApiKeyAsync method how can I have them as expected ?
I wrote it like this
storageMock.Verify(x => x.StoreApiKeyAsync(It.IsAny<string>(), It.IsAny<string>(),
It.Is<string[]>(p => p == scopes.Select(s => s.GetValue()).ToArray())), Times.Once);
but it give this error " Expected invocation on the mock once, but was 0 times" I don't know why can you check this