예제 #1
0
        public async Task ExecuteAsync_WhenClientIdIsUnknown_ReturnsNull()
        {
            CommandHandler sut = CreateSut(false);

            IAuthenticateClientSecretCommand command = CreateCommand();
            IClientSecretIdentity            result  = await sut.ExecuteAsync(command);

            Assert.That(result, Is.Null);
        }
예제 #2
0
        public async Task ExecuteAsync_WhenClientIdIsUnknown_AssertGenerateWasNotCalledOnTokenHelper()
        {
            CommandHandler sut = CreateSut(false);

            IAuthenticateClientSecretCommand command = CreateCommand();
            await sut.ExecuteAsync(command);

            _tokenHelperMock.Verify(m => m.Generate(It.IsAny <IClientSecretIdentity>()), Times.Never);
        }
예제 #3
0
        public async Task ExecuteAsync_WhenClientIdIsUnknown_AssertClearSensitiveDataWasNotCalledOnClientSecretIdentity()
        {
            Mock <IClientSecretIdentity> clientSecretIdentityMock = _fixture.BuildClientSecretIdentityMock();
            CommandHandler sut = CreateSut(false, clientSecretIdentityMock.Object);

            IAuthenticateClientSecretCommand command = CreateCommand();
            await sut.ExecuteAsync(command);

            clientSecretIdentityMock.Verify(m => m.ClearSensitiveData(), Times.Never);
        }
예제 #4
0
        public async Task ExecuteAsync_WhenClientIdIsUnknown_AssertAddClaimsWasNotCalledOnClientSecretIdentity()
        {
            Mock <IClientSecretIdentity> clientSecretIdentityMock = _fixture.BuildClientSecretIdentityMock();
            CommandHandler sut = CreateSut(false, clientSecretIdentityMock.Object);

            IAuthenticateClientSecretCommand command = CreateCommand();
            await sut.ExecuteAsync(command);

            clientSecretIdentityMock.Verify(m => m.AddClaims(It.IsAny <IEnumerable <Claim> >()), Times.Never);
        }
예제 #5
0
        public async Task ExecuteAsync_WhenCalled_AssertGetClientSecretIdentityAsyncWasCalledOnSecurityRepository()
        {
            CommandHandler sut = CreateSut();

            string clientId = _fixture.Create <string>();
            IAuthenticateClientSecretCommand command = CreateCommand(clientId);
            await sut.ExecuteAsync(command);

            _securityRepositoryMock.Verify(m => m.GetClientSecretIdentityAsync(It.Is <string>(value => string.Compare(value, clientId, StringComparison.Ordinal) == 0)), Times.Once);
        }
예제 #6
0
        public async Task ExecuteAsync_WhenClientIdIsKnown_AssertClientSecretWasCalledOnClientSecretIdentity()
        {
            Mock <IClientSecretIdentity> clientSecretIdentityMock = _fixture.BuildClientSecretIdentityMock();
            CommandHandler sut = CreateSut(clientSecretIdentity: clientSecretIdentityMock.Object);

            IAuthenticateClientSecretCommand command = CreateCommand();
            await sut.ExecuteAsync(command);

            clientSecretIdentityMock.Verify(m => m.ClientSecret, Times.Once);
        }
예제 #7
0
        public async Task ExecuteAsync_WhenClientIdIsKnownAndClientSecretDoesMatch_ReturnsClientSecretIdentity()
        {
            string clientSecret = _fixture.Create <string>();
            IClientSecretIdentity clientSecretIdentity = _fixture.BuildClientSecretIdentityMock(clientSecret: clientSecret).Object;
            CommandHandler        sut = CreateSut(clientSecretIdentity: clientSecretIdentity);

            string submittedClientSecret             = clientSecret;
            IAuthenticateClientSecretCommand command = CreateCommand(clientSecret: submittedClientSecret);
            IClientSecretIdentity            result  = await sut.ExecuteAsync(command);

            Assert.That(result, Is.EqualTo(clientSecretIdentity));
        }
예제 #8
0
        public async Task ExecuteAsync_WhenClientIdIsKnownAndClientSecretDoesMatch_AssertGenerateWasCalledOnTokenHelper()
        {
            string clientSecret = _fixture.Create <string>();
            IClientSecretIdentity clientSecretIdentity = _fixture.BuildClientSecretIdentityMock(clientSecret: clientSecret).Object;
            CommandHandler        sut = CreateSut(clientSecretIdentity: clientSecretIdentity);

            string submittedClientSecret             = clientSecret;
            IAuthenticateClientSecretCommand command = CreateCommand(clientSecret: submittedClientSecret);
            await sut.ExecuteAsync(command);

            _tokenHelperMock.Verify(m => m.Generate(It.Is <IClientSecretIdentity>(value => value == clientSecretIdentity)), Times.Once);
        }
예제 #9
0
        public async Task ExecuteAsync_WhenClientIdIsKnownAndClientSecretDoesMatch_AssertClearSensitiveDataWasCalledOnClientSecretIdentity()
        {
            string clientSecret = _fixture.Create <string>();
            Mock <IClientSecretIdentity> clientSecretIdentityMock = _fixture.BuildClientSecretIdentityMock(clientSecret: clientSecret);
            CommandHandler sut = CreateSut(clientSecretIdentity: clientSecretIdentityMock.Object);

            string submittedClientSecret             = clientSecret;
            IAuthenticateClientSecretCommand command = CreateCommand(clientSecret: submittedClientSecret);
            await sut.ExecuteAsync(command);

            clientSecretIdentityMock.Verify(m => m.ClearSensitiveData(), Times.Once);
        }
예제 #10
0
        public async Task ExecuteAsync_WhenClientIdIsKnownAndClientSecretDoesNotMatch_ReturnNull()
        {
            string clientSecret = _fixture.Create <string>();
            Mock <IClientSecretIdentity> clientSecretIdentityMock = _fixture.BuildClientSecretIdentityMock(clientSecret: clientSecret);
            CommandHandler sut = CreateSut(clientSecretIdentity: clientSecretIdentityMock.Object);

            string submittedClientSecret             = _fixture.Create <string>();
            IAuthenticateClientSecretCommand command = CreateCommand(clientSecret: submittedClientSecret);
            IClientSecretIdentity            result  = await sut.ExecuteAsync(command);

            Assert.That(result, Is.Null);
        }
예제 #11
0
        public async Task ExecuteAsync_WhenClientIdIsKnownAndClientSecretDoesNotMatch_AssertAddTokenWasNotCalledOnClientSecretIdentity()
        {
            string clientSecret = _fixture.Create <string>();
            Mock <IClientSecretIdentity> clientSecretIdentityMock = _fixture.BuildClientSecretIdentityMock(clientSecret: clientSecret);
            CommandHandler sut = CreateSut(clientSecretIdentity: clientSecretIdentityMock.Object);

            string submittedClientSecret             = _fixture.Create <string>();
            IAuthenticateClientSecretCommand command = CreateCommand(clientSecret: submittedClientSecret);
            await sut.ExecuteAsync(command);

            clientSecretIdentityMock.Verify(m => m.AddToken(It.IsAny <IToken>()), Times.Never);
        }
예제 #12
0
        public async Task ExecuteAsync_WhenClientIdIsKnownAndClientSecretDoesMatch_AssertAddTokenWasCalledOnClientSecretIdentity()
        {
            string clientSecret = _fixture.Create <string>();
            Mock <IClientSecretIdentity> clientSecretIdentityMock = _fixture.BuildClientSecretIdentityMock(clientSecret: clientSecret);
            IToken         token = _fixture.BuildTokenMock().Object;
            CommandHandler sut   = CreateSut(clientSecretIdentity: clientSecretIdentityMock.Object, token: token);

            string submittedClientSecret             = clientSecret;
            IAuthenticateClientSecretCommand command = CreateCommand(clientSecret: submittedClientSecret);
            await sut.ExecuteAsync(command);

            clientSecretIdentityMock.Verify(m => m.AddToken(It.Is <IToken>(value => value == token)), Times.Once);
        }
예제 #13
0
        public async Task ExecuteAsync_WhenClientIdIsKnownAndClientSecretDoesMatch_AssertAddClaimsWasCalledOnClientSecretIdentity()
        {
            string clientSecret = _fixture.Create <string>();
            Mock <IClientSecretIdentity> clientSecretIdentityMock = _fixture.BuildClientSecretIdentityMock(clientSecret: clientSecret);
            CommandHandler sut = CreateSut(clientSecretIdentity: clientSecretIdentityMock.Object);

            string submittedClientSecret             = clientSecret;
            IEnumerable <Claim> claims               = new List <Claim>(0);
            IAuthenticateClientSecretCommand command = CreateCommand(clientSecret: submittedClientSecret, claims: claims);
            await sut.ExecuteAsync(command);

            clientSecretIdentityMock.Verify(m => m.AddClaims(It.Is <IEnumerable <Claim> >(value => Equals(value, claims))), Times.Once);
        }
예제 #14
0
        public void ExecuteAsync_WhenCommandIsNull_ThrowsArgumentNullException()
        {
            CommandHandler sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.ExecuteAsync(null));

            Assert.That(result.ParamName, Is.EqualTo("command"));
        }