-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#360 - Create stress/load test which should cover all APIs with mocke…
…d OP
- Loading branch information
Showing
20 changed files
with
395 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
oxd-server/src/main/java/org/gluu/oxd/server/op/OpClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.gluu.oxd.server.op; | ||
|
||
import org.gluu.oxauth.client.*; | ||
import org.gluu.oxauth.model.jwt.Jwt; | ||
import org.gluu.oxd.server.service.PublicOpKeyService; | ||
|
||
public interface OpClientFactory { | ||
public TokenClient createTokenClient(String url); | ||
|
||
public UserInfoClient createUserInfoClient(String url); | ||
|
||
public RegisterClient createRegisterClient(String url); | ||
|
||
public OpenIdConfigurationClient createOpenIdConfigurationClient(String url); | ||
|
||
public AuthorizeClient createAuthorizeClient(String url); | ||
|
||
public Validator createValidator(Jwt idToken, OpenIdConfigurationResponse discoveryResponse, PublicOpKeyService keyService); | ||
} |
36 changes: 36 additions & 0 deletions
36
oxd-server/src/main/java/org/gluu/oxd/server/op/OpClientFactoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.gluu.oxd.server.op; | ||
|
||
import org.gluu.oxauth.client.*; | ||
import org.gluu.oxauth.model.jwt.Jwt; | ||
import org.gluu.oxd.server.service.PublicOpKeyService; | ||
|
||
public class OpClientFactoryImpl implements OpClientFactory { | ||
|
||
public OpClientFactoryImpl() { | ||
} | ||
|
||
public TokenClient createTokenClient(String url) { | ||
return new TokenClient(url); | ||
} | ||
|
||
public UserInfoClient createUserInfoClient(String url) { | ||
return new UserInfoClient(url); | ||
} | ||
|
||
public RegisterClient createRegisterClient(String url) { | ||
return new RegisterClient(url); | ||
} | ||
|
||
public OpenIdConfigurationClient createOpenIdConfigurationClient(String url) { | ||
return new OpenIdConfigurationClient(url); | ||
} | ||
|
||
public AuthorizeClient createAuthorizeClient(String url) { | ||
return new AuthorizeClient(url); | ||
} | ||
|
||
public Validator createValidator(Jwt idToken, OpenIdConfigurationResponse discoveryResponse, PublicOpKeyService keyService) { | ||
return new Validator(idToken, discoveryResponse, keyService); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
oxd-server/src/test/java/org/gluu/oxd/mock/AuthorizationCodeFlowTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package org.gluu.oxd.mock; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.base.Strings; | ||
import com.google.common.collect.Lists; | ||
import org.gluu.oxauth.model.common.GrantType; | ||
import org.gluu.oxd.client.ClientInterface; | ||
import org.gluu.oxd.client.GetTokensByCodeResponse2; | ||
import org.gluu.oxd.common.CoreUtils; | ||
import org.gluu.oxd.common.params.*; | ||
import org.gluu.oxd.common.response.GetLogoutUriResponse; | ||
import org.gluu.oxd.common.response.RegisterSiteResponse; | ||
import org.gluu.oxd.server.GetTokensByCodeTest; | ||
import org.gluu.oxd.server.RegisterSiteTest; | ||
import org.gluu.oxd.server.Tester; | ||
import org.testng.annotations.Parameters; | ||
import org.testng.annotations.Test; | ||
|
||
import java.net.URLEncoder; | ||
import java.util.UUID; | ||
|
||
import static junit.framework.Assert.assertNotNull; | ||
import static junit.framework.Assert.assertTrue; | ||
import static org.gluu.oxd.server.TestUtils.notEmpty; | ||
|
||
/** | ||
* @author Yuriy Zabrovarnyy | ||
* @version 0.9, 12/10/2015 | ||
*/ | ||
|
||
public class AuthorizationCodeFlowTest { | ||
|
||
@Parameters({"host", "opHost", "redirectUrls", "userId", "userSecret"}) | ||
@Test(enabled = false) | ||
public void mockTest(String host, String opHost, String redirectUrls, String userId, String userSecret) { | ||
ClientInterface client = Tester.newClient(host); | ||
//Register client | ||
final RegisterSiteResponse site = registerSite(client, opHost, redirectUrls); | ||
//Get Token by code | ||
final GetTokensByCodeResponse2 tokens = requestTokens(client, site, userId, userSecret); | ||
//Get User Info | ||
GetUserInfoParams params = new GetUserInfoParams(); | ||
params.setOxdId(site.getOxdId()); | ||
params.setAccessToken(tokens.getAccessToken()); | ||
|
||
final JsonNode resp = client.getUserInfo(Tester.getAuthorization(), params); | ||
assertNotNull(resp); | ||
assertNotNull(resp.get("sub")); | ||
|
||
//Get Logout Url | ||
getLogoutUrl(client, site, redirectUrls); | ||
|
||
} | ||
public static RegisterSiteResponse registerSite(ClientInterface client, String opHost, String redirectUrls) { | ||
return registerSite(client, opHost, redirectUrls, redirectUrls, ""); | ||
} | ||
|
||
public static RegisterSiteResponse registerSite(ClientInterface client, String opHost, String redirectUrls, String postLogoutRedirectUrls, String logoutUri) { | ||
|
||
final RegisterSiteParams params = new RegisterSiteParams(); | ||
params.setOpHost(opHost); | ||
params.setPostLogoutRedirectUris(Lists.newArrayList(postLogoutRedirectUrls.split(" "))); | ||
params.setClientFrontchannelLogoutUris(Lists.newArrayList(logoutUri)); | ||
params.setRedirectUris(Lists.newArrayList(redirectUrls.split(" "))); | ||
params.setScope(Lists.newArrayList("openid", "uma_protection", "profile")); | ||
params.setTrustedClient(true); | ||
params.setGrantTypes(Lists.newArrayList( | ||
GrantType.AUTHORIZATION_CODE.getValue(), | ||
GrantType.OXAUTH_UMA_TICKET.getValue(), | ||
GrantType.CLIENT_CREDENTIALS.getValue())); | ||
|
||
final RegisterSiteResponse resp = client.registerSite(params); | ||
//assertNotNull(resp); | ||
//assertTrue(!Strings.isNullOrEmpty(resp.getOxdId())); | ||
return resp; | ||
} | ||
private GetTokensByCodeResponse2 requestTokens(ClientInterface client, RegisterSiteResponse site, String userId, String userSecret) { | ||
|
||
final String state = CoreUtils.secureRandomString(); | ||
final String nonce = "rrsenukn8h9hjmscjf5gq9i5tu"; | ||
|
||
final GetTokensByCodeParams params = new GetTokensByCodeParams(); | ||
params.setOxdId(site.getOxdId()); | ||
params.setCode(codeRequest(client, site.getOxdId(), userId, userSecret, state, nonce)); | ||
params.setState(state); | ||
|
||
final GetTokensByCodeResponse2 resp = client.getTokenByCode(Tester.getAuthorization(), params); | ||
assertNotNull(resp); | ||
notEmpty(resp.getAccessToken()); | ||
notEmpty(resp.getIdToken()); | ||
return resp; | ||
} | ||
|
||
public static String codeRequest(ClientInterface client, String siteId, String userId, String userSecret, String state, String nonce) { | ||
GetAuthorizationCodeParams params = new GetAuthorizationCodeParams(); | ||
params.setOxdId(siteId); | ||
params.setUsername(userId); | ||
params.setPassword(userSecret); | ||
params.setState(state); | ||
params.setNonce(nonce); | ||
|
||
return client.getAuthorizationCode(Tester.getAuthorization(), params).getCode(); | ||
} | ||
|
||
public static void getLogoutUrl(ClientInterface client, RegisterSiteResponse site, String postLogoutRedirectUrl) { | ||
final GetLogoutUrlParams logoutParams = new GetLogoutUrlParams(); | ||
logoutParams.setOxdId(site.getOxdId()); | ||
logoutParams.setIdTokenHint("dummy_token"); | ||
logoutParams.setPostLogoutRedirectUri(postLogoutRedirectUrl); | ||
logoutParams.setState(UUID.randomUUID().toString()); | ||
logoutParams.setSessionState(UUID.randomUUID().toString()); // here must be real session instead of dummy UUID | ||
|
||
final GetLogoutUriResponse resp = client.getLogoutUri(Tester.getAuthorization(), logoutParams); | ||
assertNotNull(resp); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
oxd-server/src/test/java/org/gluu/oxd/mock/guice/MockAppModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.gluu.oxd.mock.guice; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Singleton; | ||
import org.gluu.oxd.mock.service.OpClientFactoryMockImpl; | ||
import org.gluu.oxd.server.OxdServerConfiguration; | ||
import org.gluu.oxd.server.op.OpClientFactory; | ||
import org.gluu.oxd.server.persistence.H2PersistenceProvider; | ||
import org.gluu.oxd.server.persistence.PersistenceService; | ||
import org.gluu.oxd.server.persistence.PersistenceServiceImpl; | ||
import org.gluu.oxd.server.persistence.SqlPersistenceProvider; | ||
import org.gluu.oxd.server.service.*; | ||
|
||
public class MockAppModule extends AbstractModule { | ||
|
||
@Override | ||
protected void configure() { | ||
bind(OxdServerConfiguration.class).toProvider(ConfigurationService.class); | ||
|
||
bind(ConfigurationService.class).in(Singleton.class); | ||
bind(PublicOpKeyService.class).in(Singleton.class); | ||
bind(RpService.class).in(Singleton.class); | ||
bind(HttpService.class).in(Singleton.class); | ||
bind(IntrospectionService.class).in(Singleton.class); | ||
bind(SqlPersistenceProvider.class).to(H2PersistenceProvider.class).in(Singleton.class); | ||
bind(PersistenceService.class).to(PersistenceServiceImpl.class).in(Singleton.class); | ||
bind(MigrationService.class).in(Singleton.class); | ||
bind(DiscoveryService.class).in(Singleton.class); | ||
bind(ValidationService.class).in(Singleton.class); | ||
bind(StateService.class).in(Singleton.class); | ||
bind(OpClientFactory.class).to(OpClientFactoryMockImpl.class).in(Singleton.class); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
oxd-server/src/test/java/org/gluu/oxd/mock/listener/EnableMocksListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.gluu.oxd.mock.listener; | ||
|
||
import org.testng.IAnnotationTransformer; | ||
import org.testng.ITest; | ||
import org.testng.annotations.ITestAnnotation; | ||
import org.testng.annotations.Parameters; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Method; | ||
|
||
public class EnableMocksListener implements IAnnotationTransformer { | ||
|
||
@Override | ||
public void transform(ITestAnnotation annotation, Class testClass, | ||
Constructor testConstructor, Method testMethod){ | ||
|
||
System.out.println("===============>"+testMethod.getName()); | ||
System.out.println("***************>"+isTestDisabled(testMethod.getName())); | ||
if (isTestDisabled(testMethod.getName())) { | ||
annotation.setEnabled(false); | ||
} else { | ||
annotation.setEnabled(true); | ||
} | ||
} | ||
|
||
public boolean isTestDisabled(String testName){ | ||
if(testName.startsWith("mock")) { | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.