KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > auth > ntlm > NTLMMessageTest


1 /*
2  * Copyright (C) 2006 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.server.auth.ntlm;
18
19 import junit.framework.TestCase;
20
21 /**
22  * NTLM Message Test Class
23  *
24  * @author GKSpencer
25  */

26 public class NTLMMessageTest extends TestCase
27 {
28     /**
29      * Test type 1 message packing/unpacking
30      */

31     public void testType1Message()
32     {
33         // Create a minimal type 1 message
34

35         Type1NTLMMessage ntlmMsg = new Type1NTLMMessage();
36         ntlmMsg.buildType1(0, null, null);
37         
38         assertEquals("Minimal type 1 message length wrong", 16, ntlmMsg.getLength());
39         assertFalse("Minimal type 1 message domain supplied flag set", ntlmMsg.hasFlag(NTLM.FlagDomainSupplied));
40         assertFalse("Minimal type 1 message workstation supplied flag set", ntlmMsg.hasFlag(NTLM.FlagWorkstationSupplied));
41         assertFalse("Minimal type 1 has domain", ntlmMsg.hasDomain());
42         assertNull("Minimal type 1 domain not null", ntlmMsg.getDomain());
43         assertFalse("Minimal type 1 has workstation", ntlmMsg.hasWorkstation());
44         assertNull("Minimal type 1 workstation not null", ntlmMsg.getWorkstation());
45         
46         // Use a buffer to build a type 1 message
47

48         byte[] buf = new byte[256];
49         ntlmMsg = new Type1NTLMMessage(buf, 128, 128);
50         ntlmMsg.buildType1(0, null, null);
51         
52         assertEquals("Minimal type 1 message length wrong", 16, ntlmMsg.getLength());
53         assertFalse("Minimal type 1 message domain supplied flag set", ntlmMsg.hasFlag(NTLM.FlagDomainSupplied));
54         assertFalse("Minimal type 1 message workstation supplied flag set", ntlmMsg.hasFlag(NTLM.FlagWorkstationSupplied));
55         assertFalse("Minimal type 1 has domain", ntlmMsg.hasDomain());
56         assertNull("Minimal type 1 domain not null", ntlmMsg.getDomain());
57         assertFalse("Minimal type 1 has workstation", ntlmMsg.hasWorkstation());
58         assertNull("Minimal type 1 workstation not null", ntlmMsg.getWorkstation());
59         
60         // Test type 1 with domain name only
61

62         String JavaDoc testDomain = "TESTDOMAIN";
63         String JavaDoc testWks = "TESTPC";
64         
65         ntlmMsg = new Type1NTLMMessage();
66         ntlmMsg.buildType1(0, testDomain, null);
67         
68         assertTrue("Minimal type 1 message length wrong", ntlmMsg.getLength() > 16);
69         assertTrue("Minimal type 1 message domain supplied flag not set", ntlmMsg.hasFlag(NTLM.FlagDomainSupplied));
70         assertFalse("Minimal type 1 message workstation supplied flag set", ntlmMsg.hasFlag(NTLM.FlagWorkstationSupplied));
71         assertTrue("Minimal type 1 no domain", ntlmMsg.hasDomain());
72         assertEquals("Minimal type 1 domain not correct", testDomain, ntlmMsg.getDomain());
73         assertFalse("Minimal type 1 has workstation", ntlmMsg.hasWorkstation());
74         assertNull("Minimal type 1 workstation not null", ntlmMsg.getWorkstation());
75         
76         // Test type 1 with domain name only with buffer
77

78         ntlmMsg = new Type1NTLMMessage(buf, 128, 128);
79         ntlmMsg.buildType1(0, testDomain, null);
80
81         assertTrue("Minimal type 1 message length wrong", ntlmMsg.getLength() > 16);
82         assertTrue("Minimal type 1 message domain supplied flag not set", ntlmMsg.hasFlag(NTLM.FlagDomainSupplied));
83         assertFalse("Minimal type 1 message workstation supplied flag set", ntlmMsg.hasFlag(NTLM.FlagWorkstationSupplied));
84         assertTrue("Minimal type 1 no domain", ntlmMsg.hasDomain());
85         assertEquals("Minimal type 1 domain not correct", testDomain, ntlmMsg.getDomain());
86         assertFalse("Minimal type 1 has workstation", ntlmMsg.hasWorkstation());
87         assertNull("Minimal type 1 workstation not null", ntlmMsg.getWorkstation());
88
89         // Test type 1 with workstation name only
90

91         ntlmMsg = new Type1NTLMMessage();
92         ntlmMsg.buildType1(0, null, testWks);
93         
94         assertTrue("Minimal type 1 message length wrong", ntlmMsg.getLength() > 16);
95         assertFalse("Minimal type 1 message domain supplied flag set", ntlmMsg.hasFlag(NTLM.FlagDomainSupplied));
96         assertTrue("Minimal type 1 message workstation supplied flag not set", ntlmMsg.hasFlag(NTLM.FlagWorkstationSupplied));
97         assertFalse("Minimal type 1 has domain", ntlmMsg.hasDomain());
98         assertNull("Minimal type 1 domain not null", ntlmMsg.getDomain());
99         assertTrue("Minimal type 1 no workstation", ntlmMsg.hasWorkstation());
100         assertEquals("Minimal type 1 workstation not correct", testWks, ntlmMsg.getWorkstation());
101         
102         // Test type 1 with domain name only with buffer
103

104         ntlmMsg = new Type1NTLMMessage(buf, 128, 128);
105         ntlmMsg.buildType1(0, null, testWks);
106
107         assertTrue("Minimal type 1 message length wrong", ntlmMsg.getLength() > 16);
108         assertFalse("Minimal type 1 message domain supplied flag set", ntlmMsg.hasFlag(NTLM.FlagDomainSupplied));
109         assertTrue("Minimal type 1 message workstation supplied flag not set", ntlmMsg.hasFlag(NTLM.FlagWorkstationSupplied));
110         assertFalse("Minimal type 1 has domain", ntlmMsg.hasDomain());
111         assertNull("Minimal type 1 domain not null", ntlmMsg.getDomain());
112         assertTrue("Minimal type 1 no workstation", ntlmMsg.hasWorkstation());
113         assertEquals("Minimal type 1 workstation not correct", testWks, ntlmMsg.getWorkstation());
114     
115         // Test type 1 with domain and workstation names
116

117         ntlmMsg = new Type1NTLMMessage();
118         ntlmMsg.buildType1(0, testDomain, testWks);
119         
120         assertTrue("Minimal type 1 message length wrong", ntlmMsg.getLength() > 16);
121         assertTrue("Minimal type 1 message domain supplied flag not set", ntlmMsg.hasFlag(NTLM.FlagDomainSupplied));
122         assertTrue("Minimal type 1 message workstation supplied flag not set", ntlmMsg.hasFlag(NTLM.FlagWorkstationSupplied));
123         assertTrue("Minimal type 1 has domain", ntlmMsg.hasDomain());
124         assertEquals("Minimal type 1 domain not correct", testDomain, ntlmMsg.getDomain());
125         assertTrue("Minimal type 1 no workstation", ntlmMsg.hasWorkstation());
126         assertEquals("Minimal type 1 workstation not correct", testWks, ntlmMsg.getWorkstation());
127         
128         // Test type 1 with domain and workstation names, with buffer
129

130         ntlmMsg = new Type1NTLMMessage(buf, 128, 128);
131         ntlmMsg.buildType1(0, testDomain, testWks);
132
133         assertTrue("Minimal type 1 message length wrong", ntlmMsg.getLength() > 16);
134         assertTrue("Minimal type 1 message domain supplied flag not set", ntlmMsg.hasFlag(NTLM.FlagDomainSupplied));
135         assertTrue("Minimal type 1 message workstation supplied flag not set", ntlmMsg.hasFlag(NTLM.FlagWorkstationSupplied));
136         assertTrue("Minimal type 1 has domain", ntlmMsg.hasDomain());
137         assertEquals("Minimal type 1 domain not correct", testDomain, ntlmMsg.getDomain());
138         assertTrue("Minimal type 1 no workstation", ntlmMsg.hasWorkstation());
139         assertEquals("Minimal type 1 workstation not correct", testWks, ntlmMsg.getWorkstation());
140     }
141     
142     /**
143      * Test type 2 message packing/unpacking
144      */

145     public void testType2Message()
146     {
147        // No tests yet, only receive type 2 from the server
148
}
149     
150     /**
151      * Test type 3 message packing/unpacking
152      */

153     public void testType3Message()
154     {
155         
156     }
157 }
158
Popular Tags