-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add One Login config to Edit Application User UI + tests (#1119)
- Loading branch information
Showing
15 changed files
with
1,415 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,033 changes: 1,033 additions & 0 deletions
1,033
...tore/Postgres/Migrations/20240129115405_ApplicationUserOneLoginClientIdAndPem.Designer.cs
Large diffs are not rendered by default.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
...ore/DataStore/Postgres/Migrations/20240129115405_ApplicationUserOneLoginClientIdAndPem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace TeachingRecordSystem.Core.DataStore.Postgres.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class ApplicationUserOneLoginClientIdAndPem : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.AddColumn<string>( | ||
name: "one_login_client_id", | ||
table: "users", | ||
type: "character varying(50)", | ||
maxLength: 50, | ||
nullable: true); | ||
|
||
migrationBuilder.AddColumn<string>( | ||
name: "one_login_private_key_pem", | ||
table: "users", | ||
type: "character varying(2000)", | ||
maxLength: 2000, | ||
nullable: true); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropColumn( | ||
name: "one_login_client_id", | ||
table: "users"); | ||
|
||
migrationBuilder.DropColumn( | ||
name: "one_login_private_key_pem", | ||
table: "users"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ | |
{ | ||
<tr class="govuk-table__row"> | ||
<td class="govuk-table__cell"> | ||
<a href="@LinkGenerator.EditApiKey(key.ApiKeyId)" class="govuk-link">@key.ApiKeyId</a> | ||
<a href="@LinkGenerator.EditApiKey(key.ApiKeyId)" class="govuk-link" data-testid="[email protected]">@key.ApiKeyId</a> | ||
</td> | ||
<td class="govuk-table__cell" data-testid="Expiry"> | ||
@if (key.Expires is DateTime expires) | ||
|
@@ -72,9 +72,13 @@ | |
</table> | ||
|
||
<div class="govuk-!-margin-bottom-1"> | ||
<govuk-button-link href="@LinkGenerator.AddApiKey(Model.UserId)" class="govuk-button--secondary">Add API key</govuk-button-link> | ||
<govuk-button-link href="@LinkGenerator.AddApiKey(Model.UserId)" class="govuk-button--secondary" data-testid="AddApiKey">Add API key</govuk-button-link> | ||
</div> | ||
|
||
<h2 class="govuk-heading-m">One Login</h2> | ||
<govuk-input asp-for="OneLoginClientId" label-class="govuk-label--s" autocomplete="off" /> | ||
<govuk-textarea asp-for="OneLoginPrivateKeyPem" label-class="govuk-label--s" /> | ||
|
||
<govuk-button type="submit">Save changes</govuk-button> | ||
</form> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
{ | ||
<tr class="govuk-table__row" data-testid="[email protected]"> | ||
<td class="govuk-table__cell"> | ||
<a href="@LinkGenerator.EditApplicationUser(user.UserId)" class="govuk-link" data-testid="[email protected]">@user.Name</a> | ||
<a href="@LinkGenerator.EditApplicationUser(user.UserId)" class="govuk-link" data-testid="edit-application-[email protected]">@user.Name</a> | ||
</td> | ||
</tr> | ||
} | ||
|
132 changes: 132 additions & 0 deletions
132
...ngRecordSystem/tests/TeachingRecordSystem.SupportUi.EndToEndTests/ApplicationUserTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using System.Security.Cryptography; | ||
using Microsoft.EntityFrameworkCore; | ||
using TeachingRecordSystem.Core; | ||
|
||
namespace TeachingRecordSystem.SupportUi.EndToEndTests; | ||
|
||
public class ApplicationUserTests(HostFixture hostFixture) : TestBase(hostFixture) | ||
{ | ||
[Fact] | ||
public async Task AddApplicationUser() | ||
{ | ||
var applicationUserName = TestData.GenerateApplicationUserName(); | ||
|
||
await using var context = await HostFixture.CreateBrowserContext(); | ||
var page = await context.NewPageAsync(); | ||
|
||
await page.GoToApplicationUsersPage(); | ||
|
||
await page.AssertOnApplicationUsersPage(); | ||
|
||
await page.ClickLinkForElementWithTestId("add-application-user"); | ||
|
||
await page.AssertOnAddApplicationUserPage(); | ||
|
||
await page.FillAsync("text=Name", applicationUserName); | ||
|
||
await page.ClickButton("Save"); | ||
|
||
var applicationUserId = await WithDbContext(async dbContext => | ||
{ | ||
var applicationUser = await dbContext.ApplicationUsers.Where(u => u.Name == applicationUserName).SingleOrDefaultAsync(); | ||
return applicationUser!.UserId; | ||
}); | ||
|
||
await page.AssertOnEditApplicationUserPage(applicationUserId); | ||
|
||
await page.AssertFlashMessage("Application user added"); | ||
} | ||
|
||
[Fact] | ||
public async Task EditApplicationUser() | ||
{ | ||
var applicationUser = await TestData.CreateApplicationUser(); | ||
var applicationUserId = applicationUser.UserId; | ||
var newApplicationUserName = TestData.GenerateChangedApplicationUserName(applicationUser.Name); | ||
var newOneLoginClientId = Guid.NewGuid().ToString(); | ||
var newOneLoginPrivateKeyPem = TestCommon.TestData.GeneratePrivateKeyPem(); | ||
|
||
await using var context = await HostFixture.CreateBrowserContext(); | ||
var page = await context.NewPageAsync(); | ||
|
||
await page.GoToApplicationUsersPage(); | ||
|
||
await page.AssertOnApplicationUsersPage(); | ||
|
||
await page.ClickLinkForElementWithTestId($"edit-application-user-{applicationUserId}"); | ||
|
||
await page.AssertOnEditApplicationUserPage(applicationUserId); | ||
|
||
await page.FillAsync("text=Name", newApplicationUserName); | ||
await page.SetCheckedAsync($"label:text-is('{ApiRoles.GetPerson}')", true); | ||
await page.SetCheckedAsync($"label:text-is('{ApiRoles.UpdatePerson}')", true); | ||
await page.FillAsync("text=Client ID", newOneLoginClientId); | ||
await page.FillAsync("text=Private Key PEM", newOneLoginPrivateKeyPem); | ||
|
||
await page.ClickButton("Save changes"); | ||
|
||
await page.AssertOnApplicationUsersPage(); | ||
|
||
await page.AssertFlashMessage("Application user updated"); | ||
} | ||
|
||
[Fact] | ||
public async Task AddApiKey() | ||
{ | ||
var applicationUser = await TestData.CreateApplicationUser(); | ||
var applicationUserId = applicationUser.UserId; | ||
var apiKey = Convert.ToHexString(RandomNumberGenerator.GetBytes(32)); | ||
|
||
await using var context = await HostFixture.CreateBrowserContext(); | ||
var page = await context.NewPageAsync(); | ||
|
||
await page.GoToApplicationUsersPage(); | ||
|
||
await page.AssertOnApplicationUsersPage(); | ||
|
||
await page.ClickLinkForElementWithTestId($"edit-application-user-{applicationUserId}"); | ||
|
||
await page.AssertOnEditApplicationUserPage(applicationUserId); | ||
|
||
await page.ClickLinkForElementWithTestId("AddApiKey"); | ||
|
||
await page.AssertOnAddApiKeyPage(); | ||
|
||
await page.FillAsync("label:text-is('Key')", apiKey); | ||
|
||
await page.ClickButton("Save"); | ||
|
||
await page.AssertOnEditApplicationUserPage(applicationUserId); | ||
|
||
await page.AssertFlashMessage("API key added"); | ||
} | ||
|
||
[Fact] | ||
public async Task EditApiKey() | ||
{ | ||
var applicationUser = await TestData.CreateApplicationUser(); | ||
var applicationUserId = applicationUser.UserId; | ||
var apiKey = await TestData.CreateApiKey(applicationUser.UserId); | ||
|
||
await using var context = await HostFixture.CreateBrowserContext(); | ||
var page = await context.NewPageAsync(); | ||
|
||
await page.GoToApplicationUsersPage(); | ||
|
||
await page.AssertOnApplicationUsersPage(); | ||
|
||
await page.ClickLinkForElementWithTestId($"edit-application-user-{applicationUserId}"); | ||
|
||
await page.AssertOnEditApplicationUserPage(applicationUserId); | ||
|
||
await page.ClickLinkForElementWithTestId($"EditApiKey-{apiKey.ApiKeyId}"); | ||
|
||
await page.AssertOnEditApiKeyPage(apiKey.ApiKeyId); | ||
|
||
await page.ClickButton("Expire"); | ||
|
||
await page.AssertOnEditApplicationUserPage(applicationUserId); | ||
|
||
await page.AssertFlashMessage("API key expired"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.