public async Task RetriesWhenResendRequested() { var firstResponse = new TwoFactorRequiredException(TwoFactorType.AuthenticatorApp); var challengeResults = new Queue<TwoFactorChallengeResult>(new[] { TwoFactorChallengeResult.RequestResendCode, new TwoFactorChallengeResult("two-factor-code") }); var secondResponse = new Authorization { Token = "OAUTHSECRET" }; var client = Substitute.For<IObservableAuthorizationsClient>(); client.GetOrCreateApplicationAuthentication(Args.String, Args.String, Args.NewAuthorization) .Returns(Observable.Throw<Authorization>(firstResponse)); client.GetOrCreateApplicationAuthentication( Args.String, Args.String, Args.NewAuthorization, "two-factor-code") .Returns(Observable.Return(secondResponse)); var result = await client.GetOrCreateApplicationAuthentication( "clientId", "secret", new NewAuthorization { Note = "Was it this one?" }, _ => Observable.Return(challengeResults.Dequeue())); client.Received(2).GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any<NewAuthorization>()); client.Received().GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any<NewAuthorization>(), "two-factor-code"); Assert.Equal("OAUTHSECRET", result.Token); }
public async Task RetriesWhenResendRequested() { var firstResponse = new TwoFactorRequiredException(TwoFactorType.AuthenticatorApp); var challengeResults = new Queue <TwoFactorChallengeResult>(new[] { TwoFactorChallengeResult.RequestResendCode, new TwoFactorChallengeResult("two-factor-code") }); var secondResponse = new ApplicationAuthorization("OAUTHSECRET"); var client = Substitute.For <IObservableAuthorizationsClient>(); client.GetOrCreateApplicationAuthentication(Args.String, Args.String, Args.NewAuthorization) .Returns(Observable.Throw <ApplicationAuthorization>(firstResponse)); client.GetOrCreateApplicationAuthentication( Args.String, Args.String, Args.NewAuthorization, "two-factor-code") .Returns(Observable.Return(secondResponse)); var result = await client.GetOrCreateApplicationAuthentication( "clientId", "secret", new NewAuthorization { Note = "Was it this one?" }, _ => Observable.Return(challengeResults.Dequeue())); client.Received(2).GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any <NewAuthorization>()); client.Received().GetOrCreateApplicationAuthentication("clientId", "secret", Arg.Any <NewAuthorization>(), "two-factor-code"); Assert.Equal("OAUTHSECRET", result.Token); }
public async Task UsesCallbackToRetrievTwoFactorCode() { var firstResponse = new TwoFactorRequiredException(TwoFactorType.AuthenticatorApp); var twoFactorChallengeResult = new TwoFactorChallengeResult("two-factor-code"); var secondResponse = new Authorization {Token = "OAUTHSECRET"}; var client = Substitute.For<IObservableAuthorizationsClient>(); client.GetOrCreateApplicationAuthentication(Args.String, Args.String, Args.NewAuthorization) .Returns(Observable.Throw<Authorization>(firstResponse)); client.GetOrCreateApplicationAuthentication( Args.String, Args.String, Args.NewAuthorization, "two-factor-code") .Returns(Observable.Return(secondResponse)); var result = await client.GetOrCreateApplicationAuthentication( "clientId", "secret", new NewAuthorization { Note = "Was it this one?"}, _ => Observable.Return(twoFactorChallengeResult)); Assert.Equal("OAUTHSECRET", result.Token); client.Received().GetOrCreateApplicationAuthentication( "clientId", "secret", Arg.Is<NewAuthorization>(a => a.Note == "Was it this one?")); client.Received().GetOrCreateApplicationAuthentication( "clientId", "secret", Arg.Is<NewAuthorization>(a => a.Note == "Was it this one?"), "two-factor-code"); }
public async Task UsesCallbackToRetrievTwoFactorCode() { var firstResponse = new TwoFactorRequiredException(TwoFactorType.AuthenticatorApp); var twoFactorChallengeResult = new TwoFactorChallengeResult("two-factor-code"); var secondResponse = new ApplicationAuthorization("OAUTHSECRET"); var client = Substitute.For <IObservableAuthorizationsClient>(); client.GetOrCreateApplicationAuthentication(Args.String, Args.String, Args.NewAuthorization) .Returns(Observable.Throw <ApplicationAuthorization>(firstResponse)); client.GetOrCreateApplicationAuthentication( Args.String, Args.String, Args.NewAuthorization, "two-factor-code") .Returns(Observable.Return(secondResponse)); var result = await client.GetOrCreateApplicationAuthentication( "clientId", "secret", new NewAuthorization { Note = "Was it this one?" }, _ => Observable.Return(twoFactorChallengeResult)); Assert.Equal("OAUTHSECRET", result.Token); client.Received().GetOrCreateApplicationAuthentication( "clientId", "secret", Arg.Is <NewAuthorization>(a => a.Note == "Was it this one?")); client.Received().GetOrCreateApplicationAuthentication( "clientId", "secret", Arg.Is <NewAuthorization>(a => a.Note == "Was it this one?"), "two-factor-code"); }
public void SetsDefaultMessage() { var response = new Response(HttpStatusCode.Unauthorized, null, new Dictionary <string, string>(), "application/json"); var exception = new TwoFactorRequiredException(response, TwoFactorType.Sms); Assert.Equal("Two-factor authentication code is required", exception.Message); }
public void SetsDefaultMessage() { var response = CreateResponse(HttpStatusCode.Unauthorized); var exception = new TwoFactorRequiredException(response, TwoFactorType.Sms); Assert.Equal("Two-factor authentication code is required", exception.Message); }
public void SetsDefaultMessage() { var response = new Response(HttpStatusCode.Unauthorized, null, new Dictionary<string, string>(), "application/json"); var exception = new TwoFactorRequiredException(response, TwoFactorType.Sms); Assert.Equal("Two-factor authentication code is required", exception.Message); }
public void SetsDefaultMessage() { var response = new ApiResponse<object> { StatusCode = HttpStatusCode.Unauthorized }; var exception = new TwoFactorRequiredException(response, TwoFactorType.Sms); Assert.Equal("Two-factor authentication code is required", exception.Message); }
public async Task Cancel_Resets_TwoFactorType_Async() { var target = CreateTarget(); var exception = new TwoFactorRequiredException(TwoFactorType.Sms); var userError = new TwoFactorRequiredUserError(exception); var task = target.Show(userError).ToTask(); Assert.That(TwoFactorType.Sms, Is.EqualTo(target.TwoFactorType)); target.Cancel(); await task; // TwoFactorType must be cleared here as the UIController uses it as a trigger // to show the 2FA dialog view. Assert.That(TwoFactorType.None, Is.EqualTo(target.TwoFactorType)); }