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 5, 2024
1 parent 6f33128 commit 946f28b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
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

View workflow job for this annotation

GitHub Actions / TeachingRecordSystem.AuthorizeAccess.Tests test results

TeachingRecordSystem.AuthorizeAccess.Tests.PageTests.RequestTrn.IndexTests ► Get_MissingAccessToken_ReturnsBadRequest

Failed test found in: TeachingRecordSystem/tests/TeachingRecordSystem.AuthorizeAccess.Tests/TestResults/_fv-az915-689_2024-12-05_13_55_45.trx Error: System.NullReferenceException : Object reference not set to an instance of an object.
Raw output
System.NullReferenceException : Object reference not set to an instance of an object.
   at TeachingRecordSystem.AuthorizeAccess.Pages.RequestTrn.IndexModel.OnGet() in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/RequestTrn/Index.cshtml.cs:line 19
   at lambda_method1710(Closure, Object, Object[])
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.ActionResultHandlerMethod.Execute(Object receiver, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at TeachingRecordSystem.AuthorizeAccess.Infrastructure.Middleware.AddAnalyticsDataMiddleware.InvokeAsync(HttpContext context) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Infrastructure/Middleware/AddAnalyticsDataMiddleware.cs:line 18
   at Joonasw.AspNetCore.SecurityHeaders.Csp.CspMiddleware.Invoke(HttpContext context)
   at Prometheus.HttpMetrics.HttpRequestDurationMiddleware.Invoke(HttpContext context)
   at Prometheus.HttpMetrics.HttpRequestCountMiddleware.Invoke(HttpContext context)
   at Prometheus.HttpMetrics.HttpInProgressMiddleware.Invoke(HttpContext context)
   at TeachingRecordSystem.UiCommon.FormFlow.State.CommitStateChangesMiddleware.InvokeAsync(HttpContext context) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.UiCommon/FormFlow/State/CommitStateChangesMiddleware.cs:line 11
   at TeachingRecordSystem.UiCommon.FormFlow.State.CommitStateChangesMiddleware.InvokeAsync(HttpContext context) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.UiCommon/FormFlow/State/CommitStateChangesMiddleware.cs:line 17
   at TeachingRecordSystem.AuthorizeAccess.Infrastructure.FormFlow.FormFlowSessionMiddleware.InvokeAsync(HttpContext context) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Infrastructure/FormFlow/FormFlowSessionMiddleware.cs:line 31
   at Microsoft.AspNetCore.TestHost.HttpContextBuilder.<>c__DisplayClass23_0.<<SendAsync>g__RunRequestAsync|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.TestHost.ClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Mvc.Testing.Handlers.CookieContainerHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at TeachingRecordSystem.AuthorizeAccess.Tests.PageTests.RequestTrn.IndexTests.Get_MissingAccessToken_ReturnsBadRequest() in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.AuthorizeAccess.Tests/PageTests/RequestTrn/IndexTests.cs:line 34

Check failure on line 19 in TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/RequestTrn/Index.cshtml.cs

View workflow job for this annotation

GitHub Actions / TeachingRecordSystem.AuthorizeAccess.Tests test results

TeachingRecordSystem.AuthorizeAccess.Tests.PageTests.RequestTrn.IndexTests ► Get_ValidRequest_RendersExpectedContent

Failed test found in: TeachingRecordSystem/tests/TeachingRecordSystem.AuthorizeAccess.Tests/TestResults/_fv-az915-689_2024-12-05_13_55_45.trx Error: System.NullReferenceException : Object reference not set to an instance of an object.
Raw output
System.NullReferenceException : Object reference not set to an instance of an object.
   at TeachingRecordSystem.AuthorizeAccess.Pages.RequestTrn.IndexModel.OnGet() in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/RequestTrn/Index.cshtml.cs:line 19
   at lambda_method1710(Closure, Object, Object[])
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.ActionResultHandlerMethod.Execute(Object receiver, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at TeachingRecordSystem.AuthorizeAccess.Infrastructure.Middleware.AddAnalyticsDataMiddleware.InvokeAsync(HttpContext context) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Infrastructure/Middleware/AddAnalyticsDataMiddleware.cs:line 18
   at Joonasw.AspNetCore.SecurityHeaders.Csp.CspMiddleware.Invoke(HttpContext context)
   at Prometheus.HttpMetrics.HttpRequestDurationMiddleware.Invoke(HttpContext context)
   at Prometheus.HttpMetrics.HttpRequestCountMiddleware.Invoke(HttpContext context)
   at Prometheus.HttpMetrics.HttpInProgressMiddleware.Invoke(HttpContext context)
   at TeachingRecordSystem.UiCommon.FormFlow.State.CommitStateChangesMiddleware.InvokeAsync(HttpContext context) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.UiCommon/FormFlow/State/CommitStateChangesMiddleware.cs:line 11
   at TeachingRecordSystem.UiCommon.FormFlow.State.CommitStateChangesMiddleware.InvokeAsync(HttpContext context) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.UiCommon/FormFlow/State/CommitStateChangesMiddleware.cs:line 17
   at TeachingRecordSystem.AuthorizeAccess.Infrastructure.FormFlow.FormFlowSessionMiddleware.InvokeAsync(HttpContext context) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Infrastructure/FormFlow/FormFlowSessionMiddleware.cs:line 31
   at Microsoft.AspNetCore.TestHost.HttpContextBuilder.<>c__DisplayClass23_0.<<SendAsync>g__RunRequestAsync|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.TestHost.ClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Mvc.Testing.Handlers.CookieContainerHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at TeachingRecordSystem.AuthorizeAccess.Tests.PageTests.RequestTrn.IndexTests.Get_ValidRequest_RendersExpectedContent() in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.AuthorizeAccess.Tests/PageTests/RequestTrn/IndexTests.cs:line 18
{
return BadRequest();
}
return Page();
}
}
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);
}
}

0 comments on commit 946f28b

Please sign in to comment.