Skip to content

Commit

Permalink
Fix ClientKeyServiceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
cYKatherine committed Oct 25, 2023
1 parent 905b299 commit d1fb6c7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/test/java/com/uid2/admin/vertx/ClientKeyServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void clientAdd(Vertx vertx, VertxTestContext testContext) {
fakeAuth(Role.CLIENTKEY_ISSUER);

LegacyClientKey expectedClient = new LegacyClientBuilder().withServiceId(145).build();
post(vertx, testContext, "api/client/add?name=test_client&roles=generator&site_id=5&service_id=145", "", response -> {
post(vertx, testContext, "api/client/add?name=test_client&roles=generator&site_id=999&service_id=145", "", response -> {
RevealedKey<ClientKey> revealedClient = OBJECT_MAPPER.readValue(response.bodyAsString(), new TypeReference<>() {});

assertAll(
Expand All @@ -98,7 +98,7 @@ public void clientAdd(Vertx vertx, VertxTestContext testContext) {
public void clientAddCreatesSiteKeyIfNoneExists(Set<Role> roles, boolean siteKeyShouldBeCreatedIfNoneExists, Vertx vertx, VertxTestContext testContext) {
fakeAuth(Role.CLIENTKEY_ISSUER);

String endpoint = String.format("api/client/add?name=test_client&site_id=5&roles=%s", RequestUtil.getRolesSpec(roles));
String endpoint = String.format("api/client/add?name=test_client&site_id=999&roles=%s", RequestUtil.getRolesSpec(roles));
post(vertx, testContext, endpoint, "", response -> {
assertAll(
"clientAddCreatesSiteKeyIfNoneExists",
Expand Down Expand Up @@ -147,7 +147,7 @@ public void clientUpdate(Vertx vertx, VertxTestContext testContext) {
fakeAuth(Role.CLIENTKEY_ISSUER);
setClientKeys(new LegacyClientBuilder().withServiceId(165).build());

post(vertx, testContext, "api/client/update?name=test_client&site_id=5&service_id=200", "", response -> {
post(vertx, testContext, "api/client/update?name=test_client&site_id=999&service_id=200", "", response -> {
ClientKey expected = new LegacyClientBuilder().withServiceId(200).build().toClientKey();
assertAll(
"clientUpdate",
Expand All @@ -171,7 +171,7 @@ public void clientUpdateCreatesSiteKeyIfNoneExists(Set<Role> roles, boolean site
.build()
);

post(vertx, testContext, "api/client/update?name=test_client&site_id=5&service_id=145", "", response -> {
post(vertx, testContext, "api/client/update?name=test_client&site_id=999&service_id=145", "", response -> {
assertAll(
"clientUpdateCreatesSiteKeyIfNoneExists",
() -> assertEquals(200, response.statusCode()),
Expand All @@ -189,7 +189,7 @@ public void clientUpdateCreatesSiteKeyIfNoneExists(Set<Role> roles, boolean site
@Test
public void clientUpdateUnknownClientName(Vertx vertx, VertxTestContext testContext) {
fakeAuth(Role.CLIENTKEY_ISSUER);
post(vertx, testContext, "api/client/update?name=test_client&site_id=5", "", expectHttpStatus(testContext, 404));
post(vertx, testContext, "api/client/update?name=test_client&site_id=999", "", expectHttpStatus(testContext, 404));
}

@Test
Expand Down Expand Up @@ -247,6 +247,7 @@ private static class LegacyClientBuilder {
private int siteId = 999;
private Set<Role> roles = Set.of(Role.GENERATOR);
private int serviceId = 0;
private String keyId = "UID2-C-L-999-abcde";

public LegacyClientBuilder withName(String name) {
this.name = name;
Expand All @@ -268,6 +269,11 @@ public LegacyClientBuilder withServiceId(int serviceId) {
return this;
}

public LegacyClientBuilder withKeyId(String keyId) {
this.keyId = keyId;
return this;
}

public LegacyClientKey build() {
return new LegacyClientKey(
"UID2-C-L-999-abcdeM.fsR3mDqAXELtWWMS+xG1s7RdgRTMqdOH2qaAo=",
Expand All @@ -281,7 +287,7 @@ public LegacyClientKey build() {
siteId,
false,
serviceId,
"UID2-C-L-999-abcde"
keyId
);
}
}
Expand Down

0 comments on commit d1fb6c7

Please sign in to comment.