|
14 | 14 | import io.vertx.junit5.VertxTestContext; |
15 | 15 | import org.junit.jupiter.api.BeforeEach; |
16 | 16 | 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; |
17 | 20 | import org.mockito.ArgumentCaptor; |
18 | 21 |
|
19 | 22 | import java.time.Instant; |
20 | 23 | import java.util.*; |
| 24 | +import java.util.stream.Stream; |
21 | 25 |
|
22 | 26 | import static org.junit.jupiter.api.Assertions.*; |
23 | 27 | import static org.mockito.Mockito.*; |
@@ -616,6 +620,42 @@ void deleteKeypair(Vertx vertx, VertxTestContext testContext) throws Exception { |
616 | 620 | testContext.completeNow(); |
617 | 621 | }); |
618 | 622 | } |
| 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 | + } |
619 | 659 | } |
620 | 660 |
|
621 | 661 |
|
0 commit comments