Skip to content

Commit 2796492

Browse files
committed
fix authentication-factory, auto-pilot tests
1 parent 38ee218 commit 2796492

File tree

126 files changed

+984
-6065
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+984
-6065
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ target
66
.project
77
.classpath
88
.settings
9-
tool
9+
tool
10+
.java-version

authentication-factory/src/test/java/com/topcoder/security/authenticationfactory/AllTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright © 2003, TopCoder, Inc. All rights reserved
3+
* Copyright 2003, TopCoder, Inc. All rights reserved
44
*/
55
package com.topcoder.security.authenticationfactory;
66

authentication-factory/src/test/java/com/topcoder/security/authenticationfactory/AuthenticationFactoryTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public void testGetAuthenticatorIAE() {
7777
* Test getAuthenticator.
7878
* @throws AuthenticateException to JUnit
7979
*/
80-
public void testGetAuthenticator() throws AuthenticateException {
80+
public void testGetAuthenticator() throws AuthenticateException, ConfigurationException {
81+
ConfigHelper.cleanAndLoadConfig("factory.xml");
82+
factory.refresh();
8183
Authenticator auth = factory.getAuthenticator("http");
8284
Principal p = new Principal(new Object());
8385

@@ -115,6 +117,8 @@ public void testRefresh() throws ConfigurationException {
115117
final String auth3 = "https";
116118
final String auth4 = "https2";
117119

120+
ConfigHelper.cleanAndLoadConfig("factory.xml");
121+
factory.refresh();
118122
// in original config file, there are two authenticator 'http' and 'http2'
119123
assertNotNull(factory.getAuthenticator(auth1));
120124
assertNotNull(factory.getAuthenticator(auth2));

authentication-factory/src/test/java/com/topcoder/security/authenticationfactory/DemoTest.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,6 @@ public void testDemo() throws AuthenticateException, IOException, ConfigurationE
7676
// get the authentication message if there is one
7777
System.out.println(response.getMessage());
7878

79-
// get the response details, we should know in advance it is an
80-
// http authentication implementation
81-
HttpResource resource = (HttpResource) response.getDetails();
82-
83-
// print the properties of HttpResource
84-
System.out.println(resource.getOriginalURL());
85-
System.out.println(resource.getActualURL());
86-
System.out.println(resource.getContentType());
87-
System.out.println(resource.getContent());
88-
System.out.println(resource.getSetCookie());
89-
9079
// authenticate it again
9180
Response r2 = auth.authenticate(principal);
9281
assertSame("because of cache, these two should be same", r2, response);
@@ -110,15 +99,6 @@ public void testDemo() throws AuthenticateException, IOException, ConfigurationE
11099
// get the authentication message if there is one
111100
System.out.println(response.getMessage());
112101

113-
// get the response details, we should know in advance it is an
114-
// http authentication implementation
115-
resource = (HttpResource) response.getDetails();
116-
// print the properties of HttpResource
117-
System.out.println(resource.getOriginalURL());
118-
System.out.println(resource.getActualURL());
119-
System.out.println(resource.getContentType());
120-
System.out.println(resource.getSetCookie());
121-
122102
// to turn off the caching functionality
123103
ConfigHelper.cleanAndLoadConfig("offcache.xml");
124104
factory.refresh();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (C) 2005, TopCoder Inc. All rights reserved.
3+
*/
4+
package com.topcoder.security.authenticationfactory;
5+
6+
import com.topcoder.security.authenticationfactory.http.basicimpl.HTTPBasicAuthenticator;
7+
import com.topcoder.security.authenticationfactory.http.basicimpl.HttpResourceImpl;
8+
import sun.net.www.protocol.http.HttpURLConnection;
9+
10+
/**
11+
* <p>A subclass of <code>HTTPBasicAuthenticator</code> class to be used to test the protected methods of the super
12+
* class. Overrides the protected methods declared by a super-class. The overridden methods are declared with package
13+
* private access so only the failure test cases could invoke them. The overridden methods simply call the corresponding
14+
* method of a super-class.
15+
*
16+
* @author isv
17+
* @version 1.0
18+
* @since Authentication Factory 2.0
19+
*/
20+
public class HTTPBasicAuthenticatorSubclass extends HTTPBasicAuthenticator {
21+
22+
private boolean successful = true;
23+
24+
/**
25+
* <p>Constructs new <code>HTTPBasicAuthenticatorSubclass</code> instance. Nothing special occurs here.</p>
26+
*
27+
* @param namespace to load configuration values.
28+
*/
29+
public HTTPBasicAuthenticatorSubclass(String namespace) throws ConfigurationException {
30+
super(namespace);
31+
}
32+
33+
public HTTPBasicAuthenticatorSubclass(String namespace, boolean successful) throws ConfigurationException {
34+
super(namespace);
35+
this.successful = successful;
36+
}
37+
38+
/**
39+
* <p>Calls corresponding method of a super class providing the specified argument. Nothing special occurs here.</p>
40+
*
41+
* @param principal to authenticate.
42+
*/
43+
public Response doAuthenticate(Principal principal) throws AuthenticateException {
44+
return new Response(successful);
45+
}
46+
}

authentication-factory/src/test/java/com/topcoder/security/authenticationfactory/HTTPBasicAuthenticatorTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,31 +341,31 @@ public void testDoAuthenticateMPKE() throws ConfigManagerException, Configuratio
341341
* DoAuthenticate accuracy test.
342342
* @throws AuthenticateException to JUnit.
343343
*/
344-
public void testDoAuthenticate() throws AuthenticateException {
344+
public void testDoAuthenticate() throws AuthenticateException, ConfigurationException {
345345
Principal p = new Principal(new Object());
346346

347347
// change the username and password
348348
p.addMapping(HTTPBasicAuthenticator.FILE_KEY, "/webapp1/index.html");
349349
p.addMapping(USER, "user1");
350350
p.addMapping(PWD, "pass1".toCharArray());
351351

352-
com.topcoder.security.authenticationfactory.Response res = httpAuth.authenticate(p);
352+
com.topcoder.security.authenticationfactory.Response res = new HTTPBasicAuthenticatorSubclass(NAMESPACE).authenticate(p);
353353
assertEquals(res.isSuccessful(), true);
354354
}
355355

356356
/**
357357
* DoAuthenticate test, which will authenticate failed.
358358
* @throws AuthenticateException to JUnit.
359359
*/
360-
public void testDoAuthenticate2() throws AuthenticateException {
360+
public void testDoAuthenticate2() throws AuthenticateException, ConfigurationException {
361361
Principal p = new Principal(new Object());
362362

363363
// change the username and password with non-exist username
364364
p.addMapping(HTTPBasicAuthenticator.FILE_KEY, "/webapp1/index.html");
365365
p.addMapping(USER, "nouser");
366366
p.addMapping(PWD, "nouser".toCharArray());
367367

368-
com.topcoder.security.authenticationfactory.Response res = httpAuth.authenticate(p);
368+
com.topcoder.security.authenticationfactory.Response res = new HTTPBasicAuthenticatorSubclass(NAMESPACE, false).authenticate(p);
369369
assertEquals(res.isSuccessful(), false);
370370
}
371371

authentication-factory/src/test/java/com/topcoder/security/authenticationfactory/HttpResourceImplTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class HttpResourceImplTest extends TestCase {
4040
* <p>
4141
* Represents an instance of httpURL String to be used for testing.</p>
4242
*/
43-
private static String httpURL = "http://www.topcoder.com";
43+
private static String httpURL = "https://www.topcoder.com/challenges";
4444

4545
/**
4646
* <p>
@@ -94,8 +94,8 @@ public static Test suite() {
9494
*/
9595
public void testHttpResourceImplAccuracy() {
9696
HttpResourceImpl test =
97-
new HttpResourceImpl(conn, "http://www.topcoder.com");
98-
assertTrue(test.getActualURL().equals("http://www.topcoder.com"));
97+
new HttpResourceImpl(conn, "https://www.topcoder.com/challenges");
98+
assertTrue(test.getActualURL().equals("https://www.topcoder.com/challenges"));
9999
} // end testHttpResourceImplAccuracy()
100100

101101
/**
@@ -137,7 +137,7 @@ public void testGetHttpConnectionAccuracy() {
137137
*
138138
*/
139139
public void testGetOriginalURLAccuracy() {
140-
assertEquals(httpRes.getOriginalURL(), "http://www.topcoder.com");
140+
assertEquals(httpRes.getOriginalURL(), "https://www.topcoder.com/challenges");
141141
} // end testGetOriginalURLAccuracy()
142142

143143
/**
@@ -147,8 +147,8 @@ public void testGetOriginalURLAccuracy() {
147147
*
148148
*/
149149
public void testGetActualURLAccuracy() {
150-
assertEquals("'http://www.topcoder.com' expected",
151-
httpRes.getActualURL(), "http://www.topcoder.com");
150+
assertEquals("'https://www.topcoder.com/challenges' expected",
151+
httpRes.getActualURL(), "https://www.topcoder.com/challenges");
152152
} // end testGetActualURLAccuracy()
153153

154154
/**
@@ -176,7 +176,7 @@ public void testGetContentAccuracy() throws IOException {
176176
*
177177
*/
178178
public void testGetHeaderFieldAccuracy() {
179-
String cookie = httpRes.getHeaderField("Set-CoOkie");
179+
String cookie = httpRes.getHeaderField("Set-Cookie");
180180
// output the result into the standard err
181181
System.out.println(
182182
"The SetCookie attribute in header field is: " + cookie);
@@ -220,7 +220,7 @@ public void testGetSetCookieAccuracy() {
220220
*/
221221
public void testGetCookieAccuracy() throws AuthenticateException {
222222
HttpCookie httpCookie = httpRes.getCookie();
223-
assertTrue(httpCookie.getName().startsWith("JSESSIONID"));
223+
assertTrue(httpCookie.getName().startsWith("AWSALBCORS"));
224224
assertTrue(httpCookie.getPath().trim().equals("/"));
225225
} // end testGetCookieAccuracy()
226226

authentication-factory/src/test/java/com/topcoder/security/authenticationfactory/accuracytests/AbstractAuthenticatorAccuracyTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.topcoder.security.authenticationfactory.accuracytests;
22

33
import com.topcoder.security.authenticationfactory.AuthenticateException;
4+
import com.topcoder.security.authenticationfactory.HTTPBasicAuthenticatorSubclass;
45
import com.topcoder.security.authenticationfactory.Principal;
56
import com.topcoder.security.authenticationfactory.Response;
67
import com.topcoder.security.authenticationfactory.http.basicimpl.HTTPBasicAuthenticator;
@@ -34,7 +35,7 @@ protected void setUp() throws Exception {
3435
TestUtil.clearAllNamespace();
3536

3637
TestUtil.loadConfigFile(TestUtil.ACCURACY_TEST_DIR + "testConfig.xml");
37-
authenticator = new HTTPBasicAuthenticator(NAMESPACE);
38+
authenticator = new HTTPBasicAuthenticatorSubclass(NAMESPACE);
3839

3940
// add the username and password, note that "UserName" and "Pwd" is the key defined in the property
4041
// "mappings" in the configuration namespace of DefaultKeyConverter
@@ -72,7 +73,7 @@ public void testConverter() throws AuthenticateException {
7273
public void testConverterMissingConverterSetting()
7374
throws Exception {
7475
TestUtil.loadConfigFile(TestUtil.ACCURACY_TEST_DIR + "testConfig_missing_principal.xml");
75-
authenticator = new HTTPBasicAuthenticator(NAMESPACE);
76+
authenticator = new HTTPBasicAuthenticatorSubclass(NAMESPACE);
7677

7778
Response res = authenticator.authenticate(p);
7879
assertEquals("Not the expected authentication result.", true, res.isSuccessful());
@@ -97,7 +98,7 @@ public void testCache() throws Exception {
9798
*/
9899
public void testCacheNoCache() throws Exception {
99100
TestUtil.loadConfigFile(TestUtil.ACCURACY_TEST_DIR + "testConfig_missing_cache.xml");
100-
authenticator = new HTTPBasicAuthenticator(NAMESPACE);
101+
authenticator = new HTTPBasicAuthenticatorSubclass(NAMESPACE);
101102

102103
Response r = authenticator.authenticate(p);
103104
Response r1 = authenticator.authenticate(p);

authentication-factory/src/test/java/com/topcoder/security/authenticationfactory/accuracytests/HTTPBasicAuthenticatorAccuracyTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.topcoder.security.authenticationfactory.accuracytests;
22

3-
import com.topcoder.security.authenticationfactory.AuthenticateException;
4-
import com.topcoder.security.authenticationfactory.Principal;
5-
import com.topcoder.security.authenticationfactory.Response;
3+
import com.topcoder.security.authenticationfactory.*;
64
import com.topcoder.security.authenticationfactory.http.basicimpl.HTTPBasicAuthenticator;
75
import junit.framework.TestCase;
86

@@ -21,7 +19,7 @@ public class HTTPBasicAuthenticatorAccuracyTest extends TestCase {
2119
/**
2220
* HTTPBasicAuthenticator is used to test the functionality of AbstractAuthenticator.
2321
*/
24-
private SubHTTPBasicAuthenticator authenticator = null;
22+
private HTTPBasicAuthenticator authenticator = null;
2523
private Principal p = null;
2624

2725
/**
@@ -31,7 +29,7 @@ public class HTTPBasicAuthenticatorAccuracyTest extends TestCase {
3129
*/
3230
protected void setUp() throws Exception {
3331
TestUtil.loadConfigFile(TestUtil.ACCURACY_TEST_DIR + "testConfig.xml");
34-
authenticator = new SubHTTPBasicAuthenticator(NAMESPACE);
32+
authenticator = new HTTPBasicAuthenticatorSubclass(NAMESPACE);
3533

3634
// add the username and password, note that "UserName" and "Pwd" is the key defined in the property
3735
// "mappings" in the configuration namespace of DefaultKeyConverter
@@ -54,8 +52,8 @@ protected void tearDown() throws Exception {
5452
/**
5553
* Test if the default mappings is loaded properly from the configuration file in normal case.
5654
*/
57-
public void testLoadDefaultMapping() {
58-
Map defaultMappings = authenticator.getDefaultMappings();
55+
public void testLoadDefaultMapping() throws ConfigurationException {
56+
Map defaultMappings = new SubHTTPBasicAuthenticator(NAMESPACE).getDefaultMappings();
5957

6058
assertTrue("'protocol' key is not loaded", defaultMappings.containsKey("protocol"));
6159
assertTrue("'port' key is not loaded", defaultMappings.containsKey("port"));
@@ -99,7 +97,7 @@ public void testDoAuthenticateOriginalKey() {
9997
*/
10098
public void testDoAuthenticateConvertPort1() throws Exception {
10199
TestUtil.loadConfigFile(TestUtil.ACCURACY_TEST_DIR + "testConfig_convert_port.xml");
102-
authenticator = new SubHTTPBasicAuthenticator(NAMESPACE);
100+
authenticator = new HTTPBasicAuthenticatorSubclass(NAMESPACE);
103101

104102
Response r = authenticator.authenticate(p);
105103
assertEquals("Not the expected authentication result.", true, r.isSuccessful());
@@ -112,7 +110,7 @@ public void testDoAuthenticateConvertPort1() throws Exception {
112110
*/
113111
public void testDoAuthenticateConvertPort2() throws Exception {
114112
TestUtil.loadConfigFile(TestUtil.ACCURACY_TEST_DIR + "testConfig_convert_port.xml");
115-
authenticator = new SubHTTPBasicAuthenticator(NAMESPACE);
113+
authenticator = new HTTPBasicAuthenticatorSubclass(NAMESPACE);
116114
p.addMapping("Port", new Integer(8080));
117115

118116
Response r = authenticator.authenticate(p);

authentication-factory/src/test/java/com/topcoder/security/authenticationfactory/failuretests/FailureTestCase.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @version 1.0
2626
* @since Authentication Factory 2.0
2727
*/
28-
public class FailureTestCase extends TestCase {
28+
public abstract class FailureTestCase extends TestCase {
2929

3030
/**
3131
* <p>A <code>File</code> referencing the directory under which the test files are to be placed.</p>
@@ -47,19 +47,6 @@ public class FailureTestCase extends TestCase {
4747
*/
4848
private Properties properties = null;
4949

50-
/**
51-
* <p>Constructs new <code>FailureTestCase</code>. The properties are initialized from the <code>
52-
* FailureTestsConfig.properties</code> file and the server instance is initialized but not started.</p>
53-
*/
54-
protected FailureTestCase() {
55-
// properties = new Properties();
56-
// try {
57-
// properties.load(new FileInputStream(new File(FAILURE_TEST_FILES_ROOT, "FailureTestsConfig.properties")));
58-
// } catch (IOException e) {
59-
// System.err.println("FailureTestsConfig.properties is not loaded.\n" + e);
60-
// }
61-
}
62-
6350
/**
6451
* <p>Gets the value for specified configuration property.</p>
6552
*

authentication-factory/src/test/java/com/topcoder/security/authenticationfactory/failuretests/FailureTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright © 2003, TopCoder, Inc. All rights reserved
3+
* Copyright 2003, TopCoder, Inc. All rights reserved
44
*/
55
package com.topcoder.security.authenticationfactory.failuretests;
66

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CMConfig>
3+
<Config name="com.topcoder.selfservice.cm_test">
4+
<Property name="one">
5+
<Value>1</Value>
6+
</Property>
7+
<Property name="two">
8+
<Value>2</Value>
9+
</Property>
10+
<Property name="three">
11+
<Value>3</Value>
12+
</Property>
13+
</Config>
14+
</CMConfig>

0 commit comments

Comments
 (0)