Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterOrneholm committed Sep 1, 2022
1 parent 4e562ff commit c2c6be1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,42 @@ public async Task Init_Returns_Ui_With_Script()

Assert.Equal("/", GetInlineJsonValue(transactionContent, "returnUrl"));
Assert.Equal("/", GetInlineJsonValue(transactionContent, "cancelReturnUrl"));
Assert.Equal("Ignored", GetInlineJsonValue(transactionContent, "protectedUiOptions"));
Assert.Equal("X", GetInlineJsonValue(transactionContent, "protectedUiOptions"));
}

[Fact]
public async Task Init_Preserves_UI_Options()
{
// Arrange
using var server = CreateServer(o =>
{
o.UseSimulatedEnvironment();
},
o =>
{
o.AddSameDevice();
},
DefaultAppConfiguration(async context =>
{
await context.ChallengeAsync(BankIdAuthDefaults.SameDeviceAuthenticationScheme);
}),
services =>
{
services.AddTransient(s => _bankIdUiOptionsProtector.Object);
services.AddTransient(s => _bankIdUiStateProtector.Object);
});

// Act
var request =
CreateRequestWithFakeStateCookie(server, "/ActiveLogin/BankId/Auth?returnUrl=%2F&uiOptions=UIOPTIONS&orderRef=Y");
var transaction = await request.GetAsync();

// Assert
Assert.Equal(HttpStatusCode.OK, transaction.StatusCode);

var transactionContent = await transaction.Content.ReadAsStringAsync();

Assert.Equal("UIOPTIONS", GetInlineJsonValue(transactionContent, "protectedUiOptions"));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,42 @@ public async Task SignInit_Returns_Ui_With_Script()

Assert.Equal("/", GetInlineJsonValue(transactionContent, "returnUrl"));
Assert.Equal("/", GetInlineJsonValue(transactionContent, "cancelReturnUrl"));
Assert.Equal("Ignored", GetInlineJsonValue(transactionContent, "protectedUiOptions"));
Assert.Equal("X", GetInlineJsonValue(transactionContent, "protectedUiOptions"));
}

[Fact]
public async Task SignInit_Preserves_UI_Options()
{
// Arrange
using var server = CreateServer(o =>
{
o.UseSimulatedEnvironment();
},
o =>
{
o.AddSameDevice();
},
DefaultAppConfiguration(async context =>
{
await context.ChallengeAsync(BankIdSignDefaults.SameDeviceConfigKey);
}),
services =>
{
services.AddTransient(s => _bankIdUiOptionsProtector.Object);
services.AddTransient(s => _bankIdUiStateProtector.Object);
});

// Act
var request =
CreateRequestWithFakeStateCookie(server, "/ActiveLogin/BankId/Sign?returnUrl=%2F&uiOptions=UIOPTIONS&orderRef=Y");
var transaction = await request.GetAsync();

// Assert
Assert.Equal(HttpStatusCode.OK, transaction.StatusCode);

var transactionContent = await transaction.Content.ReadAsStringAsync();

Assert.Equal("UIOPTIONS", GetInlineJsonValue(transactionContent, "protectedUiOptions"));
}

[Fact]
Expand Down

0 comments on commit c2c6be1

Please sign in to comment.