public void TestMultiLineSaslAuthCommand() { var detector = new SmtpAuthenticationSecretDetector(); 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"); }
public void TestSaslIRAuthCommandBitByBit() { const string command = "AUTH PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n"; var detector = new SmtpAuthenticationSecretDetector(); 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++; } }
public void TestMultiLineSaslAuthCommandBitByBit() { const string command = "AUTH LOGIN\r\ndXNlcm5hbWU=\r\ncGFzc3dvcmQ=\r\n"; var detector = new SmtpAuthenticationSecretDetector(); 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++; } }
public void TestNotIsAuthenticating() { const string command = "AUTH PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n"; var detector = new SmtpAuthenticationSecretDetector(); var buffer = Encoding.ASCII.GetBytes(command); var secrets = detector.DetectSecrets(buffer, 0, buffer.Length); Assert.AreEqual(0, secrets.Count, "# of secrets"); }
public void TestMultiLineSaslAuthCommand() { var detector = new SmtpAuthenticationSecretDetector(); 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"); }
public void TestEmptyCommand() { var detector = new SmtpAuthenticationSecretDetector(); var buffer = new byte[0]; detector.IsAuthenticating = true; var secrets = detector.DetectSecrets(buffer, 0, buffer.Length); Assert.AreEqual(0, secrets.Count, "# of secrets"); }
public void TestNonAuthCommand() { const string command = "MAIL FROM:<*****@*****.**>\r\n"; var detector = new SmtpAuthenticationSecretDetector(); var buffer = Encoding.ASCII.GetBytes(command); detector.IsAuthenticating = true; var secrets = detector.DetectSecrets(buffer, 0, buffer.Length); Assert.AreEqual(0, secrets.Count, "# of secrets"); }
public void TestSaslIRAuthCommand() { const string command = "AUTH PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n"; var detector = new SmtpAuthenticationSecretDetector(); 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"); }