protected override async Task ExecuteAsync(HttpContext httpContext) { var request = await OwnIdSerializer.DeserializeAsync <GenerateContextRequest>(httpContext.Request.Body); var result = await _createFlowCommand.ExecuteAsync(request); await JsonAsync(httpContext, result, StatusCodes.Status200OK, false); }
public async Task ExecuteAsync_GeneralFlow(ChallengeType challengeType, bool isQr, bool isPartial, string payload, bool fido2Enabled, FlowType expectedFlowType) { var fixture = new Fixture().SetOwnidSpecificSettings(); var cacheService = fixture.Freeze <Mock <ICacheItemRepository> >(); var urlProvider = fixture.Freeze <IUrlProvider>(); var identitiesProvider = fixture.Freeze <IIdentitiesProvider>(); var configuration = fixture.Freeze <IOwnIdCoreConfiguration>(); var linkAdapter = fixture.Freeze <Mock <IAccountLinkHandler> >(); var language = fixture.Freeze <string>(); configuration.TFAEnabled = fido2Enabled; configuration.MaximumNumberOfConnectedDevices = 99; var did = fixture.Create <string>(); linkAdapter.Setup(x => x.GetCurrentUserLinkStateAsync(It.IsAny <string>())) .ReturnsAsync(new LinkState(did, 1)); var command = new CreateFlowCommand(cacheService.Object, urlProvider, identitiesProvider, configuration, linkAdapter.Object); var actual = await command.ExecuteAsync(new GenerateContextRequest { Type = challengeType, IsQr = isQr, IsPartial = isPartial, Payload = payload, Language = language }); var context = identitiesProvider.GenerateContext(); var nonce = identitiesProvider.GenerateNonce(); var expiration = configuration.CacheExpirationTimeout; //TODO: refactor implementation if (challengeType == ChallengeType.Link) { var capturedPayload = payload; linkAdapter.Verify(x => x.GetCurrentUserLinkStateAsync(capturedPayload), Times.Once); payload = null; } else { did = null; } cacheService.Verify( x => x.CreateAsync( It.Is <CacheItem>(y => y.Context == context && y.Nonce == nonce && y.FlowType == expectedFlowType), null), Times.Once); var url = urlProvider.GetWebAppSignWithCallbackUrl(urlProvider.GetStartFlowUrl(context), language); var expected = new GetChallengeLinkResponse(context, url.ToString(), nonce, expiration, false); expected.Config.LogLevel = "0"; actual.Should().BeEquivalentTo(expected); }