Skip to content

[Bug]: Keycloak tests occasionally fail (FlurlHttpException : Call failed with status code 401 (Unauthorized)) #1533

Description

@HofmeisterAn

Testcontainers version

develop

Using the latest Testcontainers version?

Yes

Host OS

Ubuntu 22.04

Host arch

x86

.NET version

9.0.300

Docker version

-

Docker info

-

What happened?

Occasionally, the Keycloak tests fail with the following error in our CI. I haven't tested it, but I assume the issue can be reproduced in GitHub Codespaces:

cd tests/Testcontainers.Keycloak.Tests/
dotnet build
until ! dotnet test --no-build; do :; done

Relevant log output

[xUnit.net 00:02:18.02]     Testcontainers.Keycloak.KeycloakContainerTest+KeycloakDefaultConfiguration.MasterRealmIsEnabled [FAIL]
  Failed Testcontainers.Keycloak.KeycloakContainerTest+KeycloakDefaultConfiguration.MasterRealmIsEnabled [1 m 1 s]
  Error Message:
   Flurl.Http.FlurlHttpException : Call failed with status code 401 (Unauthorized): POST http://127.0.0.1:32777/realms/master/protocol/openid-connect/token
  Stack Trace:
     at Flurl.Http.FlurlRequest.HandleExceptionAsync(HttpCall call, Exception ex, CancellationToken token)
   at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Flurl.Http.FlurlRequest.SendAsync(HttpMethod verb, HttpContent content, CancellationToken cancellationToken, HttpCompletionOption completionOption)
   at Flurl.Http.HttpResponseMessageExtensions.ReceiveJson[T](Task`1 response)
   at Flurl.Http.HttpResponseMessageExtensions.ReceiveJson(Task`1 response)
   at Keycloak.Net.Common.Extensions.FlurlRequestExtensions.GetAccessTokenAsync(String url, String realm, String userName, String password, KeycloakOptions options)
   at Keycloak.Net.Common.Extensions.FlurlRequestExtensions.GetAccessToken(String url, String realm, String userName, String password, KeycloakOptions options)
   at Keycloak.Net.Common.Extensions.FlurlRequestExtensions.WithAuthentication(IFlurlRequest request, Func`1 getToken, String url, String realm, String userName, String password, String clientSecret, KeycloakOptions options)
   at Keycloak.Net.KeycloakClient.GetBaseUrl(String authenticationRealm)
   at Keycloak.Net.KeycloakClient.GetRealmAsync(String realm, CancellationToken cancellationToken)
   at Testcontainers.Keycloak.KeycloakContainerTest.MasterRealmIsEnabled() in /home/runner/work/testcontainers-dotnet/testcontainers-dotnet/tests/Testcontainers.Keycloak.Tests/KeycloakContainerTest.cs:line 50

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededmoduleAn official Testcontainers module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions