Skip to content

Commit

Permalink
Merge pull request #53 from pdowler/main
Browse files Browse the repository at this point in the history
improve int-test so they can be run vs CADC deployment
  • Loading branch information
pdowler authored Oct 2, 2024
2 parents 90bc698 + 8fd7ae8 commit 2cd5cae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cred/src/intTest/java/org/opencadc/cred/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
package org.opencadc.cred;

import java.net.URI;
import org.apache.log4j.Logger;

/**
*
Expand All @@ -77,6 +76,7 @@
public class Constants {

public static final URI RESOURCE_IDENTIFIER = URI.create("ivo://opencadc.org/cred");
//public static final URI RESOURCE_IDENTIFIER = URI.create("ivo://cadc.nrc.ca/cred");

public Constants() {
}
Expand Down
32 changes: 10 additions & 22 deletions cred/src/intTest/java/org/opencadc/cred/GetCertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,28 +381,14 @@ public void testRenewWithCertFail() throws Exception {
RegistryClient reg = new RegistryClient();
URL credUrl = reg.getServiceURL(Constants.RESOURCE_IDENTIFIER, Standards.CRED_PROXY_10, AuthMethod.TOKEN);

float daysValid = 3; // 3 days cert
URL credDaysValidURL = new URL(credUrl.toString() + "?daysValid=" + daysValid);
log.debug("get cert, URL=" + credDaysValidURL);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
HttpGet get = new HttpGet(credDaysValidURL, bos);
addBasicAuthHeader(get);
get.run();
Assert.assertEquals(200, get.getResponseCode());
log.debug("generate, response code: " + get.getResponseCode());
byte[] certificate = bos.toByteArray();
Assert.assertNotNull(certificate);
log.debug("Downloaded Certificate of size: " + certificate.length);
Assert.assertTrue(certificate.length > 0);

X509CertificateChain chain = SSLUtil.readPemCertificateAndKey(certificate);
verifyCert(chain, netrcUserID);

File sf = FileUtil.getFileFromResource(SUPER_CERT_FILENAME, GetCertTest.class);
Subject superUser = SSLUtil.createSubject(sf);

// try to renew superuser
Subject superUser = AuthenticationUtil.getSubject(chain);
bos = new ByteArrayOutputStream();
get = new HttpGet(credUrl, bos);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
HttpGet get = new HttpGet(credUrl, bos);
Subject.doAs(superUser, new RunnableAction(get));
log.info("super self renew: " + get.getResponseCode() + " " + get.getThrowable());
Assert.assertEquals(403, get.getResponseCode());

// get a user cert
Expand All @@ -411,8 +397,9 @@ public void testRenewWithCertFail() throws Exception {
get = new HttpGet(new URL(credUrl + "/userid/" + userID), bos);
Subject.doAs(superUser, new RunnableAction(get));
Assert.assertEquals(200, get.getResponseCode());
certificate = bos.toByteArray();
chain = SSLUtil.readPemCertificateAndKey(certificate);
log.info("super get user: " + get.getResponseCode() + " " + get.getThrowable());
byte[] certificate = bos.toByteArray();
X509CertificateChain chain = SSLUtil.readPemCertificateAndKey(certificate);
log.debug("Retrieved cert for " + chain.getChain()[0].getSubjectX500Principal());
verifyCert(chain, userID);

Expand All @@ -421,6 +408,7 @@ public void testRenewWithCertFail() throws Exception {
bos = new ByteArrayOutputStream();
get = new HttpGet(credUrl, bos);
Subject.doAs(regUser, new RunnableAction(get));
log.info("user self renew: " + get.getResponseCode() + " " + get.getThrowable());
Assert.assertEquals(403, get.getResponseCode());
}

Expand Down

0 comments on commit 2cd5cae

Please sign in to comment.