Skip to content

Commit

Permalink
Integration tests now use tokens.
Browse files Browse the repository at this point in the history
  • Loading branch information
at88mph committed Sep 22, 2023
1 parent e409155 commit 19fcedd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 44 deletions.
1 change: 1 addition & 0 deletions opencadc.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ sourceSets {
}
resources.srcDir file('src/intTest/resources')
resources.srcDirs += new File(System.getenv('A') + '/test-certificates/')
resources.srcDirs += new File(System.getenv('A') + '/test-tokens/')
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
import ca.nrc.cadc.auth.AuthorizationToken;
import ca.nrc.cadc.net.HttpGet;
import ca.nrc.cadc.net.InputStreamWrapper;
import ca.nrc.cadc.net.NetUtil;
import ca.nrc.cadc.reg.client.RegistryClient;
import ca.nrc.cadc.util.FileUtil;
import ca.nrc.cadc.util.Log4jInit;
import ca.nrc.cadc.util.StringUtil;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Assert;
Expand All @@ -87,6 +87,7 @@
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.security.PrivilegedExceptionAction;
import java.util.Arrays;
import java.util.List;
Expand All @@ -106,27 +107,20 @@ public class GroupManagementIntTest {

protected URL groupMapperURL;
protected Subject userSubject;
protected String bearerToken = System.getenv("BEARER_TOKEN");

public GroupManagementIntTest() {
try {
RegistryClient regClient = new RegistryClient();
final String overrideTargetURL = System.getenv("POSIX_MAPPER_URL");
groupMapperURL = StringUtil.hasText(overrideTargetURL)
? new URL(overrideTargetURL + "/gid")
: regClient.getServiceURL(GroupManagementIntTest.POSIX_MAPPER_SERVICE_ID,
GroupManagementIntTest.GROUP_MAPPER_STANDARD_ID, AuthMethod.TOKEN);
log.info("User Mapping URL: " + groupMapperURL);

File cert = FileUtil.getFileFromResource("posix-mapper-test.pem", UserManagementIntTest.class);
userSubject = new Subject();
userSubject.getPublicCredentials().add(new AuthorizationToken("Bearer", bearerToken,
List.of("cadc.dao.nrc.ca")));
log.debug("userSubject: " + userSubject);
} catch (Exception e) {
log.error("init exception", e);
throw new RuntimeException("init exception", e);
}

public GroupManagementIntTest() throws Exception {
RegistryClient regClient = new RegistryClient();
groupMapperURL = regClient.getServiceURL(GroupManagementIntTest.POSIX_MAPPER_SERVICE_ID,
GroupManagementIntTest.GROUP_MAPPER_STANDARD_ID, AuthMethod.TOKEN);
log.info("Group Mapping URL: " + groupMapperURL);

File bearerTokenFile = FileUtil.getFileFromResource("posix-mapper-test.token",
UserManagementIntTest.class);
final String bearerToken = new String(Files.readAllBytes(bearerTokenFile.toPath()));
userSubject = new Subject();
userSubject.getPublicCredentials().add(
new AuthorizationToken("bearer", bearerToken, List.of(NetUtil.getDomainName(groupMapperURL))));
log.debug("userSubject: " + userSubject);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@
import ca.nrc.cadc.auth.AuthMethod;
import ca.nrc.cadc.auth.AuthorizationToken;
import ca.nrc.cadc.auth.NotAuthenticatedException;
import ca.nrc.cadc.auth.SSLUtil;
import ca.nrc.cadc.net.HttpGet;
import ca.nrc.cadc.net.HttpPost;
import ca.nrc.cadc.net.InputStreamWrapper;
import ca.nrc.cadc.net.NetUtil;
import ca.nrc.cadc.reg.client.RegistryClient;
import ca.nrc.cadc.util.FileUtil;
import ca.nrc.cadc.util.Log4jInit;
import ca.nrc.cadc.util.StringUtil;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
Expand All @@ -90,9 +91,10 @@
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

public class UserManagementIntTest {
Expand All @@ -109,27 +111,20 @@ public class UserManagementIntTest {

protected URL userMapperURL;
protected Subject userSubject;
protected String bearerToken = System.getenv("BEARER_TOKEN");

public UserManagementIntTest() {
try {
RegistryClient regClient = new RegistryClient();
final String overrideTargetURL = System.getenv("POSIX_MAPPER_URL");
userMapperURL = StringUtil.hasText(overrideTargetURL)
? new URL(overrideTargetURL + "/uid")
: regClient.getServiceURL(UserManagementIntTest.POSIX_MAPPER_SERVICE_ID,
UserManagementIntTest.USER_MAPPER_STANDARD_ID, AuthMethod.TOKEN);
log.info("User Mapping URL: " + userMapperURL);

File cert = FileUtil.getFileFromResource("posix-mapper-test.pem", UserManagementIntTest.class);
userSubject = new Subject();
userSubject.getPublicCredentials().add(new AuthorizationToken("Bearer", bearerToken,
List.of("cadc.dao.nrc.ca")));
log.debug("userSubject: " + userSubject);
} catch (Exception e) {
log.error("init exception", e);
throw new RuntimeException("init exception", e);
}
public UserManagementIntTest() throws Exception {
RegistryClient regClient = new RegistryClient();
userMapperURL = regClient.getServiceURL(UserManagementIntTest.POSIX_MAPPER_SERVICE_ID,
UserManagementIntTest.USER_MAPPER_STANDARD_ID, AuthMethod.TOKEN);
log.info("User Mapping URL: " + userMapperURL);

File bearerTokenFile = FileUtil.getFileFromResource("posix-mapper-test.token",
UserManagementIntTest.class);
final String bearerToken = new String(Files.readAllBytes(bearerTokenFile.toPath()));
userSubject = new Subject();
userSubject.getPublicCredentials().add(
new AuthorizationToken("bearer", bearerToken, List.of(NetUtil.getDomainName(userMapperURL))));
log.debug("userSubject: " + userSubject);
}

final String randomUsername() {
Expand Down

0 comments on commit 19fcedd

Please sign in to comment.