-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests to verify config changes are reflected in endpoints
- Loading branch information
1 parent
7ef6af6
commit ed3141a
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5090,4 +5090,101 @@ void secureLinkValidationFailsReturnsIdentityError(Vertx vertx, VertxTestContext | |
testContext.completeNow(); | ||
}); | ||
} | ||
|
||
@Test | ||
void tokenGenerateRespectsConfigValues(Vertx vertx, VertxTestContext testContext) { | ||
final int clientSiteId = 201; | ||
final String emailAddress = "[email protected]"; | ||
fakeAuth(clientSiteId, Role.GENERATOR); | ||
setupSalts(); | ||
setupKeys(); | ||
|
||
String v1Param = "email=" + emailAddress; | ||
JsonObject v2Payload = new JsonObject(); | ||
v2Payload.put("email", emailAddress); | ||
|
||
Duration newIdentityExpiresAfter = Duration.ofMinutes(20); | ||
Duration newRefreshExpiresAfter = Duration.ofMinutes(30); | ||
Duration newRefreshIdentityAfter = Duration.ofMinutes(10); | ||
|
||
config.put(UIDOperatorService.IDENTITY_TOKEN_EXPIRES_AFTER_SECONDS, newIdentityExpiresAfter.toMillis() / 1000); | ||
config.put(UIDOperatorService.REFRESH_TOKEN_EXPIRES_AFTER_SECONDS, newRefreshExpiresAfter.toMillis() / 1000); | ||
config.put(UIDOperatorService.REFRESH_IDENTITY_TOKEN_AFTER_SECONDS, newRefreshIdentityAfter.toMillis() / 1000); | ||
when(configService.getConfig()).thenReturn(config); | ||
|
||
try { | ||
sendTokenGenerate("v2", vertx, | ||
v1Param, v2Payload, 200, | ||
respJson -> { | ||
JsonObject body = respJson.getJsonObject("body"); | ||
testContext.verify(() -> { | ||
assertNotNull(body); | ||
assertEquals(now.plusMillis(newIdentityExpiresAfter.toMillis()).toEpochMilli(), body.getLong("identity_expires")); | ||
assertEquals(now.plusMillis(newRefreshExpiresAfter.toMillis()).toEpochMilli(), body.getLong("refresh_expires")); | ||
assertEquals(now.plusMillis(newRefreshIdentityAfter.toMillis()).toEpochMilli(), body.getLong("refresh_from")); | ||
}); | ||
testContext.completeNow(); | ||
}); | ||
} catch (Exception e) { | ||
testContext.failNow(e); | ||
} | ||
} | ||
|
||
@Test | ||
void keySharingRespectsConfigValues(Vertx vertx, VertxTestContext testContext) { | ||
int newSharingTokenExpiry = config.getInteger(Const.Config.SharingTokenExpiryProp) + 1; | ||
int newMaxSharingLifetimeSeconds = config.getInteger(Const.Config.SharingTokenExpiryProp) + 1; | ||
|
||
config.put(Const.Config.SharingTokenExpiryProp, newSharingTokenExpiry); | ||
config.put(Const.Config.MaxSharingLifetimeProp, newMaxSharingLifetimeSeconds); | ||
|
||
String apiVersion = "v2"; | ||
int siteId = 5; | ||
fakeAuth(siteId, Role.SHARER); | ||
Keyset[] keysets = { | ||
new Keyset(MasterKeysetId, MasterKeySiteId, "test", null, now.getEpochSecond(), true, true), | ||
new Keyset(10, 5, "siteKeyset", null, now.getEpochSecond(), true, true), | ||
}; | ||
KeysetKey[] encryptionKeys = { | ||
new KeysetKey(101, "master key".getBytes(), now, now, now.plusSeconds(10), MasterKeysetId), | ||
new KeysetKey(102, "site key".getBytes(), now, now, now.plusSeconds(10), 10), | ||
}; | ||
MultipleKeysetsTests test = new MultipleKeysetsTests(Arrays.asList(keysets), Arrays.asList(encryptionKeys)); | ||
setupSiteDomainAndAppNameMock(true, false, 101, 102, 103, 104, 105); | ||
send(apiVersion, vertx, apiVersion + "/key/sharing", true, null, null, 200, respJson -> { | ||
|
||
JsonObject body = respJson.getJsonObject("body"); | ||
testContext.verify(() -> { | ||
assertNotNull(body); | ||
assertEquals(newSharingTokenExpiry, Integer.parseInt(body.getString("token_expiry_seconds"))); | ||
assertEquals(newMaxSharingLifetimeSeconds + TOKEN_LIFETIME_TOLERANCE.toSeconds(), body.getLong(Const.Config.MaxSharingLifetimeProp)); | ||
}); | ||
testContext.completeNow(); | ||
}); | ||
} | ||
|
||
@Test | ||
void keyBidstreamRespectsConfigValues(Vertx vertx, VertxTestContext testContext) { | ||
int newMaxBidstreamLifetimeSeconds = 999999; | ||
config.put(Const.Config.MaxBidstreamLifetimeSecondsProp, newMaxBidstreamLifetimeSeconds); | ||
|
||
final String apiVersion = "v2"; | ||
final KeyDownloadEndpoint endpoint = KeyDownloadEndpoint.BIDSTREAM; | ||
|
||
final int clientSiteId = 101; | ||
fakeAuth(clientSiteId, Role.ID_READER); | ||
|
||
// Required, sets up mock keys. | ||
new MultipleKeysetsTests(); | ||
|
||
send(apiVersion, vertx, apiVersion + endpoint.getPath(), true, null, null, 200, respJson -> { | ||
JsonObject body = respJson.getJsonObject("body"); | ||
testContext.verify(() -> { | ||
assertNotNull(body); | ||
assertEquals(newMaxBidstreamLifetimeSeconds + TOKEN_LIFETIME_TOLERANCE.toSeconds(), body.getLong(Const.Config.MaxBidstreamLifetimeSecondsProp)); | ||
}); | ||
testContext.completeNow(); | ||
}); | ||
} | ||
|
||
} |