1

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, IQueryable1 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 GenericAdapter1.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?

  • Did you see this posting? https://stackoverflow.com/questions/51023223/the-provider-for-the-source-iqueryable-doesnt-implement-iasyncqueryprovider – jdweng Jan 06 '20 at 16:39
  • I did, but my question is specifically about the IDS4 upgrade and this post is about unit tests for async methods. As I mentioned, it works before the upgrade and I want to figure out what is the reason why it no longer works with IDS4 new version – Leonardo Oliveira Jan 07 '20 at 09:03
  • See link again. Kuroro says it works in EF Core 2.2. Then Marc Gravell says "it is because of your mocking approach". So I thought the solution was somewhere in the posting. Microsoft often fixes bugs in upgrades which is not backwards compatible with older code. – jdweng Jan 07 '20 at 09:48

0 Answers0