Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pic-sure-api-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<artifactId>javaee-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package edu.harvard.dbmi.avillach;

import edu.harvard.dbmi.avillach.data.entity.BaseEntity;

import edu.harvard.dbmi.avillach.data.entity.AuthUser;
import org.junit.Test;

import org.junit.jupiter.api.Test;

import java.util.UUID;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

/**
* Unit test for simple App.
*/
public class DataTest {

@Test
public void BaseEntityBasicFunctionsTest() {
BaseEntity user = new AuthUser();
user.setUuid(UUID.fromString("6ef9387a-4cde-4253-bd47-0bdc74ff76ab"));
@Test
public void BaseEntityBasicFunctionsTest() {
BaseEntity user = new AuthUser();
user.setUuid(UUID.fromString("6ef9387a-4cde-4253-bd47-0bdc74ff76ab"));

BaseEntity user2 = new AuthUser();
user2.setUuid(UUID.fromString("6ef9387a-4cde-4253-bd47-0bdc74ff76ab"));
BaseEntity user2 = new AuthUser();
user2.setUuid(UUID.fromString("6ef9387a-4cde-4253-bd47-0bdc74ff76ab"));

assertEquals(user, user2);
}
assertEquals(user, user2);
}
}
14 changes: 12 additions & 2 deletions pic-sure-api-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
Expand All @@ -73,7 +78,12 @@
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package edu.harvard.dbmi.avillach;

import org.glassfish.jersey.internal.RuntimeDelegateImpl;
import org.junit.BeforeClass;

import org.junit.Ignore;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;

import javax.ws.rs.ext.RuntimeDelegate;

@Ignore
@Disabled
public class BaseServiceTest {

protected static String endpointUrl;

@BeforeClass
@BeforeAll
public static void beforeClass() {
endpointUrl = System.getProperty("service.url");

//Need to be able to throw exceptions without container so we can verify correct errors are being thrown
// Need to be able to throw exceptions without container so we can verify correct errors are being thrown
RuntimeDelegate runtimeDelegate = new RuntimeDelegateImpl();
RuntimeDelegate.setInstance(runtimeDelegate);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package edu.harvard.dbmi.avillach;

import org.junit.jupiter.api.Test;

import edu.harvard.dbmi.avillach.data.request.ConfigurationRequest;
import org.junit.Test;

import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
Expand All @@ -10,16 +11,16 @@
import java.util.Arrays;
import java.util.UUID;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ConfigurationRSTest {
private final String SUPER_ADMIN = "SUPER_ADMIN";

private void assertRolesAllowed(Method method, String role) {
RolesAllowed annotation = method.getAnnotation(RolesAllowed.class);
assertNotNull("@RolesAllowed missing on " + method.getName(), annotation);
assertTrue(role + " role missing on " + method.getName(), Arrays.asList(annotation.value()).contains(role));
assertNotNull(annotation, "@RolesAllowed missing on " + method.getName());
assertTrue(Arrays.asList(annotation.value()).contains(role), role + " role missing on " + method.getName());
}

// These unit tests only guard against accidental removal during refactor & they are not an E2E test of the functionality
Expand All @@ -37,7 +38,7 @@ public void adminEndpoints_requireAdminRole() throws NoSuchMethodException {

private void assertPermitAll(Method method) {
PermitAll permitAll = method.getAnnotation(PermitAll.class);
assertNotNull(method.getName() + " must have @PermitAll annotation", permitAll);
assertNotNull(permitAll, method.getName() + " must have @PermitAll annotation");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,66 @@
import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.junit.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;

import javax.ws.rs.ext.ReaderInterceptorContext;

import java.io.IOException;

import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.util.HashMap;


import org.apache.cxf.jaxrs.impl.ReaderInterceptorContextImpl;

import static org.junit.Assert.*;

public class LoggerReaderInterceptorTest {

private LoggerReaderInterceptor cut = new LoggerReaderInterceptor();

@Test
public void testCredentialsRedacted() throws IOException{

//Different pieces of a query
String resourceCredentials = "resourceCredentials\": " +
"{ \"IRCT_BEARER_TOKEN\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0fGF2bGJvdEBkYm1pLmhtcy5oYXJ2YXJkLmVkdSIsImVtYWlsIjoiYXZsYm90QGRibWkuaG1zLmhhcnZhcmQuZWR1In0.51TYsm-uw2VtI8aGawdggbGdCSrPJvjtvzafd2Ii9NU\"}";

String query = "query\": " +
"{ " +
"\"select\": [" +
" {" +
" \"alias\": \"gender\", \"field\": {\"pui\": \"/nhanes/Demo/demographics/demographics/SEX/male\", \"dataType\":\"STRING\"}" +
" }," +
" {" +
" \"alias\": \"gender\", \"field\": {\"pui\": \"/nhanes/Demo/demographics/demographics/SEX/female\", \"dataType\":\"STRING\"}" +
" }," +
" {" +
" \"alias\": \"age\", \"field\": {\"pui\": \"/nhanes/Demo/demographics/demographics/AGE\", \"dataType\":\"STRING\"}" +
" }" +
" ]," +
" \"where\": [ " +
"{ \"predicate\": \"CONTAINS\", " +
"\"field\": " +
"{ \"pui\": \"/nhanes/Demo/demographics/demographics/SEX/male/\", " +
"\"dataType\": \"STRING\" " +
"}, " +
"\"fields\": " +
"{ \"ENOUNTER\": \"YES\" } " +
"} ]" +
"}";
public void testCredentialsRedacted() throws IOException {

// Different pieces of a query
String resourceCredentials = "resourceCredentials\": "
+ "{ \"IRCT_BEARER_TOKEN\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0fGF2bGJvdEBkYm1pLmhtcy5oYXJ2YXJkLmVkdSIsImVtYWlsIjoiYXZsYm90QGRibWkuaG1zLmhhcnZhcmQuZWR1In0.51TYsm-uw2VtI8aGawdggbGdCSrPJvjtvzafd2Ii9NU\"}";

String query = "query\": " + "{ " + "\"select\": [" + " {"
+ " \"alias\": \"gender\", \"field\": {\"pui\": \"/nhanes/Demo/demographics/demographics/SEX/male\", \"dataType\":\"STRING\"}"
+ " }," + " {"
+ " \"alias\": \"gender\", \"field\": {\"pui\": \"/nhanes/Demo/demographics/demographics/SEX/female\", \"dataType\":\"STRING\"}"
+ " }," + " {"
+ " \"alias\": \"age\", \"field\": {\"pui\": \"/nhanes/Demo/demographics/demographics/AGE\", \"dataType\":\"STRING\"}"
+ " }" + " ]," + " \"where\": [ " + "{ \"predicate\": \"CONTAINS\", " + "\"field\": "
+ "{ \"pui\": \"/nhanes/Demo/demographics/demographics/SEX/male/\", " + "\"dataType\": \"STRING\" " + "}, " + "\"fields\": "
+ "{ \"ENOUNTER\": \"YES\" } " + "} ]" + "}";

String resourceUUID = "\"resourceUUID\" : \"{{resourceUUID}}\"";

//Assemble pieces into different test queries
// Assemble pieces into different test queries
String order1 = "{ " + resourceUUID + "," + query + ", " + resourceCredentials + "}";
String order2 = "{ " + query + "," + resourceCredentials + ", " + resourceUUID + "}";
String credentialsOnly = "{" + resourceCredentials + "}";
String nested1 = "{" + resourceUUID + ", query: " + order1 + ", " + resourceCredentials + "}";
String nested2 = "{ " + resourceCredentials + "," + "query:" + nested1 + ", " + resourceUUID + "}";


//Mocking turned out to be a mess so let's just do this this dumb way
// Mocking turned out to be a mess so let's just do this this dumb way
Message message = new MessageImpl();
Exchange ex = new ExchangeImpl();
ex.put("jaxrs.filter.properties", new HashMap<String, String>());
message.setExchange(ex);

//Put the test string into a stream and stuff it in a context to test
// Put the test string into a stream and stuff it in a context to test
InputStream stream = IOUtils.toInputStream(order1, "UTF-8");
ReaderInterceptorContext context = new ReaderInterceptorContextImpl(null, null, null, stream,message, null);
ReaderInterceptorContext context = new ReaderInterceptorContextImpl(null, null, null, stream, message, null);
cut.aroundReadFrom(context);

//See if it's done what we want
// See if it's done what we want
Object result = context.getProperty("requestContent");
assertNotNull(result);
String resultString = result.toString();
Expand All @@ -84,9 +75,9 @@ public void testCredentialsRedacted() throws IOException{
assertFalse(resultString.contains("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"));
assertTrue(resultString.contains("RESOURCE_CREDENTIALS_REDACTED"));

//Make sure order isn't an issue
// Make sure order isn't an issue
stream = IOUtils.toInputStream(order2, "UTF-8");
context = new ReaderInterceptorContextImpl(null, null, null, stream,message, null);
context = new ReaderInterceptorContextImpl(null, null, null, stream, message, null);
cut.aroundReadFrom(context);

result = context.getProperty("requestContent");
Expand All @@ -98,9 +89,9 @@ public void testCredentialsRedacted() throws IOException{
assertFalse(resultString.contains("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"));
assertTrue(resultString.contains("RESOURCE_CREDENTIALS_REDACTED"));

//What if there's nothing in there but credentials
// What if there's nothing in there but credentials
stream = IOUtils.toInputStream(credentialsOnly, "UTF-8");
context = new ReaderInterceptorContextImpl(null, null, null, stream,message, null);
context = new ReaderInterceptorContextImpl(null, null, null, stream, message, null);
cut.aroundReadFrom(context);

result = context.getProperty("requestContent");
Expand All @@ -112,9 +103,9 @@ public void testCredentialsRedacted() throws IOException{
assertFalse(resultString.contains("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"));
assertTrue(resultString.contains("RESOURCE_CREDENTIALS_REDACTED"));

//What if it's nested?
// What if it's nested?
stream = IOUtils.toInputStream(nested1, "UTF-8");
context = new ReaderInterceptorContextImpl(null, null, null, stream,message, null);
context = new ReaderInterceptorContextImpl(null, null, null, stream, message, null);
cut.aroundReadFrom(context);

result = context.getProperty("requestContent");
Expand All @@ -127,9 +118,9 @@ public void testCredentialsRedacted() throws IOException{
assertTrue(resultString.contains("RESOURCE_CREDENTIALS_REDACTED"));
assertEquals(2, StringUtils.countMatches(resultString, "RESOURCE_CREDENTIALS_REDACTED"));

//What if it's nested two layers deep??
// What if it's nested two layers deep??
stream = IOUtils.toInputStream(nested2, "UTF-8");
context = new ReaderInterceptorContextImpl(null, null, null, stream,message, null);
context = new ReaderInterceptorContextImpl(null, null, null, stream, message, null);
cut.aroundReadFrom(context);

result = context.getProperty("requestContent");
Expand Down
Loading