01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.protocol.http.control;
20:
21: import java.net.URL;
22:
23: import org.apache.jmeter.junit.JMeterTestCase;
24: import org.apache.jmeter.testelement.property.CollectionProperty;
25:
26: public class TestAuthManager extends JMeterTestCase {
27: public TestAuthManager(String name) {
28: super (name);
29: }
30:
31: public void testHttp() throws Exception {
32: assertTrue(AuthManager.isSupportedProtocol(new URL("http:")));
33: }
34:
35: public void testHttps() throws Exception {
36: assertTrue(AuthManager.isSupportedProtocol(new URL("https:")));
37: }
38:
39: public void testFile() throws Exception {
40: AuthManager am = new AuthManager();
41: CollectionProperty ao = am.getAuthObjects();
42: assertEquals(0, ao.size());
43: am.addFile("testfiles/TestAuth.txt");
44: assertEquals(9, ao.size());
45: Authorization at;
46: at = am.getAuthForURL(new URL("http://a.b.c/"));
47: assertEquals("login", at.getUser());
48: assertEquals("password", at.getPass());
49: at = am.getAuthForURL(new URL("http://a.b.c:80/")); // same as above
50: assertEquals("login", at.getUser());
51: assertEquals("password", at.getPass());
52: at = am.getAuthForURL(new URL("http://a.b.c:443/"));// not same
53: assertNull(at);
54: at = am.getAuthForURL(new URL("http://a.b.c/1"));
55: assertEquals("login1", at.getUser());
56: assertEquals("password1", at.getPass());
57: assertEquals("", at.getDomain());
58: assertEquals("", at.getRealm());
59: at = am.getAuthForURL(new URL("http://d.e.f/"));
60: assertEquals("user", at.getUser());
61: assertEquals("pass", at.getPass());
62: assertEquals("domain", at.getDomain());
63: assertEquals("realm", at.getRealm());
64: at = am.getAuthForURL(new URL("https://j.k.l/"));
65: assertEquals("jkl", at.getUser());
66: assertEquals("pass", at.getPass());
67: at = am.getAuthForURL(new URL("https://j.k.l:443/"));
68: assertEquals("jkl", at.getUser());
69: assertEquals("pass", at.getPass());
70: at = am.getAuthForURL(new URL("https://l.m.n/"));
71: assertEquals("lmn443", at.getUser());
72: assertEquals("pass", at.getPass());
73: at = am.getAuthForURL(new URL("https://l.m.n:443/"));
74: assertEquals("lmn443", at.getUser());
75: assertEquals("pass", at.getPass());
76: at = am.getAuthForURL(new URL("https://l.m.n:8443/"));
77: assertEquals("lmn8443", at.getUser());
78: assertEquals("pass", at.getPass());
79: }
80: }
|