コード例 #1
0
        public void TestMultiLineSaslAuthCommand()
        {
            var detector = new Pop3AuthenticationSecretDetector();
            IList <AuthenticationSecret> secrets;

            byte[] buffer;

            detector.IsAuthenticating = true;

            buffer  = Encoding.ASCII.GetBytes("AUTH LOGIN\r\n");
            secrets = detector.DetectSecrets(buffer, 0, buffer.Length);
            Assert.AreEqual(0, secrets.Count, "initial # of secrets");

            buffer  = Encoding.ASCII.GetBytes("dXNlcm5hbWU=\r\n");
            secrets = detector.DetectSecrets(buffer, 0, buffer.Length);
            Assert.AreEqual(1, secrets.Count, "# of secrets");
            Assert.AreEqual(0, secrets[0].StartIndex, "StartIndex");
            Assert.AreEqual(12, secrets[0].Length, "Length");

            buffer  = Encoding.ASCII.GetBytes("cGFzc3dvcmQ=\r\n");
            secrets = detector.DetectSecrets(buffer, 0, buffer.Length);
            Assert.AreEqual(1, secrets.Count, "# of secrets");
            Assert.AreEqual(0, secrets[0].StartIndex, "StartIndex");
            Assert.AreEqual(12, secrets[0].Length, "Length");
        }
コード例 #2
0
        public void TestApopCommandBitByBit()
        {
            const string command  = "APOP username AHVzZXJuYW1lAHBhc3N3b3Jk\r\n";
            var          detector = new Pop3AuthenticationSecretDetector();
            var          buffer   = Encoding.ASCII.GetBytes(command);
            IList <AuthenticationSecret> secrets;
            int index = 0;

            detector.IsAuthenticating = true;

            while (index < command.Length)
            {
                secrets = detector.DetectSecrets(buffer, index, 1);
                if (index >= 5 && index != 13 && index < command.Length - 2)
                {
                    Assert.AreEqual(1, secrets.Count, "# of secrets @ index {0}", index);
                    Assert.AreEqual(index, secrets[0].StartIndex, "StartIndex");
                    Assert.AreEqual(1, secrets[0].Length, "Length");
                }
                else
                {
                    Assert.AreEqual(0, secrets.Count, "# of secrets @ index {0}", index);
                }
                index++;
            }
        }
コード例 #3
0
        public void TestMultiLineSaslAuthCommandBitByBit()
        {
            const string command     = "AUTH LOGIN\r\ndXNlcm5hbWU=\r\ncGFzc3dvcmQ=\r\n";
            var          detector    = new Pop3AuthenticationSecretDetector();
            var          buffer      = Encoding.ASCII.GetBytes(command);
            int          secretIndex = "AUTH LOGIN\r\n".Length;
            IList <AuthenticationSecret> secrets;
            int index = 0;

            detector.IsAuthenticating = true;

            while (index < command.Length)
            {
                secrets = detector.DetectSecrets(buffer, index, 1);
                if (index >= secretIndex && command[index] != '\r' && command[index] != '\n')
                {
                    Assert.AreEqual(1, secrets.Count, "# of secrets @ index {0}", index);
                    Assert.AreEqual(index, secrets[0].StartIndex, "StartIndex");
                    Assert.AreEqual(1, secrets[0].Length, "Length");
                }
                else
                {
                    Assert.AreEqual(0, secrets.Count, "# of secrets @ index {0}", index);
                }
                index++;
            }
        }
コード例 #4
0
        public void TestSaslIRAuthCommandBitByBit()
        {
            const string command     = "AUTH PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n";
            var          detector    = new Pop3AuthenticationSecretDetector();
            var          buffer      = Encoding.ASCII.GetBytes(command);
            int          secretIndex = "AUTH PLAIN ".Length;
            IList <AuthenticationSecret> secrets;
            int index = 0;

            detector.IsAuthenticating = true;

            while (index < command.Length)
            {
                secrets = detector.DetectSecrets(buffer, index, 1);
                if (index >= secretIndex && command[index] != '\r' && command[index] != '\n')
                {
                    Assert.AreEqual(1, secrets.Count, "# of secrets @ index {0}", index);
                    Assert.AreEqual(index, secrets[0].StartIndex, "StartIndex");
                    Assert.AreEqual(1, secrets[0].Length, "Length");
                }
                else
                {
                    Assert.AreEqual(0, secrets.Count, "# of secrets @ index {0}", index);
                }
                index++;
            }
        }
コード例 #5
0
        public void TestUserPassCommandBitByBit()
        {
            const string command  = "USER user\r\nPASS p@$$w0rd\r\n";
            var          detector = new Pop3AuthenticationSecretDetector();
            var          buffer   = Encoding.ASCII.GetBytes(command);
            IList <AuthenticationSecret> secrets;
            int index = 0;

            detector.IsAuthenticating = true;

            while (index < command.Length)
            {
                secrets = detector.DetectSecrets(buffer, index, 1);
                if ((index >= 5 && index < 9) || (index >= 16 && index < 24))
                {
                    Assert.AreEqual(1, secrets.Count, "# of secrets @ index {0}", index);
                    Assert.AreEqual(index, secrets[0].StartIndex, "StartIndex");
                    Assert.AreEqual(1, secrets[0].Length, "Length");
                }
                else
                {
                    Assert.AreEqual(0, secrets.Count, "# of secrets @ index {0}", index);
                }
                index++;
            }
        }
コード例 #6
0
        public void TestNotIsAuthenticating()
        {
            const string command  = "AUTH PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n";
            var          detector = new Pop3AuthenticationSecretDetector();
            var          buffer   = Encoding.ASCII.GetBytes(command);

            var secrets = detector.DetectSecrets(buffer, 0, buffer.Length);

            Assert.AreEqual(0, secrets.Count, "# of secrets");
        }
コード例 #7
0
        public void TestMultiLineSaslAuthCommand()
        {
            var detector = new Pop3AuthenticationSecretDetector();
            IList <AuthenticationSecret> secrets;

            byte[] buffer;

            detector.IsAuthenticating = true;

            buffer  = Encoding.ASCII.GetBytes("AUTH PLAIN\r\n");
            secrets = detector.DetectSecrets(buffer, 0, buffer.Length);
            Assert.AreEqual(0, secrets.Count, "initial # of secrets");

            buffer  = Encoding.ASCII.GetBytes("AHVzZXJuYW1lAHBhc3N3b3Jk\r\n");
            secrets = detector.DetectSecrets(buffer, 0, buffer.Length);
            Assert.AreEqual(1, secrets.Count, "# of secrets");
            Assert.AreEqual(0, secrets[0].StartIndex, "StartIndex");
            Assert.AreEqual(24, secrets[0].Length, "Length");
        }
コード例 #8
0
        public void TestEmptyCommand()
        {
            var detector = new Pop3AuthenticationSecretDetector();
            var buffer   = new byte[0];

            detector.IsAuthenticating = true;

            var secrets = detector.DetectSecrets(buffer, 0, buffer.Length);

            Assert.AreEqual(0, secrets.Count, "# of secrets");
        }
コード例 #9
0
        public void TestNonAuthCommand()
        {
            const string command  = "UIDL 1\r\n";
            var          detector = new Pop3AuthenticationSecretDetector();
            var          buffer   = Encoding.ASCII.GetBytes(command);

            detector.IsAuthenticating = true;

            var secrets = detector.DetectSecrets(buffer, 0, buffer.Length);

            Assert.AreEqual(0, secrets.Count, "# of secrets");
        }
コード例 #10
0
        public void TestUserPassCommand()
        {
            var detector = new Pop3AuthenticationSecretDetector();
            IList <AuthenticationSecret> secrets;

            byte[] buffer;

            detector.IsAuthenticating = true;

            buffer  = Encoding.ASCII.GetBytes("USER user\r\n");
            secrets = detector.DetectSecrets(buffer, 0, buffer.Length);
            Assert.AreEqual(1, secrets.Count, "USER # of secrets");
            Assert.AreEqual(5, secrets[0].StartIndex, "USER StartIndex");
            Assert.AreEqual(4, secrets[0].Length, "USER Length");

            buffer  = Encoding.ASCII.GetBytes("PASS p@$$w0rd\r\n");
            secrets = detector.DetectSecrets(buffer, 0, buffer.Length);
            Assert.AreEqual(1, secrets.Count, "PASS # of secrets");
            Assert.AreEqual(5, secrets[0].StartIndex, "PASS StartIndex");
            Assert.AreEqual(8, secrets[0].Length, "PASS Length");
        }
コード例 #11
0
        public void TestSaslIRAuthCommand()
        {
            const string command  = "AUTH PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n";
            var          detector = new Pop3AuthenticationSecretDetector();
            var          buffer   = Encoding.ASCII.GetBytes(command);

            detector.IsAuthenticating = true;

            var secrets = detector.DetectSecrets(buffer, 0, buffer.Length);

            Assert.AreEqual(1, secrets.Count, "# of secrets");
            Assert.AreEqual(11, secrets[0].StartIndex, "StartIndex");
            Assert.AreEqual(24, secrets[0].Length, "Length");
        }