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

            byte[] buffer;

            detector.IsAuthenticating = true;

            buffer  = Encoding.ASCII.GetBytes("A00000000 AUTHENTICATE 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 TestLoginCommandBitByBit()
        {
            const string command     = "A00000000 LOGIN username password\r\n";
            var          userIndex   = command.IndexOf("username", StringComparison.Ordinal);
            var          passwdIndex = command.IndexOf("password", StringComparison.Ordinal);
            var          detector    = new ImapAuthenticationSecretDetector();
            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 >= userIndex && index < userIndex + 8) || (index >= passwdIndex && index < passwdIndex + 8))
                {
                    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     = "A00000000 AUTHENTICATE LOGIN\r\ndXNlcm5hbWU=\r\ncGFzc3dvcmQ=\r\n";
            var          secretIndex = command.IndexOf("dXNlcm5hbWU=", StringComparison.Ordinal);
            var          detector    = new ImapAuthenticationSecretDetector();
            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 >= 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 TestLoginCommandLiterals()
        {
            var detector = new ImapAuthenticationSecretDetector();
            IList <AuthenticationSecret> secrets;

            byte[] buffer;

            detector.IsAuthenticating = true;

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

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

            buffer  = Encoding.ASCII.GetBytes("password\r\n");
            secrets = detector.DetectSecrets(buffer, 0, buffer.Length);
            Assert.AreEqual(1, secrets.Count, "password # of secrets");
            Assert.AreEqual(0, secrets[0].StartIndex, "Password StartIndex");
            Assert.AreEqual(8, secrets[0].Length, "Password Length");
        }
コード例 #5
0
        public void TestSaslIRAuthCommandBitByBit()
        {
            const string command     = "A00000000 AUTHENTICATE PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n";
            var          secretIndex = command.IndexOf("AHVzZXJuYW1lAHBhc3N3b3Jk", System.StringComparison.Ordinal);
            var          detector    = new ImapAuthenticationSecretDetector();
            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 >= 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++;
            }
        }
コード例 #6
0
        public void TestNotIsAuthenticating()
        {
            const string command  = "A00000000 AUTHENTICATE PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n";
            var          detector = new ImapAuthenticationSecretDetector();
            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 TestEmptyCommand()
        {
            var detector = new ImapAuthenticationSecretDetector();
            var buffer   = new byte[0];

            detector.IsAuthenticating = true;

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

            Assert.AreEqual(0, secrets.Count, "# of secrets");
        }
コード例 #8
0
        public void TestNonAuthCommand()
        {
            string command  = string.Format("A00000000 APPEND INBOX (\\Seen) \"{0}\" {{4096}}\r\n", ImapUtils.FormatInternalDate(DateTimeOffset.Now));
            var    detector = new ImapAuthenticationSecretDetector();
            var    buffer   = Encoding.ASCII.GetBytes(command);

            detector.IsAuthenticating = true;

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

            Assert.AreEqual(0, secrets.Count, "# of secrets");
        }
コード例 #9
0
        public void TestSaslIRAuthCommand()
        {
            const string command     = "A00000000 AUTHENTICATE PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n";
            var          secretIndex = command.IndexOf("AHVzZXJuYW1lAHBhc3N3b3Jk", StringComparison.Ordinal);
            var          detector    = new ImapAuthenticationSecretDetector();
            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(secretIndex, secrets[0].StartIndex, "StartIndex");
            Assert.AreEqual(24, secrets[0].Length, "Length");
        }
コード例 #10
0
        public void TestLoginCommand()
        {
            const string command     = "A00000000 LOGIN username password\r\n";
            var          userIndex   = command.IndexOf("username", StringComparison.Ordinal);
            var          passwdIndex = command.IndexOf("password", StringComparison.Ordinal);
            var          detector    = new ImapAuthenticationSecretDetector();
            var          buffer      = Encoding.ASCII.GetBytes(command);

            detector.IsAuthenticating = true;

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

            Assert.AreEqual(2, secrets.Count, "# of secrets");
            Assert.AreEqual(userIndex, secrets[0].StartIndex, "UserName StartIndex");
            Assert.AreEqual(8, secrets[0].Length, "UserName Length");
            Assert.AreEqual(passwdIndex, secrets[1].StartIndex, "Password StartIndex");
            Assert.AreEqual(8, secrets[1].Length, "Password Length");
        }
コード例 #11
0
        public void TestMultiLineSaslAuthCommand()
        {
            var detector = new ImapAuthenticationSecretDetector();
            IList <AuthenticationSecret> secrets;

            byte[] buffer;

            detector.IsAuthenticating = true;

            buffer  = Encoding.ASCII.GetBytes("A00000000 AUTHENTICATE 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");
        }