Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Oct 17, 2024
1 parent 508c651 commit 7ec3ad0
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions backend/src/test/java/org/cryptomator/hub/api/VaultResourceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,10 @@ public void testUnlock() {
when().get("/vaults/{vaultId}/access-token", "7E57C0DE-0000-4000-8000-000100001111")
.then().statusCode(449);
}
}

@Nested
@DisplayName("As vault admin user1")
@TestSecurity(user = "User Name 1", roles = {"create-vaults"})
@OidcSecurity(claims = {
@Claim(key = "sub", value = "user1")
})
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class CreateVaults {

@Test
@Order(1)
@TestSecurity(user = "User Name 1", roles = {"user"})
@DisplayName("PUT /vaults/7E57C0DE-0000-4000-8000-000100003333 returns 403 for missing role")
public void testCreteVaultWithMissingRole() {
public void testCreateVaultWithMissingRole() {
var uuid = UUID.fromString("7E57C0DE-0000-4000-8000-000100003333");
var vaultDto = new VaultResource.VaultDto(uuid, "My Vault", "Test vault 3", false, Instant.parse("2112-12-21T21:12:21Z"), "masterkey3", 42, "NaCl", "authPubKey3", "authPrvKey3");

Expand All @@ -265,6 +253,17 @@ public void testCreteVaultWithMissingRole() {
.then().statusCode(403);
}

}

@Nested
@DisplayName("As vault admin user1")
@TestSecurity(user = "User Name 1", roles = {"user", "create-vaults"})
@OidcSecurity(claims = {
@Claim(key = "sub", value = "user1")
})
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class CreateVaults {

@Test
@Order(1)
@DisplayName("PUT /vaults/7E57C0DE-0000-4000-8000-000100003333 returns 201")
Expand Down Expand Up @@ -845,7 +844,7 @@ public void reset() throws SQLException {

@Nested
@DisplayName("Claim Ownership")
@TestSecurity(user = "User Name 1", roles = {"create-vaults"})
@TestSecurity(user = "User Name 1", roles = {"user"})
@OidcSecurity(claims = {
@Claim(key = "sub", value = "user1")
})
Expand Down Expand Up @@ -1007,23 +1006,6 @@ public void testClaimOwnershipNoSuchVault() {
.then().statusCode(404);
}

@Test
@Order(1)
@TestSecurity(user = "User Name 1", roles = {"user"})
@DisplayName("POST /vaults/7E57C0DE-0000-4000-8000-000100009999/claim-ownership returns 403 for missing role")
public void testClaimOwnershipWithMissingRole() {
var proof = JWT.create()
.withNotBefore(Instant.now().minusSeconds(10))
.withExpiresAt(Instant.now().plusSeconds(10))
.withSubject("user1")
.withClaim("vaultId", "7E57C0DE-0000-4000-8000-000100009999".toLowerCase())
.sign(JWT_ALG);

given().param("proof", proof)
.when().post("/vaults/{vaultId}/claim-ownership", "7E57C0DE-0000-4000-8000-000100009999")
.then().statusCode(403);
}

@Test
@Order(2)
@DisplayName("POST /vaults/7E57C0DE-0000-4000-8000-000100009999/claim-ownership returns 200")
Expand Down

0 comments on commit 7ec3ad0

Please sign in to comment.