Skip to content

Commit

Permalink
Merge pull request #156 from bcgov/bugs/ECER-1401
Browse files Browse the repository at this point in the history
ECER-1401: integration test fix
  • Loading branch information
farzadnadiri authored Mar 22, 2024
2 parents be390c6 + b6538d9 commit 42f213e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 40 deletions.
42 changes: 5 additions & 37 deletions src/ECER.Tests/Integration/AuthenticationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,18 @@ namespace ECER.Tests.Integration;

public static class AuthenticationHelper
{
public static Scenario WithNewUser(this Scenario scenario, UserIdentity identity)
{
ArgumentNullException.ThrowIfNull(identity);

scenario.WithClaim("identity_provider", identity.IdentityProvider);
scenario.WithClaim("identity_id", identity.UserId);
public static Scenario WithNewUser(this Scenario scenario, UserIdentity identity) => scenario.WithUser(identity);

if (identity.IdentityProvider == "bcsc")
{
scenario.WithClaim(ClaimTypes.NameIdentifier, identity.UserId);
}
else if (identity.IdentityProvider == "bceidbasic")
{
scenario.WithClaim("bceid_user_guid", identity.UserId);
}
else
{
throw new NotImplementedException();
}
public static Scenario WithExistingUser(this Scenario scenario, UserIdentity identity, string userId) => scenario.WithUser(identity, userId);

return scenario;
}

public static Scenario WithExistingUser(this Scenario scenario, UserIdentity identity, string userId)
private static Scenario WithUser(this Scenario scenario, UserIdentity identity, string? userId = null)
{
ArgumentNullException.ThrowIfNull(identity);

scenario.WithClaim("identity_provider", identity.IdentityProvider);
scenario.WithClaim("identity_id", identity.UserId);

if (identity.IdentityProvider == "bcsc")
{
scenario.WithClaim(ClaimTypes.NameIdentifier, identity.UserId);
}
else if (identity.IdentityProvider == "bceidbasic")
{
scenario.WithClaim("bceid_user_guid", identity.UserId);
}
else
{
throw new NotImplementedException();
}

scenario.WithClaim("user_id", userId);
scenario.WithClaim(ClaimTypes.NameIdentifier, identity.UserId);
if (!string.IsNullOrEmpty(userId)) scenario.WithClaim("user_id", userId);

return scenario;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ECER.Tests/Integration/RegistryApi/UserInfoTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Alba;
using System.Net;
using Alba;
using Bogus;
using ECER.Clients.RegistryPortal.Server.Users;
using ECER.Utilities.Security;
using Shouldly;
using System.Net;
using Xunit.Abstractions;

namespace ECER.Tests.Integration.Api;
Expand All @@ -14,7 +14,7 @@ public UserInfoTests(ITestOutputHelper output, RegistryPortalWebAppFixture fixtu
{
}

[Fact(Skip = "fails due to custom realm changes")]
[Fact]
public async Task PostUserInfo_NewBceidUser_Ok()
{
await Host.Scenario(_ =>
Expand Down

0 comments on commit 42f213e

Please sign in to comment.