public async Task HandlerNotifiedOfExceptionIn2FAChallengeResponse() { var client = CreateClient(); var twoFaException = new TwoFactorChallengeFailedException(); var forbiddenResponse = Substitute.For <IResponse>(); forbiddenResponse.StatusCode.Returns(HttpStatusCode.Forbidden); var loginAttemptsException = new LoginAttemptsExceededException(forbiddenResponse); client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any <NewAuthorization>()) .Returns <ApplicationAuthorization>(_ => { throw twoFaException; }); client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any <NewAuthorization>(), "111111") .Returns <ApplicationAuthorization>(_ => { throw loginAttemptsException; }); var keychain = Substitute.For <IKeychain>(); var tfa = new Lazy <ITwoFactorChallengeHandler>(() => Substitute.For <ITwoFactorChallengeHandler>()); var oauthListener = Substitute.For <IOAuthCallbackListener>(); tfa.Value.HandleTwoFactorException(twoFaException).Returns( new TwoFactorChallengeResult("111111"), new TwoFactorChallengeResult("123456")); var target = new LoginManager(keychain, tfa, oauthListener, "id", "secret", scopes); Assert.ThrowsAsync <LoginAttemptsExceededException>(async() => await target.Login(host, client, "foo", "bar")); await client.Authorization.Received(1).GetOrCreateApplicationAuthentication( "id", "secret", Arg.Any <NewAuthorization>(), "111111"); await tfa.Value.Received(1).ChallengeFailed(loginAttemptsException); }
public async Task HandlerNotifiedOfExceptionIn2FAChallengeResponse() { var client = Substitute.For <IGitHubClient>(); var twoFaException = new TwoFactorChallengeFailedException(); var forbiddenResponse = Substitute.For <IResponse>(); forbiddenResponse.StatusCode.Returns(HttpStatusCode.Forbidden); var loginAttemptsException = new LoginAttemptsExceededException(forbiddenResponse); client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any <NewAuthorization>()) .Returns <ApplicationAuthorization>(_ => { throw twoFaException; }); client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any <NewAuthorization>(), "111111") .Returns <ApplicationAuthorization>(_ => { throw loginAttemptsException; }); var loginCache = Substitute.For <ILoginCache>(); var tfa = Substitute.For <ITwoFactorChallengeHandler>(); tfa.HandleTwoFactorException(twoFaException).Returns( new TwoFactorChallengeResult("111111"), new TwoFactorChallengeResult("123456")); var target = new LoginManager(loginCache, tfa, "id", "secret"); Assert.ThrowsAsync <LoginAttemptsExceededException>(async() => await target.Login(host, client, "foo", "bar")); await client.Authorization.Received(1).GetOrCreateApplicationAuthentication( "id", "secret", Arg.Any <NewAuthorization>(), "111111"); tfa.Received(1).ChallengeFailed(loginAttemptsException); }
public void SetsDefaultMessage() { var response = new Response(HttpStatusCode.Forbidden, null, new Dictionary <string, string>(), "application/json"); var exception = new LoginAttemptsExceededException(response); Assert.Equal("Maximum number of login attempts exceeded", exception.Message); }
public void SetsDefaultMessage() { var response = new Response(HttpStatusCode.Forbidden, null, new Dictionary<string, string>(), "application/json"); var exception = new LoginAttemptsExceededException(response); Assert.Equal("Maximum number of login attempts exceeded", exception.Message); }
public void SetsDefaultMessage() { var response = CreateResponse(HttpStatusCode.Forbidden); var exception = new LoginAttemptsExceededException(response); Assert.Equal("Maximum number of login attempts exceeded", exception.Message); }
public void SetsDefaultMessage() { var response = new ApiResponse<object> { StatusCode = HttpStatusCode.Forbidden }; var exception = new LoginAttemptsExceededException(response); Assert.Equal("Maximum number of login attempts exceeded", exception.Message); }