Fixed/added tests
This commit is contained in:
parent
0bd8b2fbf6
commit
6fcf847fdf
|
@ -55,8 +55,8 @@ public class ContextTest {
|
|||
DEVVRE = DEVSEC + "/devVRE";
|
||||
|
||||
PARENT_DEFAULT_TEST_SCOPE = GCUBE;
|
||||
DEFAULT_TEST_SCOPE = DEVNEXT;
|
||||
ALTERNATIVE_TEST_SCOPE = NEXTNEXT;
|
||||
DEFAULT_TEST_SCOPE = DEVSEC;
|
||||
ALTERNATIVE_TEST_SCOPE = DEVVRE;
|
||||
|
||||
properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(CONFIG_INI_FILENAME);
|
||||
|
@ -87,7 +87,6 @@ public class ContextTest {
|
|||
set(secret);
|
||||
}
|
||||
|
||||
|
||||
protected static String getJWTAccessToken(String context) throws Exception {
|
||||
Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString());
|
||||
|
||||
|
@ -119,7 +118,6 @@ public class ContextTest {
|
|||
|
||||
logger.trace("Generated Access Token is {}", accessToken);
|
||||
return accessToken;
|
||||
|
||||
}
|
||||
|
||||
public static Secret getSecretByContextName(String context) throws Exception {
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
package org.gcube.common.authorization.utils.manager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.common.authorization.utils.ContextTest;
|
||||
import org.gcube.common.authorization.utils.clientid.ClientIDManager;
|
||||
import org.gcube.common.authorization.utils.secret.JWTSecret;
|
||||
import org.gcube.common.authorization.utils.secret.Secret;
|
||||
import org.gcube.common.authorization.utils.user.User;
|
||||
import org.gcube.common.iam.D4ScienceIAMClient;
|
||||
import org.gcube.common.iam.D4ScienceIAMClientAuthn;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -41,4 +48,56 @@ public class SecretManagerTest extends ContextTest {
|
|||
String nameSurname = user.getFullName(true);
|
||||
logger.debug("{} - {} - {}", username, surnameName, nameSurname);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientIDManager() throws Exception {
|
||||
Properties properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(CONFIG_INI_FILENAME);
|
||||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
String context = DEFAULT_TEST_SCOPE;
|
||||
|
||||
int index = context.indexOf('/', 1);
|
||||
String root = context.substring(0, index == -1 ? context.length() : index);
|
||||
String clientId = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
|
||||
String clientSecret = properties.getProperty(root);
|
||||
|
||||
ClientIDManager clientIDManager = new ClientIDManager(clientId, clientSecret);
|
||||
Secret secret = clientIDManager.getSecret(context);
|
||||
Map<String, String> map = secret.getHTTPAuthorizationHeaders();
|
||||
logger.debug("{}", map);
|
||||
|
||||
map = clientIDManager.renew(context).getHTTPAuthorizationHeaders();
|
||||
logger.debug("{}", map);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshClientIDTokenTest() throws Exception {
|
||||
Properties properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(CONFIG_INI_FILENAME);
|
||||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
String context = DEFAULT_TEST_SCOPE;
|
||||
|
||||
int index = context.indexOf('/', 1);
|
||||
String root = context.substring(0, index == -1 ? context.length() : index);
|
||||
String clientId = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
|
||||
String clientSecret = properties.getProperty(root);
|
||||
|
||||
D4ScienceIAMClient iamClient = D4ScienceIAMClient.newInstance(context);
|
||||
D4ScienceIAMClientAuthn d4ScienceIAMClientAuthn = iamClient.authenticate(clientId, clientSecret, context);
|
||||
if(d4ScienceIAMClientAuthn!=null && d4ScienceIAMClientAuthn.canBeRefreshed()) {
|
||||
d4ScienceIAMClientAuthn.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue