Moved test code to authorization utils
This commit is contained in:
parent
b438820f86
commit
e8e29532fa
|
@ -7,14 +7,9 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.gcube.common.authorization.client.Constants;
|
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
import org.gcube.common.authorization.utils.secret.GCubeSecret;
|
||||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
import org.gcube.common.authorization.utils.secret.Secret;
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
|
||||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -58,37 +53,29 @@ public class ContextTest {
|
||||||
DEV_VRE = ALTERNATIVE_TEST_SCOPE;
|
DEV_VRE = ALTERNATIVE_TEST_SCOPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCurrentContextFullName() {
|
public static void set(Secret secret) throws Exception {
|
||||||
String token = SecurityTokenProvider.instance.get();
|
SecretManager.instance.get().reset();
|
||||||
AuthorizationEntry authorizationEntry = null;
|
secret.set();
|
||||||
try {
|
|
||||||
authorizationEntry = Constants.authorizationService().get(token);
|
|
||||||
} catch(Exception e) {
|
|
||||||
return ScopeProvider.instance.get();
|
|
||||||
}
|
|
||||||
return authorizationEntry.getContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getContextFullName(String token) throws ObjectNotFound, Exception {
|
public static void setContext(String token) throws Exception {
|
||||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
Secret secret = getSecret(token);
|
||||||
return authorizationEntry.getContext();
|
set(secret);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setContextByName(String fullContextName) throws Exception {
|
||||||
|
Secret secret = getSecretByContextName(fullContextName);
|
||||||
|
set(secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
|
private static Secret getSecret(String token) throws Exception {
|
||||||
|
GCubeSecret secret = new GCubeSecret(token);
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Secret getSecretByContextName(String fullContextName) throws Exception {
|
||||||
String token = ContextTest.properties.getProperty(fullContextName);
|
String token = ContextTest.properties.getProperty(fullContextName);
|
||||||
setContext(token);
|
return getSecret(token);
|
||||||
}
|
|
||||||
|
|
||||||
public static void setContext(String token) throws ObjectNotFound, Exception {
|
|
||||||
SecurityTokenProvider.instance.set(token);
|
|
||||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
|
||||||
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
|
||||||
String qualifier = authorizationEntry.getQualifier();
|
|
||||||
Caller caller = new Caller(clientInfo, qualifier);
|
|
||||||
AuthorizationProvider.instance.set(caller);
|
|
||||||
String contextFullNane = getContextFullName(token);
|
|
||||||
ScopeProvider.instance.set(contextFullNane);
|
|
||||||
logger.debug("Context: {} - User : {} - Type : {}", contextFullNane, clientInfo.getId(), clientInfo.getType().name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
|
@ -98,8 +85,7 @@ public class ContextTest {
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClass() throws Exception {
|
public static void afterClass() throws Exception {
|
||||||
SecurityTokenProvider.instance.reset();
|
SecretManager.instance.get().reset();
|
||||||
ScopeProvider.instance.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class CKANPackageTest extends ContextTest {
|
||||||
public void count() throws Exception {
|
public void count() throws Exception {
|
||||||
CKANPackage ckanPackage = new CKANPackage();
|
CKANPackage ckanPackage = new CKANPackage();
|
||||||
int count = ckanPackage.count();
|
int count = ckanPackage.count();
|
||||||
logger.debug("Number of items in {} is {}", ContextTest.getCurrentContextFullName(), count);
|
logger.debug("Number of items in {} is {}", SecretManager.instance.get().getContext(), count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue