I'm upgrading IdentityServer4 to version 3.1 and I'm having an issue with an unit test after the upgrade. IdentityServer4.EntityFramework.Stores.ClientStore
was extended as we can see below:
public class IfloClientStore : ClientStore
{
private const string Saml2BearerClientSuffix = "_saml2bearer";
public IfloClientStore(IConfigurationDbContext context, ILogger<ClientStore> logger) : base(context, logger)
{
}
public override async Task<Client> FindClientByIdAsync(string clientId)
{
if(string.IsNullOrWhiteSpace(clientId))
throw new ArgumentException(nameof(clientId) +" is null or empty");
clientId = clientId.ToLowerInvariant();
var result = await base.FindClientByIdAsync(MapClientId(clientId));
if (result == null)
throw new ResourceNotFoundException(clientId);
if (IsSamlClient(clientId))
AllowSamlFlow(result);
return result;
}
private void AllowSamlFlow(Client client)
{
client.AllowedGrantTypes.Add(Constants.GrantTypes.Saml2BearerGrant);
}
private bool IsSamlClient(string clientId)
{
return clientId.EndsWith(Saml2BearerClientSuffix);
}
private string MapClientId(string clientId)
{
if (IsSamlClient(clientId))
return clientId.Substring(0, clientId.Length - Saml2BearerClientSuffix.Length);
return clientId;
}
}
My unit test:
[Test]
public async Task FindClientByIdAsync_Given_PFP_Saml2Bearer_Client_Return_PFP_SamlAllowed_Client()
{
var client = await underTest.FindClientByIdAsync(PfpWebClientIdForSaml);
client.ClientId.Should().Be(PfpWebClientId);
client.AllowedGrantTypes.Single().Should().Be("urn:ietf:params:oauth:grant-type:saml2-bearer");
}
This exception is being thrown when FindClientByIdAsync
is executed:
Message:
System.InvalidOperationException : The provider for the source IQueryable doesn't implement IAsyncQueryProvider. Only providers that implement IAsyncQueryProvider can be used for Entity Framework asynchronous operations.
Stack Trace:
EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable1 source, Expression expression, CancellationToken cancellationToken)
EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable
1 source, CancellationToken cancellationToken)
EntityFrameworkQueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable1 source, CancellationToken cancellationToken)
ClientStore.FindClientByIdAsync(String clientId)
IfloClientStore.FindClientByIdAsync(String clientId) line 27
TestIfloClientStore.FindClientByIdAsync_Given_PFP_Saml2Bearer_Client_Return_PFP_SamlAllowed_Client() line 43
GenericAdapter
1.GetResult()
AsyncToSyncAdapter.Await(Func`1 invoke)
TestMethodCommand.RunTestMethod(TestExecutionContext context)
TestMethodCommand.Execute(TestExecutionContext context)
<>c__DisplayClass1_0.b__0()
BeforeAndAfterTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
If I downgrade IdentityServer4.EntityFramework
to version 3.0 it works just fine. But I want to ensure if IDS4 has a bug or if I must change something because of the upgrade. Could someone help me?