public void GetsOrCreatesAuthenticationAtCorrectUrl() { var data = new NewAuthorization(); var client = Substitute.For <IApiConnection>(); var authEndpoint = new AuthorizationsClient(client); authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data); client.Received().Put <ApplicationAuthorization>(Arg.Is <Uri>(u => u.ToString() == "authorizations/clients/clientId"), Args.Object); }
public async Task WrapsTwoFactorFailureWithTwoFactorException() { var data = new NewAuthorization(); var client = Substitute.For <IApiConnection>(); client.Put <ApplicationAuthorization>(Args.Uri, Args.Object, Args.String) .ThrowsAsync <ApplicationAuthorization>(new AuthorizationException(CreateResponse(HttpStatusCode.Unauthorized))); var authEndpoint = new AuthorizationsClient(client); await Assert.ThrowsAsync <TwoFactorChallengeFailedException>(() => authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data, "authenticationCode")); }
public void GetsOrCreatesAuthenticationAtCorrectUrlUsingTwoFactor() { var data = new NewAuthorization(); var client = Substitute.For <IApiConnection>(); var authEndpoint = new AuthorizationsClient(client); authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data, "two-factor"); client.Received().Put <ApplicationAuthorization>( Arg.Is <Uri>(u => u.ToString() == "authorizations/clients/clientId"), Arg.Is <Object>(o => o.GetType().GetProperty("client_secret").GetValue(o).ToString() == "secret"), "two-factor"); }
public async Task GetsOrCreatesAuthenticationWithFingerprintAtCorrectUrl() { var data = new NewAuthorization { Fingerprint = "ha-ha-fingerprint" }; var client = Substitute.For <IApiConnection>(); var authEndpoint = new AuthorizationsClient(client); authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data); client.Received().Put <ApplicationAuthorization>(Arg.Is <Uri>(u => u.ToString() == "authorizations/clients/clientId/ha-ha-fingerprint"), Args.Object, Args.String, Args.String); // NOTE: preview API }
public async Task WrapsTwoFactorFailureWithTwoFactorException() { var data = new NewAuthorization(); var client = Substitute.For <IApiConnection>(); client.Put <Authorization>(Args.Uri, Args.Object, Args.String) .Returns(_ => { throw new AuthorizationException( new ApiResponse <object> { StatusCode = HttpStatusCode.Unauthorized }); }); var authEndpoint = new AuthorizationsClient(client); AssertEx.Throws <TwoFactorChallengeFailedException>(async() => await authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data)); }
public async Task GetsOrCreatesAuthenticationWithFingerprintAtCorrectUrl() { var data = new NewAuthorization { Fingerprint = "ha-ha-fingerprint" }; var client = Substitute.For <IApiConnection>(); var authEndpoint = new AuthorizationsClient(client); Uri calledUri = null; dynamic calledBody = null; client.Put <ApplicationAuthorization>(Arg.Do <Uri>(u => calledUri = u), Arg.Do <object>(body => calledBody = body)); authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data); Assert.NotNull(calledUri); Assert.Equal(calledUri.ToString(), "authorizations/clients/clientId"); Assert.NotNull(calledBody); Assert.Equal(calledBody.fingerprint, "ha-ha-fingerprint"); }
public async Task GetsOrCreatesAuthenticationWithFingerprintAtCorrectUrl() { var data = new NewAuthorization { Fingerprint = "ha-ha-fingerprint" }; var client = Substitute.For <IApiConnection>(); var authEndpoint = new AuthorizationsClient(client); Uri calledUri = null; dynamic calledBody = null; client.Put <ApplicationAuthorization>(Arg.Do <Uri>(u => calledUri = u), Arg.Do <dynamic>(body => calledBody = body)); authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data); Assert.NotNull(calledUri); Assert.Equal(calledUri.ToString(), "authorizations/clients/clientId"); Assert.NotNull(calledBody); var fingerprintProperty = ((IEnumerable <PropertyInfo>)calledBody.GetType().DeclaredProperties).FirstOrDefault(x => x.Name == "fingerprint"); Assert.NotNull(fingerprintProperty); Assert.Equal(fingerprintProperty.GetValue(calledBody), "ha-ha-fingerprint"); }
public void GetsOrCreatesAuthenticationAtCorrectUrl() { var data = new NewAuthorization(); var client = Substitute.For<IApiConnection>(); var authEndpoint = new AuthorizationsClient(client); authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data); client.Received().Put<ApplicationAuthorization>(Arg.Is<Uri>(u => u.ToString() == "authorizations/clients/clientId"), Args.Object); }
public async Task GetsOrCreatesAuthenticationWithFingerprintAtCorrectUrl() { var data = new NewAuthorization { Fingerprint = "ha-ha-fingerprint" }; var client = Substitute.For<IApiConnection>(); var authEndpoint = new AuthorizationsClient(client); Uri calledUri = null; dynamic calledBody = null; client.Put<ApplicationAuthorization>(Arg.Do<Uri>(u => calledUri = u), Arg.Do<object>(body => calledBody = body)); authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data); Assert.NotNull(calledUri); Assert.Equal(calledUri.ToString(), "authorizations/clients/clientId"); Assert.NotNull(calledBody); Assert.Equal(calledBody.fingerprint, "ha-ha-fingerprint"); }
public async Task WrapsTwoFactorFailureWithTwoFactorException() { var data = new NewAuthorization(); var client = Substitute.For<IApiConnection>(); client.Put<ApplicationAuthorization>(Args.Uri, Args.Object, Args.String) .ThrowsAsync<ApplicationAuthorization>( new AuthorizationException( new Response(HttpStatusCode.Unauthorized, null, new Dictionary<string, string>(), "application/json"))); var authEndpoint = new AuthorizationsClient(client); await Assert.ThrowsAsync<TwoFactorChallengeFailedException>(() => authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data, "authenticationCode")); }
public async Task WrapsTwoFactorFailureWithTwoFactorException() { var data = new NewAuthorization(); var client = Substitute.For<IApiConnection>(); client.Put<Authorization>(Args.Uri, Args.Object, Args.String) .ThrowsAsync<Authorization>( new AuthorizationException( new ApiResponse<object> { StatusCode = HttpStatusCode.Unauthorized })); var authEndpoint = new AuthorizationsClient(client); await AssertEx.Throws<TwoFactorChallengeFailedException>(async () => await authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data, "authenticationCode")); }
public async Task GetsOrCreatesAuthenticationWithFingerprintAtCorrectUrl() { var data = new NewAuthorization { Fingerprint = "ha-ha-fingerprint"}; var client = Substitute.For<IApiConnection>(); var authEndpoint = new AuthorizationsClient(client); authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data); client.Received().Put<ApplicationAuthorization>(Arg.Is<Uri>(u => u.ToString() == "authorizations/clients/clientId/ha-ha-fingerprint"), Args.Object, Args.String, Args.String); // NOTE: preview API }