Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ELY-2852-Refactor the ElytronXmlParserTest class to reduce repeated code #2240

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
Expand Down Expand Up @@ -113,58 +114,44 @@ private static void createClientKeyStore(KeyStore clientKeyStore) throws Excepti

@Test
public void testKeyStoreClearPassword() throws ConfigXMLParseException, URISyntaxException {
URL config = getClass().getResource("test-wildfly-config-v1_4.xml");
SecurityFactory<AuthenticationContext> authContext = ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI());
Assert.assertNotNull(authContext);
assertAuthContext("test-wildfly-config-v1_4.xml");
}

@Test
public void testKeyStoreMaskedPassword() throws Exception {
URL config = getClass().getResource("test-wildfly-config-v1_4.xml");
SecurityFactory<AuthenticationContext> authContext = ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI());
Assert.assertNotNull(authContext);
SecurityFactory<AuthenticationContext> authContext = assertAuthContext("test-wildfly-config-v1_4.xml");
RuleNode<SecurityFactory<SSLContext>> node = authContext.create().sslRuleMatching(new URI("http://masked/"), null, null);
Assert.assertNotNull(node);
Assert.assertNotNull(node.getConfiguration().create());
}

@Test
public void testKeyStoreEmptyType() throws ConfigXMLParseException, URISyntaxException {
URL config = getClass().getResource("test-wildfly-config-v1_4.xml");
SecurityFactory<AuthenticationContext> authContext = ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI());
Assert.assertNotNull(authContext);
assertAuthContext("test-wildfly-config-v1_4.xml");
}

@Test
public void testClearCredential() throws Exception {
URL config = getClass().getResource("test-wildfly-config-v1_4.xml");
SecurityFactory<AuthenticationContext> authContext = ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI());
Assert.assertNotNull(authContext);
RuleNode<AuthenticationConfiguration> node = authContext.create().authRuleMatching(new URI("http://clear/"), null, null);
Assert.assertNotNull(node);
SecurityFactory<AuthenticationContext> authContext = assertAuthContext("test-wildfly-config-v1_4.xml");
RuleNode<AuthenticationConfiguration> node = getNode(authContext, "http://clear/");
Password password = node.getConfiguration().getCredentialSource().getCredential(PasswordCredential.class).getPassword();
Assert.assertTrue(password instanceof ClearPassword);
Assert.assertEquals(new String(PASSWORD), new String(((ClearPassword)password).getPassword()));
}

@Test
public void testMaskedCredential() throws Exception {
URL config = getClass().getResource("test-wildfly-config-v1_4.xml");
SecurityFactory<AuthenticationContext> authContext = ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI());
Assert.assertNotNull(authContext);
RuleNode<AuthenticationConfiguration> node = authContext.create().authRuleMatching(new URI("http://masked/"), null, null);
Assert.assertNotNull(node);
SecurityFactory<AuthenticationContext> authContext = assertAuthContext("test-wildfly-config-v1_4.xml");
RuleNode<AuthenticationConfiguration> node = getNode(authContext, "http://masked/");
Password password = node.getConfiguration().getCredentialSource().getCredential(PasswordCredential.class).getPassword();
Assert.assertEquals(new String(PASSWORD), new String(((ClearPassword)password).getPassword()));
}


@Test
public void testWebservices() throws Exception {
URL config = getClass().getResource("test-wildfly-config-v1_5.xml");
SecurityFactory<AuthenticationContext> authContext = ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI());
Assert.assertNotNull(authContext);
RuleNode<AuthenticationConfiguration> node = authContext.create().authRuleMatching(new URI("http://webservices/"), null, null);
Assert.assertNotNull(node);
SecurityFactory<AuthenticationContext> authContext = assertAuthContext("test-wildfly-config-v1_5.xml");
RuleNode<AuthenticationConfiguration> node = getNode(authContext, "http://webservices/");
String wsHttpMechanism = node.getConfiguration().getWsHttpMechanism();
String wsSecurityType = node.getConfiguration().getWsSecurityType();
Assert.assertEquals("BASIC", wsHttpMechanism);
Expand All @@ -173,11 +160,8 @@ public void testWebservices() throws Exception {

@Test
public void testEmptyWebServices() throws Exception {
URL config = getClass().getResource("test-wildfly-config-v1_5.xml");
SecurityFactory<AuthenticationContext> authContext = ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI());
Assert.assertNotNull(authContext);
RuleNode<AuthenticationConfiguration> node = authContext.create().authRuleMatching(new URI("http://webservices-empty/"), null, null);
Assert.assertNotNull(node);
SecurityFactory<AuthenticationContext> authContext = assertAuthContext("test-wildfly-config-v1_5.xml");
RuleNode<AuthenticationConfiguration> node = getNode(authContext, "http://webservices-empty/");
String wsSecurityType = node.getConfiguration().getWsSecurityType();
String wsHttpMechanism = node.getConfiguration().getWsHttpMechanism();
Assert.assertNull(wsHttpMechanism);
Expand All @@ -186,9 +170,7 @@ public void testEmptyWebServices() throws Exception {

@Test
public void testCipherSuites() throws Exception {
URL config = getClass().getResource("test-wildfly-config-v1_5.xml");
SecurityFactory<AuthenticationContext> authContext = ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI());
Assert.assertNotNull(authContext);
SecurityFactory<AuthenticationContext> authContext = assertAuthContext("test-wildfly-config-v1_5.xml");
checkSSLContext(authContext, "http://both.org");
checkSSLContext(authContext, "http://selector-only.org");
checkSSLContext(authContext, "http://names-only.org");
Expand All @@ -200,6 +182,20 @@ private void checkSSLContext(SecurityFactory<AuthenticationContext> authContext,
Assert.assertNotNull(node.getConfiguration().create());
}

private SecurityFactory<AuthenticationContext> assertAuthContext(final String resource) throws ConfigXMLParseException, URISyntaxException {
URL config = getClass().getResource(resource);
SecurityFactory<AuthenticationContext> authContext = ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI());
Assert.assertNotNull(authContext);
return authContext;
}

private RuleNode<AuthenticationConfiguration> getNode(SecurityFactory<AuthenticationContext> authContext, String uri)
throws GeneralSecurityException, URISyntaxException {
RuleNode<AuthenticationConfiguration> node = authContext.create().authRuleMatching(new URI(uri), null, null);
Assert.assertNotNull(node);
return node;
}

@BeforeClass
public static void prepareKeyStores() throws Exception {
if (KEYSTORE_DIR.exists() == false) {
Expand Down
Loading