/** * Verifies that the service updates tenants for a given tenantId. * * @param ctx The vert.x test context. */ @Test public void testUpdateTenantsSucceeds(final TestContext ctx) { final JsonObject updatedPayload = buildTenantPayload("tenant"); updatedPayload.put("custom-prop", "something"); addTenant("tenant").compose(ok -> { final Future<TenantResult<JsonObject>> updateResult = Future.future(); getCompleteTenantService().update("tenant", updatedPayload.copy(), updateResult.completer()); return updateResult; }).compose(updateResult -> { ctx.assertEquals(HttpURLConnection.HTTP_NO_CONTENT, updateResult.getStatus()); final Future<TenantResult<JsonObject>> getResult = Future.future(); getCompleteTenantService().get("tenant", null, getResult.completer()); return getResult; }).setHandler(ctx.asyncAssertSuccess(getResult -> { assertThat(getResult.getStatus(), is(HttpURLConnection.HTTP_OK)); assertThat(getResult.getPayload().getString("custom-prop"), is("something")); })); }
/** * Verifies that a tenant cannot be updated to use a trusted certificate authority * with the same subject DN as another tenant. * * @param ctx The vert.x test context. */ @Test public void testUpdateTenantFailsForDuplicateCa(final TestContext ctx) { // GIVEN two tenants, one with a CA configured, the other with no CA final JsonObject trustedCa = new JsonObject() .put(TenantConstants.FIELD_PAYLOAD_SUBJECT_DN, "CN=taken") .put(TenantConstants.FIELD_PAYLOAD_PUBLIC_KEY, "NOTAKEY"); final TenantObject tenantOne = TenantObject.from("tenantOne", true) .setProperty(TenantConstants.FIELD_PAYLOAD_TRUSTED_CA, trustedCa); final TenantObject tenantTwo = TenantObject.from("tenantTwo", true); addTenant("tenantOne", JsonObject.mapFrom(tenantOne)) .compose(ok -> addTenant("tenantTwo", JsonObject.mapFrom(tenantTwo))) .map(ok -> { // WHEN updating the second tenant to use the same CA as the first tenant tenantTwo.setProperty(TenantConstants.FIELD_PAYLOAD_TRUSTED_CA, trustedCa); getCompleteTenantService().update( "tenantTwo", JsonObject.mapFrom(tenantTwo), ctx.asyncAssertSuccess(s -> { // THEN the update fails with a 409 ctx.assertEquals(HttpURLConnection.HTTP_CONFLICT, s.getStatus()); })); return null; }); }