use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.
the class DynamicProxyTests method testProxyWithOnlyRefreshTokenValid.
@Test
void testProxyWithOnlyRefreshTokenValid() throws ExecutionException, InterruptedException {
val expirationRefresh = now().plus(10, ChronoUnit.SECONDS).getEpochSecond();
val userIdAndToken = createUserAndSecretAndObtainAccessToken("fence_gen3_refresh", "this_is_refresh_token", expirationRefresh);
JSONObject refreshContent = new JSONObject();
refreshContent.put("access_token", "this_is_a_fresh_access_token");
refreshContent.put("refresh_token", "this_is_a_fresh_refresh_token");
refreshContent.put("token_type", "BEARER");
refreshContent.put("expires_in", 1200);
gen3VM.stubFor(post("/").willReturn(ok(refreshContent.toJSONString()).withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)));
JSONObject content = new JSONObject();
content.put("user_id", "119");
content.put("username", "DoeJ");
gen3VM.stubFor(get("/user/user").willReturn(ok(content.toJSONString()).withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)));
webClient.get().uri("/gen3/user/user").accept(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + userIdAndToken.getAccessToken()).exchange().expectStatus().isOk().expectBody().json(content.toJSONString());
// Verify than access token has been refreshed
val accessSecret = secretTable.getItem(new Secret(userIdAndToken.getUserId(), "fence_gen3_access", null, null)).get();
assertThat(accessSecret).isNotNull();
assertThat(accessSecret.getSecret()).isEqualTo("encrypted_this_is_a_fresh_access_token");
assertThat(accessSecret.notExpired()).isTrue();
// Verify than refresh token has been refreshed, except for expiration date
val refreshSecret = secretTable.getItem(new Secret(userIdAndToken.getUserId(), "fence_gen3_refresh", null, null)).get();
assertThat(refreshSecret).isNotNull();
assertThat(refreshSecret.getSecret()).isEqualTo("encrypted_this_is_a_fresh_refresh_token");
assertThat(refreshSecret.getExpiration()).isEqualTo(expirationRefresh);
}
use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.
the class DynamicProxyTests method testProxyWithAccessTokenWithoutExpiration.
@Test
void testProxyWithAccessTokenWithoutExpiration() {
val userIdAndToken = createUserAndSecretAndObtainAccessToken("fence_gen3_access", "this_is_access_token");
JSONObject content = new JSONObject();
content.put("user_id", "119");
content.put("username", "DoeJ");
gen3VM.stubFor(get("/user/user").willReturn(ok(content.toJSONString()).withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)));
webClient.get().uri("/gen3/user/user").accept(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + userIdAndToken.getAccessToken()).exchange().expectStatus().isUnauthorized();
}
use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.
the class FenceDeprecatedTests method testFenceTokenPOST.
@Test
void testFenceTokenPOST() throws Exception {
val expiration = now().minus(10, ChronoUnit.SECONDS).getEpochSecond();
val userIdAndToken = createUserAndSecretAndObtainAccessToken("fence_gen3_access", "this_is_access_token", expiration);
createUserAndSecretAndObtainAccessToken("fence_gen3_refresh", "this_is_refresh_token", expiration);
JSONObject content = new JSONObject();
content.put("access_token", "this_is_fresh_access_token");
content.put("refresh_token", "this_is_fresh_refresh_token");
content.put("token_type", "BEARER");
content.put("expires_in", 1200);
gen3VM.stubFor(post("/").willReturn(ok(content.toJSONString()).withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)));
webClient.post().uri(uriBuilder -> uriBuilder.path(fenceTokenUri).queryParam("fence", "gen3").queryParam("code", "anAuthCodeValue").build()).accept(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + userIdAndToken.getAccessToken()).exchange().expectStatus().isOk().expectBody().jsonPath("$.access_token").value(o -> assertThat(o).isEqualTo("this_is_fresh_access_token")).jsonPath("$.refresh_token").value(o -> assertThat(o).isEqualTo("this_is_fresh_refresh_token"));
val accessSecret = secretTable.getItem(new Secret(userIdAndToken.getUserId(), "fence_gen3_access", null, null)).get();
assertThat(accessSecret).isNotNull();
assertThat(accessSecret.getSecret()).isEqualTo("encrypted_this_is_fresh_access_token");
assertThat(accessSecret.getExpiration()).isGreaterThan(expiration);
val refreshSecret = secretTable.getItem(new Secret(userIdAndToken.getUserId(), "fence_gen3_refresh", null, null)).get();
assertThat(refreshSecret).isNotNull();
assertThat(refreshSecret.getSecret()).isEqualTo("encrypted_this_is_fresh_refresh_token");
assertThat(refreshSecret.getExpiration()).isGreaterThan(expiration);
}
use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.
the class FenceTests method testFenceTokenExchange.
@Test
void testFenceTokenExchange() throws Exception {
val expiration = now().minus(10, ChronoUnit.SECONDS).getEpochSecond();
val userIdAndToken = createUserAndSecretAndObtainAccessToken("fence_gen3_access", "this_is_access_token", expiration);
createUserAndSecretAndObtainAccessToken("fence_gen3_refresh", "this_is_refresh_token", expiration);
JSONObject content = new JSONObject();
content.put("access_token", "this_is_fresh_access_token");
content.put("refresh_token", "this_is_fresh_refresh_token");
content.put("token_type", "BEARER");
content.put("expires_in", 1200);
gen3VM.stubFor(post("/").willReturn(ok(content.toJSONString()).withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)));
webClient.get().uri(uriBuilder -> uriBuilder.path(fenceExchangeUri).queryParam("code", "anAuthCodeValue").build()).accept(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + userIdAndToken.getAccessToken()).exchange().expectStatus().isOk().expectBody().jsonPath("$.expiration").exists();
val accessSecret = secretTable.getItem(new Secret(userIdAndToken.getUserId(), "fence_gen3_access", null, null)).get();
assertThat(accessSecret).isNotNull();
assertThat(accessSecret.getSecret()).isEqualTo("encrypted_this_is_fresh_access_token");
assertThat(accessSecret.notExpired()).isTrue();
assertThat(accessSecret.getExpiration()).isGreaterThan(expiration);
val refreshSecret = secretTable.getItem(new Secret(userIdAndToken.getUserId(), "fence_gen3_refresh", null, null)).get();
assertThat(refreshSecret).isNotNull();
assertThat(refreshSecret.getSecret()).isEqualTo("encrypted_this_is_fresh_refresh_token");
assertThat(refreshSecret.notExpired()).isTrue();
assertThat(refreshSecret.getExpiration()).isGreaterThan(expiration);
}
use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.
the class KeyStoreTests method testKeyStorePUT.
@Test
void testKeyStorePUT() throws Exception {
String my_secret = "my_secret";
JSONObject body = new JSONObject();
body.put("service", "cavatica");
body.put("secret", my_secret);
val userIdAndToken = createUserAndSecretAndObtainAccessToken("cavatica", my_secret);
webClient.put().uri(keyStoreUri).accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + userIdAndToken.getAccessToken()).bodyValue(body.toJSONString()).exchange().expectStatus().isOk().expectBody();
val secret = secretTable.getItem(new Secret(userIdAndToken.getUserId(), "cavatica", null, null)).get();
assertThat(secret).isNotNull();
assertThat(secret.getSecret()).isEqualTo("encrypted_" + my_secret);
}
Aggregations