コード例 #1
0
        public async Task Unsecured_NoCertificate_ExtendedHelloResponds()
        {
            var channel = new MockSmtpChannel();
            var conn    = new MockConnectionSecurity();

            var command = new ExtendedHelloCommand(
                TestHelpers.GetAuths(),
                conn,
                channel,
                TestHelpers.MakeSettings("test.vaettir.net"),
                new MockLogger());

            command.Initialize("Sender.net");

            await command.ExecuteAsync(CancellationToken.None);

            Assert.True(channel.Entries.All(c => c.Code == SmtpReplyCode.Okay));
            Assert.True(channel.Entries.Take(channel.Entries.Count - 1).All(e => e.More));
            Assert.False(channel.Entries.Last().More);

            Assert.DoesNotContain(channel.Entries, e => e.Message == "STARTTLS");
            Assert.DoesNotContain(channel.Entries, e => e.Message == "AUTH ENC");
            Assert.Contains(channel.Entries, e => e.Message == "AUTH PLN");

            MockSmtpChannel.Entry signoff = channel.Entries.First();
            Assert.Contains("test.vaettir.net", signoff.Message);
            Assert.Contains("Sender.net", signoff.Message);
        }
コード例 #2
0
        public async Task Unsecured_Certificate_ExtendedHelloResponds()
        {
            var channel = new MockSmtpChannel();
            var conn    = new MockConnectionSecurity();

            conn.Certificate = TestHelpers.GetSelfSigned();

            var command = new ExtendedHelloCommand(
                TestHelpers.GetAuths(),
                conn,
                channel,
                TestHelpers.MakeSettings("test.vaettir.net"),
                new MockLogger());

            command.Initialize("Sender.net");

            await command.ExecuteAsync(CancellationToken.None);

            Assert.True(channel.Entries.All(c => c.Code == SmtpReplyCode.Okay));
            Assert.True(channel.Entries.Take(channel.Entries.Count - 1).All(e => e.More));
            Assert.False(channel.Entries.Last().More);

            Assert.Contains(channel.Entries, e => e.Message == "STARTTLS");
            List <MockSmtpChannel.Entry> authReplies = channel.Entries.Where(e => e.Message.StartsWith("AUTH")).ToList();

            Assert.Single(authReplies);
            List <string> authParts = authReplies[0].Message.Split(' ').Skip(1).ToList();

            SequenceAssert.SameSet(new[] { "PLN" }, authParts);

            MockSmtpChannel.Entry signoff = channel.Entries.First();
            Assert.Contains("test.vaettir.net", signoff.Message);
            Assert.Contains("Sender.net", signoff.Message);
        }