Exemplo n.º 1
0
        public void TestReadResponseMismatchedResponseCodes()
        {
            using (var stream = new SmtpStream(new DummyNetworkStream(), new NullProtocolLogger())) {
                var buffer = Encoding.ASCII.GetBytes("250-This is the first line of a response.\r\n340 And this is a mismatched response code.\r\n");
                var dummy  = (MemoryStream)stream.Stream;

                dummy.Write(buffer, 0, buffer.Length);
                dummy.Position = 0;

                Assert.Throws <SmtpProtocolException> (() => stream.ReadResponse(CancellationToken.None));
            }
        }
Exemplo n.º 2
0
        public void TestReadResponseInvalidResponseCode()
        {
            using (var stream = new SmtpStream(new DummyNetworkStream(), new NullProtocolLogger())) {
                var buffer = Encoding.ASCII.GetBytes("XXX This is an invalid response.\r\n");
                var dummy  = (MemoryStream)stream.Stream;

                dummy.Write(buffer, 0, buffer.Length);
                dummy.Position = 0;

                Assert.Throws <SmtpProtocolException> (() => stream.ReadResponse(CancellationToken.None));
            }
        }
Exemplo n.º 3
0
        public void TestReadResponseLatin1Fallback()
        {
            const string input    = "250-Wikipédia est un projet d'encyclopédie collective en ligne,\r\n250-universelle, multilingue et fonctionnant sur le principe du wiki.\r\n250-Ce projet vise à offrir un contenu librement réutilisable, objectif\r\n250 et vérifiable, que chacun peut modifier et améliorer.\r\n";
            var          expected = input.Replace("250-", "").Replace("250 ", "").Replace("\r\n", "\n").TrimEnd();

            using (var stream = new SmtpStream(new DummyNetworkStream(), new NullProtocolLogger())) {
                var buffer = Encoding.GetEncoding(28591).GetBytes(input);
                var dummy  = (MemoryStream)stream.Stream;

                dummy.Write(buffer, 0, buffer.Length);
                dummy.Position = 0;

                var response = stream.ReadResponse(CancellationToken.None);

                Assert.AreEqual(250, (int)response.StatusCode);
                Assert.AreEqual(expected, response.Response);
            }
        }
Exemplo n.º 4
0
        public void TestReadResponseOver4K()
        {
            string expected;
            string input;

            using (var rng = new RNGCryptoServiceProvider()) {
                var builder = new StringBuilder();
                var buffer  = new byte[72];

                while (builder.Length < 5120)
                {
                    rng.GetBytes(buffer);

                    var base64 = Convert.ToBase64String(buffer);
                    builder.AppendFormat("250-{0}\r\n", base64);
                }

                builder.Append("250 Okay, now we're done.\r\n");
                input = builder.ToString();

                expected = input.Replace("250-", "").Replace("250 ", "").Replace("\r\n", "\n").TrimEnd();
            }

            using (var stream = new SmtpStream(new DummyNetworkStream(), new NullProtocolLogger())) {
                var buffer = Encoding.ASCII.GetBytes(input);
                var dummy  = (MemoryStream)stream.Stream;

                dummy.Write(buffer, 0, buffer.Length);
                dummy.Position = 0;

                var response = stream.ReadResponse(CancellationToken.None);

                Assert.AreEqual(250, (int)response.StatusCode);
                Assert.AreEqual(expected, response.Response);
            }
        }