-
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.
Added NPQAccessToken to gettrn journey
- Loading branch information
Showing
2 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
17 changes: 16 additions & 1 deletion
17
...ingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/RequestTrn/Index.cshtml.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 |
---|---|---|
@@ -1,10 +1,25 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using TeachingRecordSystem.UiCommon.FormFlow; | ||
|
||
namespace TeachingRecordSystem.AuthorizeAccess.Pages.RequestTrn; | ||
|
||
[Journey(RequestTrnJourneyState.JourneyName), ActivatesJourney, RequireJourneyInstance] | ||
public class IndexModel : PageModel | ||
public class IndexModel(IConfiguration configuration) : PageModel | ||
{ | ||
public JourneyInstance<RequestTrnJourneyState>? JourneyInstance { get; set; } | ||
private IConfiguration _configuration { get; init; } = configuration; | ||
|
||
[FromQuery] | ||
public string? AccessToken { get; set; } | ||
|
||
public ActionResult OnGet() | ||
{ | ||
var whitelistedAccessToken = _configuration.GetValue<string>("NPQWhitelistAccessToken"); | ||
if (!whitelistedAccessToken!.Equals(AccessToken, StringComparison.OrdinalIgnoreCase)) | ||
Check failure on line 19 in TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/RequestTrn/Index.cshtml.cs GitHub Actions / TeachingRecordSystem.AuthorizeAccess.Tests test resultsTeachingRecordSystem.AuthorizeAccess.Tests.PageTests.RequestTrn.IndexTests ► Get_MissingAccessToken_ReturnsBadRequest
Raw output
Check failure on line 19 in TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/RequestTrn/Index.cshtml.cs GitHub Actions / TeachingRecordSystem.AuthorizeAccess.Tests test resultsTeachingRecordSystem.AuthorizeAccess.Tests.PageTests.RequestTrn.IndexTests ► Get_ValidRequest_RendersExpectedContent
Raw output
|
||
{ | ||
return BadRequest(); | ||
} | ||
return Page(); | ||
} | ||
} |
23 changes: 21 additions & 2 deletions
23
...ystem/tests/TeachingRecordSystem.AuthorizeAccess.Tests/PageTests/RequestTrn/IndexTests.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 |
---|---|---|
@@ -1,20 +1,39 @@ | ||
using System.Net; | ||
|
||
namespace TeachingRecordSystem.AuthorizeAccess.Tests.PageTests.RequestTrn; | ||
|
||
public class IndexTests(HostFixture hostFixture) : TestBase(hostFixture) | ||
public class IndexTests(HostFixture hostFixture, IConfiguration configuration) : TestBase(hostFixture) | ||
{ | ||
[Fact] | ||
public async Task Get_ValidRequest_RendersExpectedContent() | ||
{ | ||
// Arrange | ||
var npqAccessToken = configuration.GetValue<string>("NPQWhitelistAccessToken"); | ||
var state = CreateNewState(); | ||
var journeyInstance = await CreateJourneyInstance(state); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Get, $"/request-trn?{journeyInstance.GetUniqueIdQueryParameter()}"); | ||
var request = new HttpRequestMessage(HttpMethod.Get, $"/request-trn?{journeyInstance.GetUniqueIdQueryParameter()}&AccessToken={npqAccessToken}"); | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(request); | ||
|
||
// Assert | ||
await AssertEx.HtmlResponseAsync(response); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_MissingAccessToken_ReturnsBadRequest() | ||
{ | ||
// Arrange | ||
var state = CreateNewState(); | ||
var journeyInstance = await CreateJourneyInstance(state); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Get, $"/request-trn?{journeyInstance.GetUniqueIdQueryParameter()}&AccessToken="); | ||
|
||
// Act | ||
var response = await HttpClient.SendAsync(request); | ||
|
||
// Assert | ||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); | ||
} | ||
} |