f3c649dd48d1b6c16d1063627d8834b8140dc360
[mono.git] / mcs / class / Mono.Security / Test / Mono.Security.Protocol.Ntlm / Type2MessageTest.cs
1 //
2 // Mono.Security.Protocol.Ntlm.Type2MessageTest
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 Type2MessageTest : Assertion {
20
21                 static byte[] nonce = { 0x53, 0x72, 0x76, 0x4e, 0x6f, 0x6e, 0x63, 0x65 };
22
23                 [Test]
24                 // Example from http://www.innovation.ch/java/ntlm.html
25                 public void Encode1 () 
26                 {
27                         Type2Message msg = new Type2Message ();
28                         AssertEquals ("Type", 2, msg.Type);
29                         msg.Nonce = nonce;
30                         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 ()));
31                 }
32
33                 [Test]
34                 // Example from http://www.innovation.ch/java/ntlm.html
35                 public void Decode1 () 
36                 {
37                         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 };
38                         Type2Message msg = new Type2Message (data);
39                         AssertEquals ("Flags", (NtlmFlags)0x8201, msg.Flags);
40                         AssertEquals ("Nonce", BitConverter.ToString (nonce), BitConverter.ToString (msg.Nonce));
41                         AssertEquals ("Type", 2, msg.Type);
42                 }
43
44                 [Test]
45                 // Example from http://davenport.sourceforge.net/ntlm.html#type2MessageExample
46                 public void Decode2 () 
47                 {
48                         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 };
49                         Type2Message msg = new Type2Message (data);
50                         AssertEquals ("Flags", (NtlmFlags)0x00810201, msg.Flags);
51                         AssertEquals ("Nonce", "01-23-45-67-89-AB-CD-EF", BitConverter.ToString (msg.Nonce));
52                         AssertEquals ("Type", 2, msg.Type);
53                 }
54         }
55 }