Skip to content

Commit

Permalink
Added NPQAccessToken to gettrn journey
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKevJoy committed Dec 6, 2024
1 parent 9e90d11 commit 6d7ef6e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
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; }

[FromQuery]
public string? AccessToken { get; set; }

public ActionResult OnGet()
{
var whitelistedAccessToken = configuration.GetRequiredValue("RequestTrnAccessToken");
if (!whitelistedAccessToken.Equals(AccessToken, StringComparison.Ordinal))
{
return BadRequest();
}
return Page();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"Microsoft.AspNetCore": "Fatal"
}
}
}
},
"RequestTrnAccessToken": "n8hhN5MSrNXxCzRo"
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
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 accessToken = configuration.GetValue<string>("RequestTrnAccessToken");
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={accessToken}");

// 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(StatusCodes.Status400BadRequest, (int)response.StatusCode);
}
}

0 comments on commit 6d7ef6e

Please sign in to comment.