2003-12-01 Sebastien Pouliot <spouliot@videotron.ca>
authorSebastien Pouliot <sebastien@ximian.com>
Tue, 2 Dec 2003 03:41:49 +0000 (03:41 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Tue, 2 Dec 2003 03:41:49 +0000 (03:41 -0000)
* ChallengeResponseTest.cs: New. Unit tests for NTLMv1 challenge response.
* Type1MessageTest.cs: New. Unit tests to encode/decode negotiation messages.
* Type2MessageTest.cs: New. Unit tests to encode/decode challenge messages.
* Type3MessageTest.cs: New. Unit tests to encode/decode authentication message.

svn path=/trunk/mcs/; revision=20677

mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/ChallengeResponseTest.cs [new file with mode: 0755]
mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/ChangeLog [new file with mode: 0755]
mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/Type1MessageTest.cs [new file with mode: 0755]
mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/Type2MessageTest.cs [new file with mode: 0755]
mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/Type3MessageTest.cs [new file with mode: 0755]

diff --git a/mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/ChallengeResponseTest.cs b/mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/ChallengeResponseTest.cs
new file mode 100755 (executable)
index 0000000..d05a683
--- /dev/null
@@ -0,0 +1,32 @@
+//
+// Mono.Security.Protocol.Ntlm.Type1MessageTest
+//
+// Author:
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// Copyright (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+using System.Text;
+
+using Mono.Security.Protocol.Ntlm;
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Security.Protocol.Ntlm {
+
+       [TestFixture]
+       public class ChallengeResponseTest : Assertion {
+
+               [Test]
+               // Example from http://www.innovation.ch/java/ntlm.html
+               public void BeeblebroxSrvNonce () 
+               {
+                       byte[] SrvNonce = Encoding.ASCII.GetBytes ("SrvNonce");
+                       using (ChallengeResponse ntlm = new ChallengeResponse ("Beeblebrox", SrvNonce)) {
+                               AssertEquals ("NT", "E0-E0-0D-E3-10-4A-1B-F2-05-3F-07-C7-DD-A8-2D-3C-48-9A-E9-89-E1-B0-00-D3", BitConverter.ToString (ntlm.NT));
+                               AssertEquals ("LM", "AD-87-CA-6D-EF-E3-46-85-B9-C4-3C-47-7A-8C-42-D6-00-66-7D-68-92-E7-E8-97", BitConverter.ToString (ntlm.LM));
+                       }
+               }
+       }
+}
diff --git a/mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/ChangeLog b/mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/ChangeLog
new file mode 100755 (executable)
index 0000000..bda764a
--- /dev/null
@@ -0,0 +1,6 @@
+2003-12-01  Sebastien Pouliot  <spouliot@videotron.ca>
+
+       * ChallengeResponseTest.cs: New. Unit tests for NTLMv1 challenge response.
+       * Type1MessageTest.cs: New. Unit tests to encode/decode negotiation messages.
+       * Type2MessageTest.cs: New. Unit tests to encode/decode challenge messages.
+       * Type3MessageTest.cs: New. Unit tests to encode/decode authentication message.
diff --git a/mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/Type1MessageTest.cs b/mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/Type1MessageTest.cs
new file mode 100755 (executable)
index 0000000..89e6aba
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// Mono.Security.Protocol.Ntlm.Type1MessageTest
+//
+// Author:
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// Copyright (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+using System.Text;
+
+using Mono.Security.Protocol.Ntlm;
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Security.Protocol.Ntlm {
+
+       [TestFixture]
+       public class Type1MessageTest : Assertion {
+
+               [Test]
+               // Example from http://www.innovation.ch/java/ntlm.html
+               public void Encode1 () 
+               {
+                       Type1Message msg = new Type1Message ();
+                       AssertEquals ("Type", 1, msg.Type);
+                       msg.Domain = "Ursa-Minor";
+                       msg.Host = "LightCity";
+                       AssertEquals ("GetBytes", "4E-54-4C-4D-53-53-50-00-01-00-00-00-03-B2-00-00-0A-00-0A-00-29-00-00-00-09-00-09-00-20-00-00-00-4C-49-47-48-54-43-49-54-59-55-52-53-41-2D-4D-49-4E-4F-52", BitConverter.ToString (msg.GetBytes ()));
+               }
+
+               [Test]
+               // Example from http://www.innovation.ch/java/ntlm.html
+               public void Decode1 () 
+               {
+                       byte[] data = { 0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0xb2, 0x00, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x29, 0x00, 0x00, 0x00, 0x09, 0x00, 0x09, 0x00, 0x20, 0x00, 0x00, 0x00, 0x4c, 0x49, 0x47, 0x48, 0x54, 0x43, 0x49, 0x54, 0x59, 0x55, 0x52, 0x53, 0x41, 0x2d, 0x4d, 0x49, 0x4e, 0x4f, 0x52 };
+                       Type1Message msg = new Type1Message (data);
+                       AssertEquals ("Domain", "URSA-MINOR", msg.Domain);
+                       AssertEquals ("Flags", (NtlmFlags)0xb203, msg.Flags);
+                       AssertEquals ("Host", "LIGHTCITY", msg.Host);
+                       AssertEquals ("Type", 1, msg.Type);
+               }
+
+               [Test]
+               // Example from http://davenport.sourceforge.net/ntlm.html#type1MessageExample
+               public void Decode2 () 
+               {
+                       byte[] data = { 0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x32, 0x00, 0x00, 0x06, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x0b, 0x00, 0x20, 0x00, 0x00, 0x00, 0x57, 0x4f, 0x52, 0x4b, 0x53, 0x54, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x44, 0x4f, 0x4d, 0x41, 0x49, 0x4e };
+                       Type1Message msg = new Type1Message (data);
+                       AssertEquals ("Domain", "DOMAIN", msg.Domain);
+                       AssertEquals ("Flags", (NtlmFlags)0x3207, msg.Flags);
+                       AssertEquals ("Host", "WORKSTATION", msg.Host);
+                       AssertEquals ("Type", 1, msg.Type);
+               }
+       }
+}
diff --git a/mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/Type2MessageTest.cs b/mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/Type2MessageTest.cs
new file mode 100755 (executable)
index 0000000..f3c649d
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// Mono.Security.Protocol.Ntlm.Type2MessageTest
+//
+// Author:
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// Copyright (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+using System.Text;
+
+using Mono.Security.Protocol.Ntlm;
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Security.Protocol.Ntlm {
+
+       [TestFixture]
+       public class Type2MessageTest : Assertion {
+
+               static byte[] nonce = { 0x53, 0x72, 0x76, 0x4e, 0x6f, 0x6e, 0x63, 0x65 };
+
+               [Test]
+               // Example from http://www.innovation.ch/java/ntlm.html
+               public void Encode1 () 
+               {
+                       Type2Message msg = new Type2Message ();
+                       AssertEquals ("Type", 2, msg.Type);
+                       msg.Nonce = nonce;
+                       AssertEquals ("GetBytes", "4E-54-4C-4D-53-53-50-00-02-00-00-00-00-00-00-00-28-00-00-00-01-82-00-00-53-72-76-4E-6F-6E-63-65-00-00-00-00-00-00-00-00", BitConverter.ToString (msg.GetBytes ()));
+               }
+
+               [Test]
+               // Example from http://www.innovation.ch/java/ntlm.html
+               public void Decode1 () 
+               {
+                       byte[] data = { 0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x82, 0x00, 0x00, 0x53, 0x72, 0x76, 0x4e, 0x6f, 0x6e, 0x63, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+                       Type2Message msg = new Type2Message (data);
+                       AssertEquals ("Flags", (NtlmFlags)0x8201, msg.Flags);
+                       AssertEquals ("Nonce", BitConverter.ToString (nonce), BitConverter.ToString (msg.Nonce));
+                       AssertEquals ("Type", 2, msg.Type);
+               }
+
+               [Test]
+               // Example from http://davenport.sourceforge.net/ntlm.html#type2MessageExample
+               public void Decode2 () 
+               {
+                       byte[] data = { 0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x02, 0x81, 0x00, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x00, 0x62, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x44, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x41, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x02, 0x00, 0x0c, 0x00, 0x44, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x41, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x01, 0x00, 0x0c, 0x00, 0x53, 0x00, 0x45, 0x00, 0x52, 0x00, 0x56, 0x00, 0x45, 0x00, 0x52, 0x00, 0x04, 0x00, 0x14, 0x00, 0x64, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x03, 0x00, 0x22, 0x00, 0x73, 0x00, 0x65, 0x00, 0x72, 0x00, 0x76, 0x00, 0x65, 0x00, 0x72, 0x00, 0x2e, 0x00, 0x64, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x2e, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00 };
+                       Type2Message msg = new Type2Message (data);
+                       AssertEquals ("Flags", (NtlmFlags)0x00810201, msg.Flags);
+                       AssertEquals ("Nonce", "01-23-45-67-89-AB-CD-EF", BitConverter.ToString (msg.Nonce));
+                       AssertEquals ("Type", 2, msg.Type);
+               }
+       }
+}
diff --git a/mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/Type3MessageTest.cs b/mcs/class/Mono.Security/Test/Mono.Security.Protocol.Ntlm/Type3MessageTest.cs
new file mode 100755 (executable)
index 0000000..9995956
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// Mono.Security.Protocol.Ntlm.Type3MessageTest
+//
+// Author:
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// Copyright (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+using System.Text;
+
+using Mono.Security.Protocol.Ntlm;
+using NUnit.Framework;
+
+namespace MonoTests.Mono.Security.Protocol.Ntlm {
+
+       [TestFixture]
+       public class NTLMTest : Assertion {
+
+               static byte[] nonce = { 0x53, 0x72, 0x76, 0x4e, 0x6f, 0x6e, 0x63, 0x65 };
+
+               [Test]
+               // Example from http://www.innovation.ch/java/ntlm.html
+               public void Encode1 () 
+               {
+                       Type3Message msg = new Type3Message ();
+                       msg.Challenge = nonce;
+                       msg.Domain = "Ursa-Minor";
+                       msg.Host = "LightCity";
+                       msg.Password = "Beeblebrox";
+                       msg.Username = "Zaphod";
+                       AssertEquals ("Type", 3, msg.Type);
+                       AssertEquals ("GetBytes", "4E-54-4C-4D-53-53-50-00-03-00-00-00-18-00-18-00-72-00-00-00-18-00-18-00-8A-00-00-00-14-00-14-00-40-00-00-00-0C-00-0C-00-54-00-00-00-12-00-12-00-60-00-00-00-00-00-00-00-A2-00-00-00-01-82-00-00-55-00-52-00-53-00-41-00-2D-00-4D-00-49-00-4E-00-4F-00-52-00-5A-00-61-00-70-00-68-00-6F-00-64-00-4C-00-49-00-47-00-48-00-54-00-43-00-49-00-54-00-59-00-AD-87-CA-6D-EF-E3-46-85-B9-C4-3C-47-7A-8C-42-D6-00-66-7D-68-92-E7-E8-97-E0-E0-0D-E3-10-4A-1B-F2-05-3F-07-C7-DD-A8-2D-3C-48-9A-E9-89-E1-B0-00-D3", BitConverter.ToString (msg.GetBytes ()));
+               }
+
+               [Test]
+               // Example from http://www.innovation.ch/java/ntlm.html
+               public void Decode1 () 
+               {
+                       byte[] data = { 0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00, 0x03, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x00, 0x72, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x14, 0x00, 0x14, 0x00, 0x40, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x54, 0x00, 0x00, 0x00, 0x12, 0x00, 0x12, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa2, 0x00, 0x00, 0x00, 0x01, 0x82, 0x00, 0x00, 0x55, 0x00, 0x52, 0x00, 0x53, 0x00, 0x41, 0x00, 0x2d, 0x00, 0x4d, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x4f, 0x00, 0x52, 0x00, 0x5a, 0x00, 0x61, 0x00, 0x70, 0x00, 0x68, 0x00, 0x6f, 0x00, 0x64, 0x00, 0x4c, 0x00, 0x49, 0x00, 0x47, 0x00, 0x48, 0x00, 0x54, 0x00, 0x43, 0x00, 0x49, 0x00, 0x54, 0x00, 0x59, 0x00, 0xad, 0x87, 0xca, 0x6d, 0xef, 0xe3, 0x46, 0x85, 0xb9, 0xc4, 0x3c, 0x47, 0x7a, 0x8c, 0x42, 0xd6, 0x00, 0x66, 0x7d, 0x68, 0x92, 0xe7, 0xe8, 0x97, 0xe0, 0xe0, 0x0d, 0xe3, 0x10, 0x4a, 0x1b, 0xf2, 0x05, 0x3f, 0x07, 0xc7, 0xdd, 0xa8, 0x2d, 0x3c, 0x48, 0x9a, 0xe9, 0x89, 0xe1, 0xb0, 0x00, 0xd3 };
+                       Type3Message msg = new Type3Message (data);
+                       AssertEquals ("Domain", "URSA-MINOR", msg.Domain);
+                       AssertEquals ("Host", "LIGHTCITY", msg.Host);
+                       AssertEquals ("Username", "Zaphod", msg.Username);
+                       AssertEquals ("Options", 0x8201, msg.Options);
+                       AssertEquals ("Type", 3, msg.Type);
+                       AssertNull ("Password", msg.Password);
+                       AssertEquals ("LM", "AD-87-CA-6D-EF-E3-46-85-B9-C4-3C-47-7A-8C-42-D6-00-66-7D-68-92-E7-E8-97", BitConverter.ToString (msg.LM));
+                       AssertEquals ("NT", "E0-E0-0D-E3-10-4A-1B-F2-05-3F-07-C7-DD-A8-2D-3C-48-9A-E9-89-E1-B0-00-D3", BitConverter.ToString (msg.NT));
+               }
+
+               [Test]
+               // Example from http://davenport.sourceforge.net/ntlm.html#type3MessageExample
+               public void Decode2 () 
+               {
+                       byte[] data = { 0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00, 0x03, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x00, 0x82, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x40, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x16, 0x00, 0x16, 0x00, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x44, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x41, 0x00, 0x49, 0x00, 0x4e, 0x00, 0x75, 0x00, 0x73, 0x00, 0x65, 0x00, 0x72, 0x00, 0x57, 0x00, 0x4f, 0x00, 0x52, 0x00, 0x4b, 0x00, 0x53, 0x00, 0x54, 0x00, 0x41, 0x00, 0x54, 0x00, 0x49, 0x00, 0x4f, 0x00, 0x4e, 0x00, 0xc3, 0x37, 0xcd, 0x5c, 0xbd, 0x44, 0xfc, 0x97, 0x82, 0xa6, 0x67, 0xaf, 0x6d, 0x42, 0x7c, 0x6d, 0xe6, 0x7c, 0x20, 0xc2, 0xd3, 0xe7, 0x7c, 0x56, 0x25, 0xa9, 0x8c, 0x1c, 0x31, 0xe8, 0x18, 0x47, 0x46, 0x6b, 0x29, 0xb2, 0xdf, 0x46, 0x80, 0xf3, 0x99, 0x58, 0xfb, 0x8c, 0x21, 0x3a, 0x9c, 0xc6 };
+                       Type3Message msg = new Type3Message (data);
+                       AssertEquals ("Domain", "DOMAIN", msg.Domain);
+                       AssertEquals ("Host", "WORKSTATION", msg.Host);
+                       AssertEquals ("Username", "user", msg.Username);
+                       AssertEquals ("Options", 0x201, msg.Options);
+                       AssertEquals ("Type", 3, msg.Type);
+                       AssertNull ("Password", msg.Password);
+                       AssertEquals ("LM", "C3-37-CD-5C-BD-44-FC-97-82-A6-67-AF-6D-42-7C-6D-E6-7C-20-C2-D3-E7-7C-56", BitConverter.ToString (msg.LM));
+                       AssertEquals ("NT", "25-A9-8C-1C-31-E8-18-47-46-6B-29-B2-DF-46-80-F3-99-58-FB-8C-21-3A-9C-C6", BitConverter.ToString (msg.NT));
+               }
+       }
+}