Skip to content

Commit 22361f5

Browse files
committed
Add a non-authed test
1 parent d283230 commit 22361f5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
import io.vertx.junit5.VertxTestContext;
1515
import org.junit.jupiter.api.BeforeEach;
1616
import org.junit.jupiter.api.Test;
17+
import org.junit.jupiter.params.ParameterizedTest;
18+
import org.junit.jupiter.params.provider.Arguments;
19+
import org.junit.jupiter.params.provider.MethodSource;
1720
import org.mockito.ArgumentCaptor;
1821

1922
import java.time.Instant;
2023
import java.util.*;
24+
import java.util.stream.Stream;
2125

2226
import static org.junit.jupiter.api.Assertions.*;
2327
import static org.mockito.Mockito.*;
@@ -616,6 +620,42 @@ void deleteKeypair(Vertx vertx, VertxTestContext testContext) throws Exception {
616620
testContext.completeNow();
617621
});
618622
}
623+
624+
private static Stream<Arguments> deleteRoles() {
625+
return Stream.of(
626+
Arguments.of(Role.MAINTAINER, 401, false),
627+
Arguments.of(Role.PRIVILEGED, 200, true),
628+
Arguments.of(Role.SHARING_PORTAL, 200, true)
629+
);
630+
}
631+
632+
@ParameterizedTest
633+
@MethodSource("deleteRoles")
634+
void deleteKeypairAuthorization(Role role, int expectedStatus, boolean shouldSucceed, Vertx vertx, VertxTestContext testContext) throws Exception {
635+
fakeAuth(role);
636+
637+
Instant time = Instant.now();
638+
ClientSideKeypair keypairToDelete = new ClientSideKeypair("CC12345678", pub1, priv1, 222, "[email protected]", time, false, name1);
639+
ClientSideKeypair remainingKeypair = new ClientSideKeypair("DD12345678", pub2, priv2, 222, "[email protected]", time, false, name2);
640+
641+
setKeypairs(List.of(keypairToDelete, remainingKeypair));
642+
setSites(new Site(222, "test", true));
643+
644+
JsonObject jo = new JsonObject().put("subscription_id", "CC12345678");
645+
646+
post(vertx, testContext, "api/client_side_keypairs/delete", jo.encode(), response -> {
647+
assertEquals(expectedStatus, response.statusCode());
648+
649+
if (shouldSucceed) {
650+
assertTrue(response.bodyAsJsonObject().getBoolean("success"));
651+
validateKeypair(keypairToDelete, "test", response.bodyAsJsonObject().getJsonObject("deleted_keypair"));
652+
verify(keypairStoreWriter, times(1)).upload(collectionOfSize(1), isNull());
653+
} else {
654+
verify(keypairStoreWriter, times(0)).upload(any(), isNull());
655+
}
656+
testContext.completeNow();
657+
});
658+
}
619659
}
620660

621661

0 commit comments

Comments
 (0)