Copied remotely
[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 (sebastien@ximian.com)
6 //
7 // Copyright (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 Novell (http://www.novell.com)
9 //
10
11 using System;
12 using System.Text;
13
14 using Mono.Security.Protocol.Ntlm;
15 using NUnit.Framework;
16
17 namespace MonoTests.Mono.Security.Protocol.Ntlm {
18
19         [TestFixture]
20         public class Type2MessageTest : Assertion {
21
22                 static byte[] nonce = { 0x53, 0x72, 0x76, 0x4e, 0x6f, 0x6e, 0x63, 0x65 };
23
24                 [Test]
25                 // Example from http://www.innovation.ch/java/ntlm.html
26                 public void Encode1 () 
27                 {
28                         Type2Message msg = new Type2Message ();
29                         AssertEquals ("Type", 2, msg.Type);
30                         msg.Nonce = nonce;
31                         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 ()));
32                 }
33
34                 [Test]
35                 // Example from http://www.innovation.ch/java/ntlm.html
36                 public void Decode1 () 
37                 {
38                         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 };
39                         Type2Message msg = new Type2Message (data);
40                         AssertEquals ("Flags", (NtlmFlags)0x8201, msg.Flags);
41                         AssertEquals ("Nonce", BitConverter.ToString (nonce), BitConverter.ToString (msg.Nonce));
42                         AssertEquals ("Type", 2, msg.Type);
43                 }
44
45                 [Test]
46                 // Example from http://davenport.sourceforge.net/ntlm.html#type2MessageExample
47                 public void Decode2 () 
48                 {
49                         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 };
50                         Type2Message msg = new Type2Message (data);
51                         AssertEquals ("Flags", (NtlmFlags)0x00810201, msg.Flags);
52                         AssertEquals ("Nonce", "01-23-45-67-89-AB-CD-EF", BitConverter.ToString (msg.Nonce));
53                         AssertEquals ("Type", 2, msg.Type);
54                 }
55                 
56                 [Test]
57                 [ExpectedException (typeof (ArgumentNullException))]
58                 public void Nonce_Null () 
59                 {
60                         Type2Message msg = new Type2Message ();
61                         msg.Nonce = null;
62                 }
63                 
64                 [Test]
65                 [ExpectedException (typeof (ArgumentException))]
66                 public void Nonce_InvalidLength () 
67                 {
68                         Type2Message msg = new Type2Message ();
69                         msg.Nonce = new byte [9];
70                 }
71         }
72 }