Exemple #1
0
        public async Task ProcessResponse_PasswordAcceptedAfterUserNameInInitialRequest()
        {
            TestMocks mocks = new TestMocks();

            mocks.ServerBehaviour.Setup(sb => sb.ValidateAuthenticationCredentials(It.IsAny <IConnection>(), It.IsAny <IAuthenticationCredentials>())).Returns(Task.FromResult(AuthenticationResult.Success));


            LoginMechanismProcessor      processor = this.Setup(mocks);
            AuthMechanismProcessorStatus result    = await processor.ProcessResponse(EncodeBase64("rob")).ConfigureAwait(false);

            Assert.Equal(AuthMechanismProcessorStatus.Continue, result);

            mocks.Connection.Verify(c =>
                                    c.WriteResponse(
                                        It.Is <SmtpResponse>(r =>
                                                             VerifyBase64Response(r.Message, "Password:"******"password")).ConfigureAwait(false);

            Assert.Equal(AuthMechanismProcessorStatus.Success, result);
        }
Exemple #2
0
        public void ProcessResponse_Response_BadBase64()
        {
            Mocks mocks = new Mocks();

            LoginMechanismProcessor processor = Setup(mocks);

            processor.ProcessResponse(null);
            processor.ProcessResponse("rob blah");
        }
Exemple #3
0
        public async Task ProcessResponse_Response_BadBase64()
        {
            await Assert.ThrowsAsync <BadBase64Exception>(async() =>
            {
                Mocks mocks = new Mocks();

                LoginMechanismProcessor processor = Setup(mocks);
                await processor.ProcessResponseAsync(null);
                await processor.ProcessResponseAsync("rob blah");
            });
        }
Exemple #4
0
        public async Task ProcessResponse_Response_BadBase64()
        {
            await Assert.ThrowsAsync <BadBase64Exception>(async() =>
            {
                TestMocks mocks = new TestMocks();

                LoginMechanismProcessor processor = this.Setup(mocks);
                await processor.ProcessResponse(null).ConfigureAwait(false);
                await processor.ProcessResponse("rob blah").ConfigureAwait(false);
            }).ConfigureAwait(false);
        }
Exemple #5
0
        public void ProcessRepsonse_NoUsername_GetUsernameChallenge()
        {
            Mocks mocks = new Mocks();

            LoginMechanismProcessor      processor = Setup(mocks);
            AuthMechanismProcessorStatus result    = processor.ProcessResponse(null);

            Assert.AreEqual(AuthMechanismProcessorStatus.Continue, result);
            mocks.Connection.Verify(c =>
                                    c.WriteResponse(
                                        It.Is <SmtpResponse>(r =>
                                                             r.Code == (int)StandardSmtpResponseCode.AuthenticationContinue &&
                                                             VerifyBase64Response(r.Message, "Username:")
                                                             )
                                        )
                                    );
        }
Exemple #6
0
        public async Task ProcessRepsonse_NoUsername_GetUsernameChallenge()
        {
            TestMocks mocks = new TestMocks();

            LoginMechanismProcessor      processor = this.Setup(mocks);
            AuthMechanismProcessorStatus result    = await processor.ProcessResponse(null).ConfigureAwait(false);

            Assert.Equal(AuthMechanismProcessorStatus.Continue, result);
            mocks.Connection.Verify(c =>
                                    c.WriteResponse(
                                        It.Is <SmtpResponse>(r =>
                                                             r.Code == (int)StandardSmtpResponseCode.AuthenticationContinue &&
                                                             VerifyBase64Response(r.Message, "Username:")
                                                             )
                                        )
                                    );
        }
Exemple #7
0
        public async Task ProcessRepsonse_Username_GetPasswordChallenge()
        {
            Mocks mocks = new Mocks();

            LoginMechanismProcessor      processor = Setup(mocks);
            AuthMechanismProcessorStatus result    = await processor.ProcessResponseAsync(EncodeBase64("rob"));

            Assert.Equal(AuthMechanismProcessorStatus.Continue, result);

            mocks.Connection.Verify(c =>
                                    c.WriteResponseAsync(
                                        It.Is <SmtpResponse>(r =>
                                                             VerifyBase64Response(r.Message, "Password:") &&
                                                             r.Code == (int)StandardSmtpResponseCode.AuthenticationContinue
                                                             )
                                        )
                                    );
        }
Exemple #8
0
        public async Task ProcessResponse_PasswordAcceptedAfterUserNameInInitialRequest()
        {
            Mocks mocks = new Mocks();

            LoginMechanismProcessor      processor = Setup(mocks);
            AuthMechanismProcessorStatus result    = await processor.ProcessResponseAsync(EncodeBase64("rob"));

            Assert.Equal(AuthMechanismProcessorStatus.Continue, result);

            mocks.Connection.Verify(c =>
                                    c.WriteResponseAsync(
                                        It.Is <SmtpResponse>(r =>
                                                             VerifyBase64Response(r.Message, "Password:"******"password"));

            Assert.Equal(AuthMechanismProcessorStatus.Success, result);
        }