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-1529] one MockWebServer init per OAuth test for less often binding fails #1130

Merged
merged 1 commit into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;

import org.junit.After;
import org.junit.Before;
import okhttp3.mockwebserver.Dispatcher;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.wildfly.security.auth.client.AuthenticationConfiguration;
import org.wildfly.security.auth.client.AuthenticationContext;
Expand All @@ -59,34 +63,25 @@
import org.wildfly.security.sasl.util.AbstractSaslParticipant;
import org.wildfly.security.sasl.util.SaslMechanismInformation;
import org.wildfly.security.util.ByteIterator;
import okhttp3.mockwebserver.Dispatcher;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;


/**
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
*/
public class OAuth2SaslClientV10Test extends BaseTestCase {

private MockWebServer server;

@Before
public void onBefore() throws Exception {
System.setProperty("wildfly.config.url", getClass().getResource("wildfly-oauth2-test-config-v1_0.xml").toExternalForm());
server = new MockWebServer();
private static final MockWebServer server = new MockWebServer();

@BeforeClass
public static void onBefore() throws Exception {
System.setProperty("wildfly.config.url", OAuth2SaslClientV10Test.class.getResource("wildfly-oauth2-test-config-v1_0.xml").toExternalForm());
server.setDispatcher(createTokenEndpoint());

server.start(50831);
}

@After
public void onAfter() throws Exception {
if (server != null) {
server.shutdown();
}
@AfterClass
public static void onAfter() throws Exception {
server.shutdown();
}

@Test
Expand Down Expand Up @@ -448,7 +443,7 @@ private SecurityRealm createSecurityRealmMock() throws MalformedURLException {
return TokenSecurityRealm.builder().validator(JwtValidator.builder().build()).principalClaimName("preferred_username").build();
}

private Dispatcher createTokenEndpoint() {
private static Dispatcher createTokenEndpoint() {
return new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest recordedRequest) throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.security.Provider;
import java.security.Security;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -47,11 +48,13 @@
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;

import org.junit.Test;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.After;
import okhttp3.mockwebserver.Dispatcher;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.wildfly.security.WildFlyElytronProvider;
import org.wildfly.security.auth.client.AuthenticationConfiguration;
import org.wildfly.security.auth.client.AuthenticationContext;
Expand All @@ -68,19 +71,14 @@
import org.wildfly.security.sasl.util.AbstractSaslParticipant;
import org.wildfly.security.sasl.util.SaslMechanismInformation;
import org.wildfly.security.util.ByteIterator;
import okhttp3.mockwebserver.Dispatcher;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;


/**
* @author <a href="mailto:psilva@redhat.com">Pedro Igor</a>
*/
public class OAuth2SaslClientV11Test extends BaseTestCase {

private MockWebServer server;

private static final MockWebServer server = new MockWebServer();
private static final Provider provider = new WildFlyElytronProvider();

private static Map<String, String> stores = new HashMap<>();
Expand All @@ -89,7 +87,7 @@ public class OAuth2SaslClientV11Test extends BaseTestCase {
stores.put("ONE", BASE_STORE_DIRECTORY + "/oauth_test_ks.jceks");
}

public static void cleanCredentialStores() {
private static void cleanCredentialStores() {
File dir = new File(BASE_STORE_DIRECTORY);
dir.mkdirs();

Expand All @@ -110,28 +108,16 @@ public static void setUp() throws Exception {
.addPassword("goodPassAlias", "dont_tell_me")
.addPassword("badPassAlias", "bad_password")
.build();
}

@AfterClass
public static void tearDown() {
Security.removeProvider(provider.getName());
}

@Before
public void onBefore() throws Exception {
System.setProperty("wildfly.config.url", getClass().getResource("wildfly-oauth2-test-config-v1_1.xml").toExternalForm());
server = new MockWebServer();

System.setProperty("wildfly.config.url", OAuth2SaslClientV11Test.class.getResource("wildfly-oauth2-test-config-v1_1.xml").toExternalForm());
server.setDispatcher(createTokenEndpoint());

server.start(50831);
}

@After
public void onAfter() throws Exception {
if (server != null) {
server.shutdown();
}
@AfterClass
public static void tearDown() throws Exception {
server.shutdown();
Security.removeProvider(provider.getName());
}

@Test
Expand Down Expand Up @@ -588,7 +574,7 @@ private SecurityRealm createSecurityRealmMock() throws MalformedURLException {
return TokenSecurityRealm.builder().validator(JwtValidator.builder().build()).principalClaimName("preferred_username").build();
}

private Dispatcher createTokenEndpoint() {
private static Dispatcher createTokenEndpoint() {
return new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest recordedRequest) throws InterruptedException {
Expand Down Expand Up @@ -624,6 +610,6 @@ private SaslClient createSaslClientFromConfiguration(URI serverUri) throws SaslE
AuthenticationContext context = AuthenticationContext.getContextManager().get();
AuthenticationContextConfigurationClient contextConfigurationClient = AccessController.doPrivileged(AuthenticationContextConfigurationClient.ACTION);
AuthenticationConfiguration authenticationConfiguration = contextConfigurationClient.getAuthenticationConfiguration(serverUri, context);
return contextConfigurationClient.createSaslClient(serverUri, authenticationConfiguration, Arrays.asList(SaslMechanismInformation.Names.OAUTHBEARER));
return contextConfigurationClient.createSaslClient(serverUri, authenticationConfiguration, Collections.singletonList(SaslMechanismInformation.Names.OAUTHBEARER));
}
}