Skip to content

Commit 95fc3b9

Browse files
authored
Merge pull request #432 from IABTechLab/aul-UID2-5227-further-tweaking-cloud-key-rotation
Added fail query param for key rotation to design alerts and dashboar…
2 parents 629262b + 4542edd commit 95fc3b9

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

src/main/java/com/uid2/admin/cloudencryption/CloudEncryptionKeyManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ public CloudEncryptionKeyManager(
3636

3737
// For any site that has an operator create a new key activating in one hour
3838
// Keep up to 10 most recent old keys per site, delete the rest
39-
public void rotateKeys() throws Exception {
39+
public void rotateKeys(boolean shouldFail) throws Exception {
4040
try {
4141
refreshCloudData();
4242
var desiredKeys = planner.planRotation(existingKeys, operatorKeys);
43+
if (shouldFail) {
44+
throw new Exception("Failing key rotation on demand due to `fail` query param being passed");
45+
}
4346
writeKeys(desiredKeys);
4447
var diff = CloudEncryptionKeyDiff.calculateDiff(existingKeys, desiredKeys);
4548
LOGGER.info("Key rotation complete. Diff: {}", diff);

src/main/java/com/uid2/admin/cloudencryption/CloudEncryptionKeyRotationJob.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
public class CloudEncryptionKeyRotationJob extends Job {
66
private final CloudEncryptionKeyManager keyManager;
7+
private final boolean shouldFail;
78

8-
public CloudEncryptionKeyRotationJob(CloudEncryptionKeyManager keyManager) {
9+
public CloudEncryptionKeyRotationJob(CloudEncryptionKeyManager keyManager, boolean shouldFail) {
910
this.keyManager = keyManager;
11+
this.shouldFail = shouldFail;
1012
}
1113

1214
@Override
@@ -16,6 +18,6 @@ public String getId() {
1618

1719
@Override
1820
public void execute() throws Exception {
19-
keyManager.rotateKeys();
21+
keyManager.rotateKeys(shouldFail);
2022
}
2123
}

src/main/java/com/uid2/admin/vertx/service/CloudEncryptionKeyService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public void setupRoutes(Router router) {
4242

4343
private void handleRotate(RoutingContext rc) {
4444
try {
45-
jobDispatcher.enqueue(new CloudEncryptionKeyRotationJob(keyManager));
45+
var shouldFail = !rc.queryParam("fail").isEmpty();
46+
47+
jobDispatcher.enqueue(new CloudEncryptionKeyRotationJob(keyManager, shouldFail));
4648
var isSuccess = jobDispatcher.executeNextJob().get();
4749
if (isSuccess) {
4850
rc.response().end();

src/test/java/com/uid2/admin/vertx/CloudEncryptionKeyServiceTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ public void testRotate_noAccess(Vertx vertx, VertxTestContext testContext) {
122122
});
123123
}
124124

125+
@Test
126+
public void testRotate_fail_on_request(Vertx vertx, VertxTestContext testContext) {
127+
fakeAuth(Role.MAINTAINER);
128+
post(vertx, testContext, Endpoints.CLOUD_ENCRYPTION_KEY_ROTATE + "?fail=true", null, response -> {
129+
assertEquals(500, response.statusCode());
130+
131+
testContext.completeNow();
132+
});
133+
}
134+
125135
@Test
126136
public void testRotate_canBeRotatedBySecretRotationJob(Vertx vertx, VertxTestContext testContext) {
127137
fakeAuth(Role.SECRET_ROTATION);

0 commit comments

Comments
 (0)