Ejemplo n.º 1
0
        public async Task DeleteUserThrowsExceptionWhenFailingToDeleteUserTest()
        {
            var username = Guid.NewGuid().ToString();
            var config   = Model.Create <Auth0ManagementConfig>().Set(x => x.IsEnabled = true);

            var handler = Substitute.For <WrapperHandler>();
            var client  = new WrapperInvoker(handler);

            var tokenResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{\"access_token\":\"SomeToken\",\"scope\":\"delete: users\",\"expires_in\":86400,\"token_type\":\"Bearer\"}")
            };
            var failureResponse = new HttpResponseMessage(HttpStatusCode.Unauthorized);

            var sut = new UserStore(config, client);

            using (var tokenSource = new CancellationTokenSource())
            {
                handler.WrapperSendAsync(Arg.Any <HttpRequestMessage>(), tokenSource.Token).Returns(tokenResponse, failureResponse);

                Func <Task> action = async() => await sut.DeleteUser(username, tokenSource.Token).ConfigureAwait(false);

                action.Should().Throw <InvalidOperationException>();

                await handler.Received(2).WrapperSendAsync(Arg.Any <HttpRequestMessage>(), tokenSource.Token).ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
        public async Task DeleteUserSkipsProcessingWhenIsEnabledIsFalseTest()
        {
            var username = Guid.NewGuid().ToString();
            var config   = Model.Create <Auth0ManagementConfig>().Set(x => x.IsEnabled = false);

            var handler = Substitute.For <WrapperHandler>();
            var client  = new WrapperInvoker(handler);

            var tokenResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{\"access_token\":\"SomeToken\",\"scope\":\"delete: users\",\"expires_in\":86400,\"token_type\":\"Bearer\"}")
            };
            var successResponse = new HttpResponseMessage(HttpStatusCode.NoContent);

            var sut = new UserStore(config, client);

            using (var tokenSource = new CancellationTokenSource())
            {
                handler.WrapperSendAsync(Arg.Any <HttpRequestMessage>(), tokenSource.Token).Returns(tokenResponse, successResponse);

                await sut.DeleteUser(username, tokenSource.Token).ConfigureAwait(false);

                await handler.DidNotReceive().WrapperSendAsync(Arg.Any <HttpRequestMessage>(), Arg.Any <CancellationToken>()).ConfigureAwait(false);
            }
        }
Ejemplo n.º 3
0
        public async Task DeleteUserRemovesUserFromServiceTest()
        {
            var username = Guid.NewGuid().ToString();
            var config   = Model.Create <Auth0ManagementConfig>().Set(x => x.IsEnabled = true);

            var handler = Substitute.For <WrapperHandler>();
            var client  = new WrapperInvoker(handler);

            var tokenResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{\"access_token\":\"SomeToken\",\"scope\":\"delete: users\",\"expires_in\":86400,\"token_type\":\"Bearer\"}")
            };
            var successResponse = new HttpResponseMessage(HttpStatusCode.NoContent);

            var sut = new UserStore(config, client);

            using (var tokenSource = new CancellationTokenSource())
            {
                handler.WrapperSendAsync(Arg.Any <HttpRequestMessage>(), tokenSource.Token).Returns(tokenResponse, successResponse);

                await sut.DeleteUser(username, tokenSource.Token).ConfigureAwait(false);

                await handler.Received(2).WrapperSendAsync(Arg.Any <HttpRequestMessage>(), tokenSource.Token).ConfigureAwait(false);

                await handler.Received(2).WrapperSendAsync(Arg.Is <HttpRequestMessage>(x => x.RequestUri.ToString().Contains(config.Tenant)), tokenSource.Token).ConfigureAwait(false);

                await handler.Received(1).WrapperSendAsync(Arg.Is <HttpRequestMessage>(x => x.RequestUri.ToString().Contains(username)), tokenSource.Token).ConfigureAwait(false);

                await handler.Received(1).WrapperSendAsync(Arg.Is <HttpRequestMessage>(x => x.Headers.Authorization.ToString() == "Bearer SomeToken"), tokenSource.Token).ConfigureAwait(false);
            }
        }
Ejemplo n.º 4
0
        public void ThrowsExceptionWithNullConfigTest()
        {
            var handler = Substitute.For <WrapperHandler>();
            var client  = new WrapperInvoker(handler);

            Action action = () => new UserStore(null, client);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 5
0
        public void DeleteUserThrowsExceptionWithInvalidUsernameTest(string username)
        {
            var config  = Model.Create <Auth0ManagementConfig>().Set(x => x.IsEnabled = true);
            var handler = Substitute.For <WrapperHandler>();
            var client  = new WrapperInvoker(handler);

            var sut = new UserStore(config, client);

            Func <Task> action = async() => await sut.DeleteUser(username, CancellationToken.None).ConfigureAwait(false);

            action.Should().Throw <ArgumentException>();
        }
Ejemplo n.º 6
0
        public async Task DeleteUserThrowsExceptionWhenFailingToGetAccessTokenTest()
        {
            var username = Guid.NewGuid().ToString();
            var config   = Model.Create <Auth0ManagementConfig>().Set(x => x.IsEnabled = true);
            var handler  = Substitute.For <WrapperHandler>();
            var client   = new WrapperInvoker(handler);

            var failureResponse = new HttpResponseMessage(HttpStatusCode.Unauthorized);

            var sut = new UserStore(config, client);

            using (var tokenSource = new CancellationTokenSource())
            {
                handler.WrapperSendAsync(Arg.Any <HttpRequestMessage>(), tokenSource.Token).Returns(failureResponse);

                Func <Task> action = async() => await sut.DeleteUser(username, tokenSource.Token).ConfigureAwait(false);

                action.Should().Throw <InvalidOperationException>();

                await handler.Received(1).WrapperSendAsync(Arg.Any <HttpRequestMessage>(), tokenSource.Token).ConfigureAwait(false);
            }
        }