Beispiel #1
0
        private async Task TestGoodDataAsync(string[] messageData, string expectedData, bool eightBitClean)
        {
            Mocks mocks = new Mocks();

            if (eightBitClean)
            {
                mocks.Connection.SetupGet(c => c.ReaderEncoding).Returns(Encoding.UTF8);
            }

            MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder();
            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);
            mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny <IConnection>())).Returns((long?)null);

            int messageLine = 0;

            mocks.Connection.Setup(c => c.ReadLineAsync()).Returns(() => Task.FromResult(messageData[messageLine++]));

            DataVerb verb = new DataVerb();
            await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("DATA"));

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.StartMailInputEndWithDot);
            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK);

            using (StreamReader dataReader = new StreamReader(messageBuilder.GetData(), eightBitClean ? Encoding.UTF8 : new ASCIISevenBitTruncatingEncoding()))
            {
                Assert.Equal(expectedData, dataReader.ReadToEnd());
            }
        }
Beispiel #2
0
        private async Task TestGoodDataAsync(string[] messageData, string expectedData, bool eightBitClean)
        {
            Mocks mocks = new Mocks();

            if (eightBitClean)
            {
                mocks.Connection.SetupGet(c => c.ReaderEncoding).Returns(Encoding.UTF8);
            }

            MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder();
            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);
            mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny<IConnection>())).Returns((long?)null);

            int messageLine = 0;
            mocks.Connection.Setup(c => c.ReadLineAsync()).Returns(() => Task.FromResult(messageData[messageLine++]));

            DataVerb verb = new DataVerb();
            await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("DATA"));

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.StartMailInputEndWithDot);
            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK);

            using (StreamReader dataReader = new StreamReader(messageBuilder.GetData(), eightBitClean ? Encoding.UTF8 : new ASCIISevenBitTruncatingEncoding()))
            {
                Assert.Equal(expectedData, dataReader.ReadToEnd());
            }
        }
Beispiel #3
0
        private async Task TestBadAddressAsync(string address)
        {
            Mocks mocks = new Mocks();
            MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder();
            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);

            RcptToVerb verb = new RcptToVerb();
            await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("TO " + address));

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.SyntaxErrorInCommandArguments);
            Assert.Equal(0, messageBuilder.To.Count);
        }
Beispiel #4
0
        private async Task TestGoodAddressAsync(string address, string expectedAddress)
        {
            Mocks mocks = new Mocks();
            MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder();
            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);

            RcptToVerb verb = new RcptToVerb();
            await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("TO " + address));

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK);
            Assert.Equal(expectedAddress, messageBuilder.To.First());
        }
Beispiel #5
0
        private async Task TestBadAddressAsync(string address)
        {
            var mocks          = new Mocks();
            var messageBuilder = new MemoryMessage.Builder();

            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);

            var verb = new RcptToVerb();
            await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("TO " + address));

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.SyntaxErrorInCommandArguments);
            Assert.Equal(0, messageBuilder.To.Count);
        }
Beispiel #6
0
        private async Task TestGoodAddressAsync(string address, string expectedAddress)
        {
            var mocks          = new Mocks();
            var messageBuilder = new MemoryMessage.Builder();

            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);

            var verb = new RcptToVerb();
            await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("TO " + address));

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.Ok);
            Assert.Equal(expectedAddress, messageBuilder.To.First());
        }
Beispiel #7
0
        private void TestBadAddress(string address)
        {
            Mocks mocks = new Mocks();

            MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder();
            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);

            RcptToVerb verb = new RcptToVerb();

            verb.Process(mocks.Connection.Object, new SmtpCommand("TO " + address));

            mocks.VerifyWriteResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments);
            Assert.AreEqual(0, messageBuilder.To.Count);
        }
Beispiel #8
0
        private void TestGoodAddress(string address, string expectedAddress)
        {
            Mocks mocks = new Mocks();

            MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder();
            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);

            RcptToVerb verb = new RcptToVerb();

            verb.Process(mocks.Connection.Object, new SmtpCommand("TO " + address));

            mocks.VerifyWriteResponse(StandardSmtpResponseCode.OK);
            Assert.AreEqual(expectedAddress, messageBuilder.To.First());
        }
Beispiel #9
0
        public async Task Data_AboveSizeLimit_Rejected()
        {
            Mocks mocks = new Mocks();

            MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder();
            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);
            mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny<IConnection>())).Returns(10);

            string[] messageData = new string[] { new string('x', 11), "." };
            int messageLine = 0;
            mocks.Connection.Setup(c => c.ReadLineAsync()).Returns(() => Task.FromResult(messageData[messageLine++]));

            DataVerb verb = new DataVerb();
            await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("DATA"));

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.StartMailInputEndWithDot);
            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.ExceededStorageAllocation);
        }
Beispiel #10
0
        public async Task Data_ExactlySizeLimit_Accepted()
        {
            Mocks mocks = new Mocks();

            MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder();
            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);
            mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny <IConnection>())).Returns(10);

            string[] messageData = new string[] { new string('x', 10), "." };
            int      messageLine = 0;

            mocks.Connection.Setup(c => c.ReadLineAsync()).Returns(() => Task.FromResult(messageData[messageLine++]));

            DataVerb verb = new DataVerb();
            await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("DATA"));

            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.StartMailInputEndWithDot);
            mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK);
        }
Beispiel #11
0
        public void Data_AboveSizeLimit_Rejected()
        {
            Mocks mocks = new Mocks();

            MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder();
            mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder);
            mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny <IConnection>())).Returns(10);

            string[] messageData = new string[] { new string('x', 11), "." };
            int      messageLine = 0;

            mocks.Connection.Setup(c => c.ReadLine()).Returns(() => messageData[messageLine++]);

            DataVerb verb = new DataVerb();

            verb.Process(mocks.Connection.Object, new SmtpCommand("DATA"));

            mocks.VerifyWriteResponse(StandardSmtpResponseCode.StartMailInputEndWithDot);
            mocks.VerifyWriteResponse(StandardSmtpResponseCode.ExceededStorageAllocation);
        }