diff --git a/pom.xml b/pom.xml index ad11dca9..54ce19e9 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ 1.1.0 5.7.0 - 5.9.6-62621be878 + 5.11.0-d71d3c960e ${project.version} diff --git a/src/main/java/com/uid2/admin/secret/IKeypairManager.java b/src/main/java/com/uid2/admin/secret/IKeypairManager.java index 8badba31..619d7044 100644 --- a/src/main/java/com/uid2/admin/secret/IKeypairManager.java +++ b/src/main/java/com/uid2/admin/secret/IKeypairManager.java @@ -3,6 +3,6 @@ import com.uid2.shared.model.ClientSideKeypair; public interface IKeypairManager { - ClientSideKeypair createAndSaveSiteKeypair(int siteId, String contact, boolean disabled) throws Exception; + ClientSideKeypair createAndSaveSiteKeypair(int siteId, String contact, boolean disabled, String name) throws Exception; Iterable getKeypairsBySite(int siteId); } diff --git a/src/main/java/com/uid2/admin/store/writer/ClientSideKeypairStoreWriter.java b/src/main/java/com/uid2/admin/store/writer/ClientSideKeypairStoreWriter.java index d1ccddc8..fe48e533 100644 --- a/src/main/java/com/uid2/admin/store/writer/ClientSideKeypairStoreWriter.java +++ b/src/main/java/com/uid2/admin/store/writer/ClientSideKeypairStoreWriter.java @@ -58,6 +58,7 @@ private static JsonObject toJson(ClientSideKeypair keypair, boolean includePriva jo.put("contact", keypair.getContact()); jo.put("created", keypair.getCreated().getEpochSecond()); jo.put("disabled", keypair.isDisabled()); + jo.put("name", keypair.getName()); return jo; } diff --git a/src/main/java/com/uid2/admin/vertx/service/ClientSideKeypairService.java b/src/main/java/com/uid2/admin/vertx/service/ClientSideKeypairService.java index 83741395..3844d7c7 100644 --- a/src/main/java/com/uid2/admin/vertx/service/ClientSideKeypairService.java +++ b/src/main/java/com/uid2/admin/vertx/service/ClientSideKeypairService.java @@ -86,6 +86,7 @@ private void handleAddKeypair(RoutingContext rc) { final Integer siteId = body.getInteger("site_id"); final String contact = body.getString("contact", ""); final boolean disabled = body.getBoolean("disabled", false); + final String name = body.getString("name"); if (siteId == null) { ResponseUtil.error(rc, 400, "Required parameters: site_id"); return; @@ -97,7 +98,7 @@ private void handleAddKeypair(RoutingContext rc) { final ClientSideKeypair newKeypair; try { - newKeypair = createAndSaveSiteKeypair(siteId, contact, disabled); + newKeypair = createAndSaveSiteKeypair(siteId, contact, disabled, name); } catch (Exception e) { ResponseUtil.errorInternal(rc, "failed to upload keypairs", e); return; @@ -120,6 +121,7 @@ private void handleUpdateKeypair(RoutingContext rc) { final String subscriptionId = body.getString("subscription_id"); String contact = body.getString("contact"); Boolean disabled = body.getBoolean("disabled"); + String name = body.getString("name"); if (subscriptionId == null) { ResponseUtil.error(rc, 400, "Required parameters: subscription_id"); @@ -132,18 +134,23 @@ private void handleUpdateKeypair(RoutingContext rc) { return; } - if (contact == null && disabled == null) { - ResponseUtil.error(rc, 400, "Updatable parameters: contact, disabled"); + if (contact == null && disabled == null && name == null) { + ResponseUtil.error(rc, 400, "Updatable parameters: contact, disabled, name"); return; } if (contact == null) { contact = keypair.getContact(); } + if (disabled == null) { disabled = keypair.isDisabled(); } + if (name == null) { + name = keypair.getName(); + } + final ClientSideKeypair newKeypair = new ClientSideKeypair( keypair.getSubscriptionId(), keypair.encodePublicKeyToString(), @@ -151,7 +158,8 @@ private void handleUpdateKeypair(RoutingContext rc) { keypair.getSiteId(), contact, keypair.getCreated(), - disabled); + disabled, + name); Set allKeypairs = new HashSet<>(this.keypairStore.getAll()); @@ -198,7 +206,7 @@ private void handleListKeypair(RoutingContext rc) { } @Override - public ClientSideKeypair createAndSaveSiteKeypair(int siteId, String contact, boolean disabled) throws Exception { + public ClientSideKeypair createAndSaveSiteKeypair(int siteId, String contact, boolean disabled, String name) throws Exception { final Instant now = clock.now(); @@ -219,7 +227,8 @@ public ClientSideKeypair createAndSaveSiteKeypair(int siteId, String contact, bo siteId, contact, now, - disabled); + disabled, + name); keypairs.add(newKeypair); storeWriter.upload(keypairs, null); diff --git a/src/test/java/com/uid2/admin/vertx/ClientSideKeypairServiceTest.java b/src/test/java/com/uid2/admin/vertx/ClientSideKeypairServiceTest.java index abfeedef..58b07365 100644 --- a/src/test/java/com/uid2/admin/vertx/ClientSideKeypairServiceTest.java +++ b/src/test/java/com/uid2/admin/vertx/ClientSideKeypairServiceTest.java @@ -39,6 +39,10 @@ public class ClientSideKeypairServiceTest extends ServiceTestBase { private final String priv2 = "UID2-Y-L-MEECAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEJzAlAgEBBCAshNg/7jgVzpyueRlF73Y4YvH18P+4EUed5Pw5ZAbnqA=="; private final String priv3 = "UID2-Y-L-MEECAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEJzAlAgEBBCBt5EM8QQfaegeYWzxbFTkn+HRZmZ3kR0Eqeesv6aMHMA=="; private final String priv4 = "UID2-Y-L-MEECAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEJzAlAgEBBCDe6TIHd+Eyoczq1a8xeNGw17OWjeJHZwSLXtuMcqCXZQ=="; + private final String name1 = "name 1"; + private final String name2 = "name 2"; + private final String name3 = "name 3"; + private final String name4 = "name 4"; @Override protected IService createService() { JsonObject config = new JsonObject(); @@ -105,10 +109,10 @@ void listAll(Vertx vertx, VertxTestContext testContext) throws Exception { fakeAuth(Role.ADMINISTRATOR); Map expectedKeypairs = new HashMap<>() {{ - put("aZ23456789", new ClientSideKeypair("aZ23456789", pub1, priv1, 123, "test@example.com", Instant.now(), false)); - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub2, priv2, 124, "test-two@example.com", Instant.now(), true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub3, priv3, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub4, priv4, 125, "test-two@example.com", Instant.now(), false)); + put("aZ23456789", new ClientSideKeypair("aZ23456789", pub1, priv1, 123, "test@example.com", Instant.now(), false, name1)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub2, priv2, 124, "test-two@example.com", Instant.now(), true, name2)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub3, priv3, 123, "test@example.com", Instant.now(), true, name3)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub4, priv4, 125, "test-two@example.com", Instant.now(), false, name4)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -139,13 +143,13 @@ void listKeypairSubscriptionIdNotFound(Vertx vertx, VertxTestContext testContext void listKeypair(Vertx vertx, VertxTestContext testContext) throws Exception { fakeAuth(Role.ADMINISTRATOR); - ClientSideKeypair queryKeypair = new ClientSideKeypair("aZ23456789", pub1, priv1, 123, "test@example.com", Instant.now(), false); + ClientSideKeypair queryKeypair = new ClientSideKeypair("aZ23456789", pub1, priv1, 123, "test@example.com", Instant.now(), false, name1); Map expectedKeypairs = new HashMap<>() {{ put("aZ23456789", queryKeypair); - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub2, priv2, 124, "test-two@example.com", Instant.now(), true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub3, priv3, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub4, priv4, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub2, priv2, 124, "test-two@example.com", Instant.now(), true, name2)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub3, priv3, 123, "test@example.com", Instant.now(), true, name3)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub4, priv4, 125, "test-two@example.com", Instant.now(), false, name4)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -163,9 +167,9 @@ void addKeypairNoSiteIdOrContact(Vertx vertx, VertxTestContext testContext) thro fakeAuth(Role.ADMINISTRATOR); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -175,6 +179,7 @@ void addKeypairNoSiteIdOrContact(Vertx vertx, VertxTestContext testContext) thro post(vertx, "api/client_side_keypairs/add", jo.encode(), testContext.succeeding(response -> testContext.verify(() -> { assertEquals(400, response.statusCode()); assertEquals("Required parameters: site_id", response.bodyAsJsonObject().getString("message")); + verify(keypairStoreWriter, times(0)).upload(any(), isNull()); testContext.completeNow(); }))); } @@ -184,9 +189,9 @@ void addKeypairNoSiteId(Vertx vertx, VertxTestContext testContext) throws Except fakeAuth(Role.ADMINISTRATOR); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -197,6 +202,7 @@ void addKeypairNoSiteId(Vertx vertx, VertxTestContext testContext) throws Except post(vertx, "api/client_side_keypairs/add", jo.encode(), testContext.succeeding(response -> testContext.verify(() -> { assertEquals(400, response.statusCode()); assertEquals("Required parameters: site_id", response.bodyAsJsonObject().getString("message")); + verify(keypairStoreWriter, times(0)).upload(any(), isNull()); testContext.completeNow(); }))); } @@ -206,9 +212,9 @@ void addKeypairBadSiteId(Vertx vertx, VertxTestContext testContext) throws Excep fakeAuth(Role.ADMINISTRATOR); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -220,6 +226,7 @@ void addKeypairBadSiteId(Vertx vertx, VertxTestContext testContext) throws Excep post(vertx, "api/client_side_keypairs/add", jo.encode(), testContext.succeeding(response -> testContext.verify(() -> { assertEquals(404, response.statusCode()); assertEquals("site_id: 123 not valid", response.bodyAsJsonObject().getString("message")); + verify(keypairStoreWriter, times(0)).upload(any(), isNull()); testContext.completeNow(); }))); } @@ -229,9 +236,9 @@ void addKeypair(Vertx vertx, VertxTestContext testContext) throws Exception { fakeAuth(Role.ADMINISTRATOR); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -262,7 +269,7 @@ void addKeypair(Vertx vertx, VertxTestContext testContext) throws Exception { assertEquals("UID2-Y-L-", resp.getString("private_key").substring(0, 9)); assertEquals(KEY_CREATE_TIME_IN_SECONDS, resp.getLong("created")); assertEquals(false, resp.getBoolean("disabled")); - assertEquals(false, resp.getBoolean("disabled")); + verify(keypairStoreWriter, times(1)).upload(any(), isNull()); testContext.completeNow(); }))); } @@ -272,9 +279,9 @@ void addKeypairNoContact(Vertx vertx, VertxTestContext testContext) throws Excep fakeAuth(Role.ADMINISTRATOR); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -298,6 +305,7 @@ void addKeypairNoContact(Vertx vertx, VertxTestContext testContext) throws Excep assertEquals(KEY_CREATE_TIME_IN_SECONDS, resp.getLong("created")); assertEquals(false, resp.getBoolean("disabled")); assertEquals(false, resp.getBoolean("disabled")); + verify(keypairStoreWriter, times(1)).upload(any(), isNull()); testContext.completeNow(); }))); } @@ -307,9 +315,9 @@ void addKeypairDisabled(Vertx vertx, VertxTestContext testContext) throws Except fakeAuth(Role.ADMINISTRATOR); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -332,6 +340,7 @@ void addKeypairDisabled(Vertx vertx, VertxTestContext testContext) throws Except assertTrue(resp.getString("private_key").length() > 0); assertEquals(KEY_CREATE_TIME_IN_SECONDS, resp.getLong("created")); assertEquals(true, resp.getBoolean("disabled")); + verify(keypairStoreWriter, times(1)).upload(any(), isNull()); testContext.completeNow(); }))); } @@ -341,9 +350,9 @@ void updateKeypairNoSubscriptionId(Vertx vertx, VertxTestContext testContext) th fakeAuth(Role.ADMINISTRATOR); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -356,6 +365,7 @@ void updateKeypairNoSubscriptionId(Vertx vertx, VertxTestContext testContext) th post(vertx, "api/client_side_keypairs/update", jo.encode(), testContext.succeeding(response -> testContext.verify(() -> { assertEquals(400, response.statusCode()); assertEquals("Required parameters: subscription_id", response.bodyAsJsonObject().getString("message")); + verify(keypairStoreWriter, times(0)).upload(any(), isNull()); testContext.completeNow(); }))); } @@ -365,9 +375,9 @@ void updateKeypairBadSubscriptionId(Vertx vertx, VertxTestContext testContext) t fakeAuth(Role.ADMINISTRATOR); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -381,6 +391,7 @@ void updateKeypairBadSubscriptionId(Vertx vertx, VertxTestContext testContext) t post(vertx, "api/client_side_keypairs/update", jo.encode(), testContext.succeeding(response -> testContext.verify(() -> { assertEquals(404, response.statusCode()); assertEquals("Failed to find a keypair for subscription id: bad-id", response.bodyAsJsonObject().getString("message")); + verify(keypairStoreWriter, times(0)).upload(any(), isNull()); testContext.completeNow(); }))); } @@ -390,9 +401,9 @@ void updateKeypairNoUpdateParams(Vertx vertx, VertxTestContext testContext) thro fakeAuth(Role.ADMINISTRATOR); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", Instant.now(), true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -403,7 +414,8 @@ void updateKeypairNoUpdateParams(Vertx vertx, VertxTestContext testContext) thro post(vertx, "api/client_side_keypairs/update", jo.encode(), testContext.succeeding(response -> testContext.verify(() -> { assertEquals(400, response.statusCode()); - assertEquals("Updatable parameters: contact, disabled", response.bodyAsJsonObject().getString("message")); + assertEquals("Updatable parameters: contact, disabled, name", response.bodyAsJsonObject().getString("message")); + verify(keypairStoreWriter, times(0)).upload(any(), isNull()); testContext.completeNow(); }))); } @@ -414,9 +426,9 @@ void updateKeypairContactOnly(Vertx vertx, VertxTestContext testContext) throws Instant time = Instant.now(); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -428,8 +440,36 @@ void updateKeypairContactOnly(Vertx vertx, VertxTestContext testContext) throws post(vertx, "api/client_side_keypairs/update", jo.encode(), testContext.succeeding(response -> testContext.verify(() -> { assertEquals(200, response.statusCode()); - ClientSideKeypair expected = new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "updated@email.com", time, true); + ClientSideKeypair expected = new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "updated@email.com", time, true, name1); + validateKeypair(expected, response.bodyAsJsonObject()); + verify(keypairStoreWriter, times(1)).upload(any(), isNull()); + testContext.completeNow(); + }))); + } + + @Test + void updateKeypairNameOnly(Vertx vertx, VertxTestContext testContext) throws Exception { + fakeAuth(Role.ADMINISTRATOR); + + Instant time = Instant.now(); + Map expectedKeypairs = new HashMap<>() {{ + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); + }}; + + setKeypairs(new ArrayList<>(expectedKeypairs.values())); + setSites(new Site(123, "test", true)); + + JsonObject jo = new JsonObject(); + jo.put("subscription_id", "89aZ234567"); + jo.put("name", "updated name"); + + post(vertx, "api/client_side_keypairs/update", jo.encode(), testContext.succeeding(response -> testContext.verify(() -> { + assertEquals(200, response.statusCode()); + ClientSideKeypair expected = new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, true, "updated name"); validateKeypair(expected, response.bodyAsJsonObject()); + verify(keypairStoreWriter, times(1)).upload(any(), isNull()); testContext.completeNow(); }))); } @@ -440,9 +480,9 @@ void updateKeypairDisabledOnly(Vertx vertx, VertxTestContext testContext) throws Instant time = Instant.now(); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -454,8 +494,9 @@ void updateKeypairDisabledOnly(Vertx vertx, VertxTestContext testContext) throws post(vertx, "api/client_side_keypairs/update", jo.encode(), testContext.succeeding(response -> testContext.verify(() -> { assertEquals(200, response.statusCode()); - ClientSideKeypair expected = new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, false); + ClientSideKeypair expected = new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, false, name1); validateKeypair(expected, response.bodyAsJsonObject()); + verify(keypairStoreWriter, times(1)).upload(any(), isNull()); testContext.completeNow(); }))); } @@ -466,9 +507,9 @@ void updateKeypairDisabledAndContact(Vertx vertx, VertxTestContext testContext) Instant time = Instant.now(); Map expectedKeypairs = new HashMap<>() {{ - put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, true)); - put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true)); - put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false)); + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); }}; setKeypairs(new ArrayList<>(expectedKeypairs.values())); @@ -481,8 +522,37 @@ void updateKeypairDisabledAndContact(Vertx vertx, VertxTestContext testContext) post(vertx, "api/client_side_keypairs/update", jo.encode(), testContext.succeeding(response -> testContext.verify(() -> { assertEquals(200, response.statusCode()); - ClientSideKeypair expected = new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "updated@email.com", time, false); + ClientSideKeypair expected = new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "updated@email.com", time, false, name1); + validateKeypair(expected, response.bodyAsJsonObject()); + verify(keypairStoreWriter, times(1)).upload(any(), isNull()); + testContext.completeNow(); + }))); + } + + @Test + void updateKeypairDisabledAndName(Vertx vertx, VertxTestContext testContext) throws Exception { + fakeAuth(Role.ADMINISTRATOR); + + Instant time = Instant.now(); + Map expectedKeypairs = new HashMap<>() {{ + put("89aZ234567", new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, true, name1)); + put("9aZ2345678", new ClientSideKeypair("9aZ2345678", pub2, priv2, 123, "test@example.com", Instant.now(), true, name2)); + put("789aZ23456", new ClientSideKeypair("789aZ23456", pub3, priv3, 125, "test-two@example.com", Instant.now(), false, name3)); + }}; + + setKeypairs(new ArrayList<>(expectedKeypairs.values())); + setSites(new Site(123, "test", true)); + + JsonObject jo = new JsonObject(); + jo.put("subscription_id", "89aZ234567"); + jo.put("name", "updated name"); + jo.put("disabled", false); + + post(vertx, "api/client_side_keypairs/update", jo.encode(), testContext.succeeding(response -> testContext.verify(() -> { + assertEquals(200, response.statusCode()); + ClientSideKeypair expected = new ClientSideKeypair("89aZ234567", pub1, priv1, 124, "test-two@example.com", time, false, "updated name"); validateKeypair(expected, response.bodyAsJsonObject()); + verify(keypairStoreWriter, times(1)).upload(any(), isNull()); testContext.completeNow(); }))); } diff --git a/webroot/adm/client-side-keypairs.html b/webroot/adm/client-side-keypairs.html index 15359257..c4d7efd8 100644 --- a/webroot/adm/client-side-keypairs.html +++ b/webroot/adm/client-side-keypairs.html @@ -17,8 +17,8 @@

Inputs

- - + + @@ -76,21 +76,21 @@

Output

$('#doCreate').on('click', function () { const siteId = $('#siteId').val(); - const contact = $('#contact').val(); + const name = $('#name').val(); const disabled = ($('#disable').is(':checked')); if(!siteId) { $('#errorOutput').text("required parameters: site_id") return } - const payload = {"site_id": parseInt(siteId), "contact": contact, "disabled": disabled} + const payload = {"site_id": parseInt(siteId), "name": name, "disabled": disabled} doApiCall('POST', '/api/client_side_keypairs/add', '#standardOutput', '#errorOutput', JSON.stringify(payload)); }); $('#doUpdate').on('click', function () { const subscriptionId = $('#subscriptionId').val() - const contact = $('#contact').val(); + const name = $('#name').val(); const disabled = ($('#disable').is(':checked')); if(!subscriptionId) { @@ -99,8 +99,8 @@

Output

} const payload = {"subscription_id": subscriptionId, "disabled" : disabled} - if(contact){ - payload["contact"] = contact + if(name){ + payload["name"] = name } doApiCall('POST', '/api/client_side_keypairs/update', '#standardOutput', '#errorOutput', JSON.stringify(payload));