improved tests
This commit is contained in:
parent
179013ec5b
commit
483826685c
|
@ -13,9 +13,8 @@ import org.gcube.common.authorization.utils.secret.JWTSecret;
|
|||
import org.gcube.common.authorization.utils.secret.Secret;
|
||||
import org.gcube.common.authorization.utils.secret.SecretUtility;
|
||||
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||
import org.gcube.common.keycloak.KeycloakClientHelper;
|
||||
import org.gcube.common.keycloak.model.TokenResponse;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -24,7 +23,6 @@ import org.slf4j.LoggerFactory;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ContextTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
|
||||
|
@ -40,17 +38,15 @@ public class ContextTest {
|
|||
public static final String NEXTNEXT;
|
||||
public static final String DEVSEC;
|
||||
public static final String DEVVRE;
|
||||
|
||||
|
||||
protected static final Properties properties;
|
||||
|
||||
protected static final String CLIENT_ID_PROPERTY_KEY = "client_id";
|
||||
protected static final String CLIENT_SECRET_PROPERTY_KEY = "client_secret";
|
||||
|
||||
protected static final String clientID;
|
||||
protected static final String clientSecret;
|
||||
public static final String TYPE_PROPERTY_KEY = "type";
|
||||
public static final String USERNAME_PROPERTY_KEY = "username";
|
||||
public static final String PASSWORD_PROPERTY_KEY = "password";
|
||||
public static final String CLIENT_ID_PROPERTY_KEY = "clientId";
|
||||
|
||||
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
|
||||
public static final String RESOURCE_REGISTRY_URL;
|
||||
|
||||
static {
|
||||
GCUBE = "/gcube";
|
||||
|
@ -59,7 +55,7 @@ public class ContextTest {
|
|||
DEVSEC = GCUBE + "/devsec";
|
||||
DEVVRE = DEVSEC + "/devVRE";
|
||||
|
||||
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
||||
PARENT_DEFAULT_TEST_SCOPE = GCUBE;
|
||||
DEFAULT_TEST_SCOPE = DEVNEXT;
|
||||
ALTERNATIVE_TEST_SCOPE = NEXTNEXT;
|
||||
|
||||
|
@ -68,18 +64,16 @@ public class ContextTest {
|
|||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
|
||||
clientID = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
|
||||
clientSecret = properties.getProperty(CLIENT_SECRET_PROPERTY_KEY);
|
||||
|
||||
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private enum Type{
|
||||
USER, CLIENT_ID
|
||||
};
|
||||
|
||||
public static void set(Secret secret) throws Exception {
|
||||
SecretManagerProvider.instance.reset();
|
||||
SecretManager secretManager = new SecretManager();
|
||||
|
@ -89,15 +83,56 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
public static void setContextByName(String fullContextName) throws Exception {
|
||||
logger.debug("Going to set credentials for context {}", fullContextName);
|
||||
Secret secret = getSecretByContextName(fullContextName);
|
||||
set(secret);
|
||||
}
|
||||
|
||||
|
||||
private static TokenResponse getJWTAccessToken(String context) throws Exception {
|
||||
ScopeProvider.instance.set(context);
|
||||
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
|
||||
return tr;
|
||||
Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString());
|
||||
|
||||
TokenResponse tr = null;
|
||||
|
||||
int index = context.indexOf('/', 1);
|
||||
String root = context.substring(0, index == -1 ? context.length() : index);
|
||||
|
||||
switch (type) {
|
||||
case CLIENT_ID:
|
||||
String clientId = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
|
||||
String clientSecret = properties.getProperty(root);
|
||||
|
||||
tr = KeycloakClientFactory.newInstance().queryUMAToken(context, clientId, clientSecret, context, null);
|
||||
break;
|
||||
|
||||
case USER:
|
||||
default:
|
||||
String username = properties.getProperty(USERNAME_PROPERTY_KEY);
|
||||
String password = properties.getProperty(PASSWORD_PROPERTY_KEY);
|
||||
|
||||
switch (root) {
|
||||
case "/gcube":
|
||||
default:
|
||||
clientId = "next.d4science.org";
|
||||
break;
|
||||
|
||||
case "/pred4s":
|
||||
clientId = "pre.d4science.org";
|
||||
break;
|
||||
|
||||
case "/d4science.research-infrastructures.eu":
|
||||
clientId = "services.d4science.org";
|
||||
break;
|
||||
}
|
||||
clientSecret = null;
|
||||
|
||||
tr = KeycloakClientHelper.getTokenForUser(context, username, password);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return tr;
|
||||
|
||||
}
|
||||
|
||||
public static Secret getSecretByContextName(String context) throws Exception {
|
||||
|
@ -117,7 +152,7 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
public static String getUser() {
|
||||
String user = Metadata.UNKNOWN_USER;
|
||||
String user = "UNKNOWN";
|
||||
try {
|
||||
user = SecretManagerProvider.instance.get().getUser().getUsername();
|
||||
} catch(Exception e) {
|
||||
|
|
|
@ -86,8 +86,9 @@ public class ERManagementTest extends ContextTest {
|
|||
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
||||
|
||||
public ERManagementTest() {
|
||||
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
|
||||
}else {
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
}
|
||||
|
@ -585,5 +586,11 @@ public class ERManagementTest extends ContextTest {
|
|||
// resourceManagement.update();
|
||||
//
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void testCreateResourceFromJson() throws Exception {
|
||||
// String json = "{\"type\":\"VirtualService\",\"consistsOf\":[{\"type\":\"IsIdentifiedBy\",\"target\":{\"name\":\"aaaaaa\",\"optional\":\"true\",\"group\":\"xxxxx\",\"description\":\"\",\"version\":\"cvcvvv\",\"qualifier\":\"\",\"type\":\"SoftwareFacet\",\"aaaa\":\"dddddd\"}}]}";
|
||||
// String ret = resourceRegistryPublisher.create(json);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -85,8 +85,9 @@ public class SmartgearResourcesTest extends ERManagementTest {
|
|||
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
||||
|
||||
public SmartgearResourcesTest() {
|
||||
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
|
||||
}else {
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
}
|
||||
|
|
|
@ -84,9 +84,10 @@ public class ERManagementTest extends ContextTest {
|
|||
protected ResourceRegistryClient resourceRegistryClient;
|
||||
|
||||
public ERManagementTest() {
|
||||
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
|
||||
resourceRegistryClient = new ResourceRegistryClientImpl(rrURLOBj.toString());
|
||||
}else {
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
|
|
|
@ -42,8 +42,9 @@ public class EntityManagementTest extends ContextTest {
|
|||
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
||||
|
||||
public EntityManagementTest(){
|
||||
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
|
||||
}else {
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
}
|
||||
|
|
|
@ -72,10 +72,10 @@ public class MultiContextTest extends ContextTest {
|
|||
protected ResourceRegistryClient resourceRegistryClient;
|
||||
|
||||
public MultiContextTest() throws Exception {
|
||||
// ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE);
|
||||
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
|
||||
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
|
||||
resourceRegistryClient = new ResourceRegistryClientImpl(rrURLOBj.toString());
|
||||
}else {
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
|
|
|
@ -1,7 +1,22 @@
|
|||
client_id=junit.tests.luca.frosini
|
||||
client_secret=6b0d0222-3130-41f1-a86d-6b23993547be
|
||||
#RESOURCE_REGISTRY_URL=http://localhost:8080/resource-registry
|
||||
#RESOURCE_REGISTRY_URL=http://pc-frosini.isti.cnr.it:8080/resource-registry
|
||||
#RESOURCE_REGISTRY_URL=http://resourceregistry1-d-d4s.d4science.org/resource-registry
|
||||
#RESOURCE_REGISTRY_URL=https://resource-registry.dev.d4science.org/resource-registry
|
||||
#RESOURCE_REGISTRY_URL=http://url.gcube.d4science.org/resource-registry
|
||||
type=USER
|
||||
#type=CLIENT_ID
|
||||
|
||||
username=luca.frosini
|
||||
password=Pupp4M3l0
|
||||
|
||||
#username=grsf.publisher
|
||||
#password=grsfcambiami
|
||||
|
||||
#clientId=grsf-publisher
|
||||
#/gcube=54cc7454-1a84-11ee-be56-0242ac120002
|
||||
#/pred4s=de293f60-e004-45ce-b64f-20de77fad888
|
||||
#/d4science.research-infrastructures.eu=
|
||||
|
||||
#client_id=junit.tests.luca.frosini
|
||||
#/gcube=6b0d0222-3130-41f1-a86d-6b23993547be
|
||||
|
||||
|
||||
#clientId=gcat
|
||||
#/gcube=712add63-c642-4a6a-8ddc-283dc978120a
|
||||
#/pred4s=4e35a122-8f25-48f9-9788-8588ee86633f
|
||||
#/d4science.research-infrastructures.eu=
|
Loading…
Reference in New Issue