Merge pull request #3142 from henricm/fix-for-win-mono_string_to_utf8
[mono.git] / mcs / class / Mono.Security / Test / Mono.Security.Protocol.Ntlm / Type1MessageTest.cs
1 //
2 // Mono.Security.Protocol.Ntlm.Type1MessageTest
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //
7 // Copyright (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
9
10 using System;
11 using System.Text;
12
13 using Mono.Security.Protocol.Ntlm;
14 using NUnit.Framework;
15
16 namespace MonoTests.Mono.Security.Protocol.Ntlm {
17
18         [TestFixture]
19         public class Type1MessageTest {
20
21                 [Test]
22                 // Example from http://www.innovation.ch/java/ntlm.html
23                 public void Encode1 () 
24                 {
25                         Type1Message msg = new Type1Message ();
26                         Assert.AreEqual (1, msg.Type, "Type");
27                         msg.Domain = "Ursa-Minor";
28                         msg.Host = "LightCity";
29                         Assert.AreEqual ("4E-54-4C-4D-53-53-50-00-01-00-00-00-07-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 ()), "GetBytes");
30                 }
31
32                 [Test]
33                 // Example from http://www.innovation.ch/java/ntlm.html
34                 public void Decode1 () 
35                 {
36                         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 };
37                         Type1Message msg = new Type1Message (data);
38                         Assert.AreEqual ("URSA-MINOR", msg.Domain, "Domain");
39                         Assert.AreEqual ((NtlmFlags)0xb203, msg.Flags, "Flags");
40                         Assert.AreEqual ("LIGHTCITY", msg.Host, "Host");
41                         Assert.AreEqual (1, msg.Type, "Type");
42                 }
43
44                 [Test]
45                 // Example from http://davenport.sourceforge.net/ntlm.html#type1MessageExample
46                 public void Decode2 () 
47                 {
48                         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 };
49                         Type1Message msg = new Type1Message (data);
50                         Assert.AreEqual ("DOMAIN", msg.Domain, "Domain");
51                         Assert.AreEqual ((NtlmFlags)0x3207, msg.Flags, "Flags");
52                         Assert.AreEqual ("WORKSTATION", msg.Host, "Host");
53                         Assert.AreEqual (1, msg.Type, "Type");
54                 }
55         }
56 }