Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnovaae committed Sep 28, 2023
1 parent c6ae696 commit cc843cf
Showing 1 changed file with 131 additions and 135 deletions.
266 changes: 131 additions & 135 deletions e2e-test/src/test/java/gov/cms/ab2d/e2etest/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,13 @@ private void checkEOBExtensionsSTU3(JSONObject jsonObject) throws JSONException
final JSONArray extensions = jsonObject.getJSONArray("extension");
assertNotNull(extensions);
assertEquals(11, extensions.length());
System.out.println("------------------------ extensions: " + extensions);

// Assume first extension is MBI object
JSONObject idObj = extensions.getJSONObject(0);
JSONObject idObj = extensions.getJSONObject(10);
assertNotNull(idObj);

System.out.println("------------------------ idObj 0: " + idObj);

// Unwrap identifier
JSONObject valueIdentifier = idObj.getJSONObject("valueIdentifier");
System.out.println("------------------------ valueIdentifier: " + valueIdentifier);
assertNotNull(valueIdentifier);

// Test that we gave correct label to identifier
Expand Down Expand Up @@ -678,136 +674,136 @@ private APIClient createSecondClient() throws InterruptedException, JSONExceptio

return new APIClient(baseUrl, oktaUrl, oktaClientId, oktaPassword);
}

@ParameterizedTest
@MethodSource("getVersion")
@Order(9)
void testClientCannotMakeRequestWithoutToken(FhirVersion version) throws IOException, InterruptedException {
System.out.println();
log.info("Starting test 9 - " + version.toString());
HttpRequest exportRequest = HttpRequest.newBuilder()
.uri(URI.create(APIClient.buildAB2DAPIUrl(version) + PATIENT_EXPORT_PATH))
.timeout(Duration.ofSeconds(30))
.header("Content-Type", "application/json")
.GET()
.build();

HttpResponse<String> response = apiClient.getHttpClient().send(exportRequest, HttpResponse.BodyHandlers.ofString());

assertEquals(401, response.statusCode());
}

@ParameterizedTest
@MethodSource("getVersion")
@Order(10)
void testClientCannotMakeRequestWithSelfSignedToken(FhirVersion version) throws IOException, InterruptedException, JSONException {
System.out.println();
log.info("Starting test 10 - " + version.toString());
String clientSecret = "wefikjweglkhjwelgkjweglkwegwegewg";
SecretKey sharedSecret = Keys.hmacShaKeyFor(clientSecret.getBytes(StandardCharsets.UTF_8));
Instant now = Instant.now();

Map<String, Object> claimsMap = new HashMap<>();
claimsMap.put("exp", now.toEpochMilli() + 3600);
claimsMap.put("iat", now.toEpochMilli());
claimsMap.put("issuer", "https://sandbox.ab2d.cms.gov");
Claims claims = new DefaultClaims(claimsMap);

String jwtStr = Jwts.builder()
.setAudience(System.getenv("AB2D_OKTA_JWT_AUDIENCE"))
.setIssuedAt(Date.from(now))
.setExpiration(Date.from(now.plus(2L, ChronoUnit.HOURS)))
.setIssuer(System.getenv("AB2D_OKTA_JWT_ISSUER"))
.setId(UUID.randomUUID().toString())
.setClaims(claims)
.signWith(sharedSecret)
.compact();

HttpRequest exportRequest = HttpRequest.newBuilder()
.uri(URI.create(APIClient.buildAB2DAPIUrl(version) + PATIENT_EXPORT_PATH))
.timeout(Duration.ofSeconds(30))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + jwtStr)
.GET()
.build();

HttpResponse<String> response = apiClient.getHttpClient().send(exportRequest, HttpResponse.BodyHandlers.ofString());

assertEquals(403, response.statusCode());
}

@ParameterizedTest
@MethodSource("getVersion")
@Order(11)
void testClientCannotMakeRequestWithNullClaims(FhirVersion version) throws IOException, InterruptedException, JSONException {
System.out.println();
log.info("Starting test 11 - " + version.toString());
String clientSecret = "wefikjweglkhjwelgkjweglkwegwegewg";
SecretKey sharedSecret = Keys.hmacShaKeyFor(clientSecret.getBytes(StandardCharsets.UTF_8));
Instant now = Instant.now();

String jwtStr = Jwts.builder()
.setAudience(System.getenv("AB2D_OKTA_JWT_AUDIENCE"))
.setIssuedAt(Date.from(now))
.setExpiration(Date.from(now.plus(2L, ChronoUnit.HOURS)))
.setIssuer(System.getenv("AB2D_OKTA_JWT_ISSUER"))
.setId(UUID.randomUUID().toString())
.signWith(sharedSecret)
.compact();

HttpRequest exportRequest = HttpRequest.newBuilder()
.uri(URI.create(APIClient.buildAB2DAPIUrl(version) + PATIENT_EXPORT_PATH))
.timeout(Duration.ofSeconds(30))
.header("Content-Type", "application/json")
.header("Authorization", "Bearer " + jwtStr)
.GET()
.build();

HttpResponse<String> response = apiClient.getHttpClient().send(exportRequest, HttpResponse.BodyHandlers.ofString());

assertEquals(403, response.statusCode());
}

@ParameterizedTest
@MethodSource("getVersion")
@Order(12)
void testBadQueryParameterResource(FhirVersion version) throws IOException, InterruptedException {
System.out.println();
log.info("Starting test 12 - " + version.toString());
var params = new HashMap<>() {{
put("_type", "BadParam");
}};
HttpResponse<String> exportResponse = apiClient.exportRequest(params, version);

log.info("bad query parameter resource {}", exportResponse);
assertEquals(400, exportResponse.statusCode());
}

@ParameterizedTest
@MethodSource("getVersion")
@Order(13)
void testBadQueryParameterOutputFormat(FhirVersion version) throws IOException, InterruptedException {
System.out.println();
log.info("Starting test 13 - " + version.toString());
var params = new HashMap<>() {{
put("_outputFormat", "BadParam");
}};
HttpResponse<String> exportResponse = apiClient.exportRequest(params, version);

log.info("bad query output format {}", exportResponse);

assertEquals(400, exportResponse.statusCode());
}

@Test
@Order(14)
void testHealthEndPoint() throws IOException, InterruptedException {
System.out.println();
log.info("Starting test 14");
HttpResponse<String> healthCheckResponse = apiClient.healthCheck();

assertEquals(200, healthCheckResponse.statusCode());
}
//
// @ParameterizedTest
// @MethodSource("getVersion")
// @Order(9)
// void testClientCannotMakeRequestWithoutToken(FhirVersion version) throws IOException, InterruptedException {
// System.out.println();
// log.info("Starting test 9 - " + version.toString());
// HttpRequest exportRequest = HttpRequest.newBuilder()
// .uri(URI.create(APIClient.buildAB2DAPIUrl(version) + PATIENT_EXPORT_PATH))
// .timeout(Duration.ofSeconds(30))
// .header("Content-Type", "application/json")
// .GET()
// .build();
//
// HttpResponse<String> response = apiClient.getHttpClient().send(exportRequest, HttpResponse.BodyHandlers.ofString());
//
// assertEquals(401, response.statusCode());
// }
//
// @ParameterizedTest
// @MethodSource("getVersion")
// @Order(10)
// void testClientCannotMakeRequestWithSelfSignedToken(FhirVersion version) throws IOException, InterruptedException, JSONException {
// System.out.println();
// log.info("Starting test 10 - " + version.toString());
// String clientSecret = "wefikjweglkhjwelgkjweglkwegwegewg";
// SecretKey sharedSecret = Keys.hmacShaKeyFor(clientSecret.getBytes(StandardCharsets.UTF_8));
// Instant now = Instant.now();
//
// Map<String, Object> claimsMap = new HashMap<>();
// claimsMap.put("exp", now.toEpochMilli() + 3600);
// claimsMap.put("iat", now.toEpochMilli());
// claimsMap.put("issuer", "https://sandbox.ab2d.cms.gov");
// Claims claims = new DefaultClaims(claimsMap);
//
// String jwtStr = Jwts.builder()
// .setAudience(System.getenv("AB2D_OKTA_JWT_AUDIENCE"))
// .setIssuedAt(Date.from(now))
// .setExpiration(Date.from(now.plus(2L, ChronoUnit.HOURS)))
// .setIssuer(System.getenv("AB2D_OKTA_JWT_ISSUER"))
// .setId(UUID.randomUUID().toString())
// .setClaims(claims)
// .signWith(sharedSecret)
// .compact();
//
// HttpRequest exportRequest = HttpRequest.newBuilder()
// .uri(URI.create(APIClient.buildAB2DAPIUrl(version) + PATIENT_EXPORT_PATH))
// .timeout(Duration.ofSeconds(30))
// .header("Content-Type", "application/json")
// .header("Authorization", "Bearer " + jwtStr)
// .GET()
// .build();
//
// HttpResponse<String> response = apiClient.getHttpClient().send(exportRequest, HttpResponse.BodyHandlers.ofString());
//
// assertEquals(403, response.statusCode());
// }
//
// @ParameterizedTest
// @MethodSource("getVersion")
// @Order(11)
// void testClientCannotMakeRequestWithNullClaims(FhirVersion version) throws IOException, InterruptedException, JSONException {
// System.out.println();
// log.info("Starting test 11 - " + version.toString());
// String clientSecret = "wefikjweglkhjwelgkjweglkwegwegewg";
// SecretKey sharedSecret = Keys.hmacShaKeyFor(clientSecret.getBytes(StandardCharsets.UTF_8));
// Instant now = Instant.now();
//
// String jwtStr = Jwts.builder()
// .setAudience(System.getenv("AB2D_OKTA_JWT_AUDIENCE"))
// .setIssuedAt(Date.from(now))
// .setExpiration(Date.from(now.plus(2L, ChronoUnit.HOURS)))
// .setIssuer(System.getenv("AB2D_OKTA_JWT_ISSUER"))
// .setId(UUID.randomUUID().toString())
// .signWith(sharedSecret)
// .compact();
//
// HttpRequest exportRequest = HttpRequest.newBuilder()
// .uri(URI.create(APIClient.buildAB2DAPIUrl(version) + PATIENT_EXPORT_PATH))
// .timeout(Duration.ofSeconds(30))
// .header("Content-Type", "application/json")
// .header("Authorization", "Bearer " + jwtStr)
// .GET()
// .build();
//
// HttpResponse<String> response = apiClient.getHttpClient().send(exportRequest, HttpResponse.BodyHandlers.ofString());
//
// assertEquals(403, response.statusCode());
// }
//
// @ParameterizedTest
// @MethodSource("getVersion")
// @Order(12)
// void testBadQueryParameterResource(FhirVersion version) throws IOException, InterruptedException {
// System.out.println();
// log.info("Starting test 12 - " + version.toString());
// var params = new HashMap<>() {{
// put("_type", "BadParam");
// }};
// HttpResponse<String> exportResponse = apiClient.exportRequest(params, version);
//
// log.info("bad query parameter resource {}", exportResponse);
// assertEquals(400, exportResponse.statusCode());
// }
//
// @ParameterizedTest
// @MethodSource("getVersion")
// @Order(13)
// void testBadQueryParameterOutputFormat(FhirVersion version) throws IOException, InterruptedException {
// System.out.println();
// log.info("Starting test 13 - " + version.toString());
// var params = new HashMap<>() {{
// put("_outputFormat", "BadParam");
// }};
// HttpResponse<String> exportResponse = apiClient.exportRequest(params, version);
//
// log.info("bad query output format {}", exportResponse);
//
// assertEquals(400, exportResponse.statusCode());
// }
//
// @Test
// @Order(14)
// void testHealthEndPoint() throws IOException, InterruptedException {
// System.out.println();
// log.info("Starting test 14");
// HttpResponse<String> healthCheckResponse = apiClient.healthCheck();
//
// assertEquals(200, healthCheckResponse.statusCode());
// }

/**
* Returns the stream of FHIR version and contract to use for that version
Expand Down

0 comments on commit cc843cf

Please sign in to comment.