Fixed test launch
This commit is contained in:
parent
e0fd599c80
commit
43865106df
|
@ -48,7 +48,6 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(AccountingDataHarvesterPluginTest.class);
|
||||
|
||||
public static final String ROOT = "/d4science.research-infrastructures.eu";
|
||||
public static final String SO_BIG_VO = "/d4science.research-infrastructures.eu/SoBigData";
|
||||
|
||||
public static final String TAGME_VRE = "/d4science.research-infrastructures.eu/SoBigData/TagMe";
|
||||
|
|
|
@ -3,11 +3,17 @@
|
|||
*/
|
||||
package org.gcube.dataharvest.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||
import org.gcube.common.authorization.utils.secret.JWTSecret;
|
||||
import org.gcube.common.authorization.utils.secret.Secret;
|
||||
import org.gcube.common.keycloak.KeycloakClientFactory;
|
||||
import org.gcube.common.keycloak.model.TokenResponse;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
|
@ -16,11 +22,26 @@ import org.junit.BeforeClass;
|
|||
*/
|
||||
public class ContextTest {
|
||||
|
||||
protected static Properties properties;
|
||||
protected static final String PROPERTIES_FILENAME = "token.properties";
|
||||
public static final String ROOT = "/d4science.research-infrastructures.eu";
|
||||
|
||||
protected static final String CONFIG_PROPERTIES_FILENAME = "config.properties";
|
||||
|
||||
protected static ContextAuthorization contextAuthorization;
|
||||
|
||||
private static Properties getProperties(){
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(CONFIG_PROPERTIES_FILENAME);
|
||||
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
|
||||
return properties;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void set(Secret secret) throws Exception {
|
||||
SecretManagerProvider.instance.reset();
|
||||
SecretManager secretManager = new SecretManager();
|
||||
|
@ -30,17 +51,37 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
public static void set(String fullContextName) throws Exception {
|
||||
Secret secret = getSecretByContextName(fullContextName);
|
||||
Secret secret = getSecret(fullContextName);
|
||||
set(secret);
|
||||
}
|
||||
|
||||
private static Secret getSecretByContextName(String fullContextName) throws Exception {
|
||||
private static Secret getSecret(String fullContextName) throws Exception {
|
||||
return contextAuthorization.getSecretForContext(fullContextName);
|
||||
}
|
||||
|
||||
private static TokenResponse getJWTAccessToken(String context) throws Exception {
|
||||
ScopeProvider.instance.set(context);
|
||||
|
||||
int index = context.indexOf('/', 1);
|
||||
String root = context.substring(0, index == -1 ? context.length() : index);
|
||||
String clientSecret = getProperties().getProperty(root);
|
||||
|
||||
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(ContextAuthorization.CLIENT_ID, clientSecret, context, null);
|
||||
return tr;
|
||||
}
|
||||
|
||||
private static Secret generateSecretByContextName(String context) throws Exception {
|
||||
TokenResponse tr = getJWTAccessToken(context);
|
||||
Secret secret = new JWTSecret(tr.getAccessToken());
|
||||
return secret;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
Secret secret = generateSecretByContextName(ROOT);
|
||||
set(secret);
|
||||
contextAuthorization = new ContextAuthorization();
|
||||
SecretManagerProvider.instance.reset();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
|
Loading…
Reference in New Issue