Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.UUID;

@RestController
@RequestMapping("/ap1/v1/projects/{projectId}/credentials")
@RequestMapping("/api/v1/projects/{projectId}/credentials")
public class CredentialController implements CredentialApi{

private final CreateCredentialUseCase createCredentialUseCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Arrays;

@RestController
@RequestMapping("/ap1/v1/security")
@RequestMapping("/api/v1/security")
public class SecurityController implements SecurityApi{

private final SetupMasterPasswordUseCase setupMasterPasswordUseCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void createCredential_shouldReturnCreated_whenLoginRequestIsValid() throws Excep
}
""";

mockMvc.perform(post("/ap1/v1/projects/{projectId}/credentials", savedProject.getId())
mockMvc.perform(post("/api/v1/projects/{projectId}/credentials", savedProject.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isCreated())
Expand Down Expand Up @@ -133,7 +133,7 @@ void createCredential_shouldReturnCreated_whenApiKeyRequestIsValid() throws Exce
}
""";

mockMvc.perform(post("/ap1/v1/projects/{projectId}/credentials", savedProject.getId())
mockMvc.perform(post("/api/v1/projects/{projectId}/credentials", savedProject.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isCreated())
Expand All @@ -151,7 +151,7 @@ void createCredential_shouldReturnCreated_whenRawTextRequestIsValid() throws Exc
}
""";

mockMvc.perform(post("/ap1/v1/projects/{projectId}/credentials", savedProject.getId())
mockMvc.perform(post("/api/v1/projects/{projectId}/credentials", savedProject.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isCreated())
Expand All @@ -169,7 +169,7 @@ void createCredential_shouldReturnBadRequest_whenSecretFieldsAreMissingForLogin(
}
""";

mockMvc.perform(post("/ap1/v1/projects/{projectId}/credentials", savedProject.getId())
mockMvc.perform(post("/api/v1/projects/{projectId}/credentials", savedProject.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isBadRequest())
Expand All @@ -188,7 +188,7 @@ void createCredential_shouldReturnBadRequest_whenTitleIsTooShort() throws Except
}
""";

mockMvc.perform(post("/ap1/v1/projects/{projectId}/credentials", savedProject.getId())
mockMvc.perform(post("/api/v1/projects/{projectId}/credentials", savedProject.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isBadRequest())
Expand All @@ -208,7 +208,7 @@ void createCredential_shouldReturnNotFound_whenProjectDoesNotExist() throws Exce
}
""";

mockMvc.perform(post("/ap1/v1/projects/{projectId}/credentials", nonExistentProjectId)
mockMvc.perform(post("/api/v1/projects/{projectId}/credentials", nonExistentProjectId)
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isNotFound())
Expand All @@ -227,7 +227,7 @@ void createCredential_shouldReturnLocked_whenVaultIsLocked() throws Exception {
}
""";

mockMvc.perform(post("/ap1/v1/projects/{projectId}/credentials", savedProject.getId())
mockMvc.perform(post("/api/v1/projects/{projectId}/credentials", savedProject.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isLocked())
Expand All @@ -246,7 +246,7 @@ void createCredential_shouldReturnForbidden_whenSetupIsRequired() throws Excepti
}
""";

mockMvc.perform(post("/ap1/v1/projects/{projectId}/credentials", savedProject.getId())
mockMvc.perform(post("/api/v1/projects/{projectId}/credentials", savedProject.getId())
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isForbidden())
Expand Down Expand Up @@ -284,7 +284,7 @@ void getAllCredentials_shouldReturnPagedSummaries() throws Exception {
credentialRepository.save(c1);
credentialRepository.save(c2);

mockMvc.perform(get("/ap1/v1/projects/{projectId}/credentials", savedProject.getId())
mockMvc.perform(get("/api/v1/projects/{projectId}/credentials", savedProject.getId())
.param("page", "0")
.param("size", "5"))
.andExpect(status().isOk())
Expand Down Expand Up @@ -316,7 +316,7 @@ void getCredentialById_shouldReturnDecryptedCredential() throws Exception {
entity.setCreatedAt(LocalDateTime.now());
credentialRepository.save(entity);

mockMvc.perform(get("/ap1/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), credentialId))
mockMvc.perform(get("/api/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), credentialId))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(credentialId.toString()))
.andExpect(jsonPath("$.title").value("Get Credential"))
Expand All @@ -329,7 +329,7 @@ void getCredentialById_shouldReturnDecryptedCredential() throws Exception {
void getCredentialById_shouldReturnNotFound_whenCredentialDoesNotExist() throws Exception {
UUID nonExistentId = UUID.randomUUID();

mockMvc.perform(get("/ap1/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), nonExistentId))
mockMvc.perform(get("/api/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), nonExistentId))
.andExpect(status().isNotFound())
.andExpect(jsonPath("$.message").value("Credential not found with identifier " + nonExistentId));
}
Expand Down Expand Up @@ -360,7 +360,7 @@ void getCredentialById_shouldReturnNotFound_whenCredentialDoesNotBelongToProject
credentialRepository.save(entity);

// Fetch using savedProject's ID (not otherProject's ID)
mockMvc.perform(get("/ap1/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), credentialId))
mockMvc.perform(get("/api/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), credentialId))
.andExpect(status().isNotFound())
.andExpect(jsonPath("$.message").value("Credential not found with identifier " + credentialId));
}
Expand Down Expand Up @@ -393,7 +393,7 @@ void updateCredential_shouldUpdateTitleAndMetadataOnly_whenNoPayloadProvided() t
}
""";

mockMvc.perform(patch("/ap1/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), credentialId)
mockMvc.perform(patch("/api/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), credentialId)
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isOk())
Expand Down Expand Up @@ -440,7 +440,7 @@ void updateCredential_shouldUpdatePayloadAndReencrypt_whenNewPayloadProvided() t
}
""";

mockMvc.perform(patch("/ap1/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), credentialId)
mockMvc.perform(patch("/api/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), credentialId)
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isOk())
Expand Down Expand Up @@ -481,7 +481,7 @@ void deleteCredential_shouldRemoveCredentialAndReturnNoContent() throws Exceptio
entity.setCreatedAt(LocalDateTime.now());
credentialRepository.save(entity);

mockMvc.perform(delete("/ap1/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), credentialId))
mockMvc.perform(delete("/api/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), credentialId))
.andExpect(status().isNoContent());

assertFalse(credentialRepository.existsById(credentialId));
Expand All @@ -491,7 +491,7 @@ void deleteCredential_shouldRemoveCredentialAndReturnNoContent() throws Exceptio
void deleteCredential_shouldReturnNotFound_whenCredentialDoesNotExist() throws Exception {
UUID nonExistentId = UUID.randomUUID();

mockMvc.perform(delete("/ap1/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), nonExistentId))
mockMvc.perform(delete("/api/v1/projects/{projectId}/credentials/{credentialId}", savedProject.getId(), nonExistentId))
.andExpect(status().isNotFound())
.andExpect(jsonPath("$.message").value("Credential not found with identifier " + nonExistentId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void setupMasterPassword_shouldReturnNoContent_whenFirstTime() throws Exception
}
""";

mockMvc.perform(post("/ap1/v1/security/master-password")
mockMvc.perform(post("/api/v1/security/master-password")
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isNoContent());
Expand All @@ -64,7 +64,7 @@ void setupMasterPassword_shouldReturnBadRequest_whenPasswordTooShort() throws Ex
}
""";

mockMvc.perform(post("/ap1/v1/security/master-password")
mockMvc.perform(post("/api/v1/security/master-password")
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isBadRequest())
Expand All @@ -87,7 +87,7 @@ void setupMasterPassword_shouldReturnConflict_whenAlreadyConfigured() throws Exc
}
""";

mockMvc.perform(post("/ap1/v1/security/master-password")
mockMvc.perform(post("/api/v1/security/master-password")
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isConflict())
Expand All @@ -96,7 +96,7 @@ void setupMasterPassword_shouldReturnConflict_whenAlreadyConfigured() throws Exc

@Test
void checkMasterPasswordSetup_shouldReturnTrue_whenNotConfigured() throws Exception {
mockMvc.perform(get("/ap1/v1/security/master-password/required-status"))
mockMvc.perform(get("/api/v1/security/master-password/required-status"))
.andExpect(status().isOk())
.andExpect(content().string("true"));
}
Expand All @@ -106,14 +106,14 @@ void checkMasterPasswordSetup_shouldReturnFalse_whenAlreadyConfigured() throws E
appSettingRepository.save(new AppSettingEntity("master_password_hash", "mockHash"));
appSettingRepository.save(new AppSettingEntity("master_password_salt", "mockSalt"));

mockMvc.perform(get("/ap1/v1/security/master-password/required-status"))
mockMvc.perform(get("/api/v1/security/master-password/required-status"))
.andExpect(status().isOk())
.andExpect(content().string("false"));
}

@Test
void getSessionStatus_shouldReturnInactiveAndZeroSeconds_whenLocked() throws Exception {
mockMvc.perform(get("/ap1/v1/security/vault/status"))
mockMvc.perform(get("/api/v1/security/vault/status"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.active").value(false))
.andExpect(jsonPath("$.secondsLeft").value(0));
Expand All @@ -123,7 +123,7 @@ void getSessionStatus_shouldReturnInactiveAndZeroSeconds_whenLocked() throws Exc
void getSessionStatus_shouldReturnActiveAndRemainingSeconds_whenUnlocked() throws Exception {
masterKeySessionPort.setKey(new SecretKeySpec(new byte[32], "AES"));

mockMvc.perform(get("/ap1/v1/security/vault/status"))
mockMvc.perform(get("/api/v1/security/vault/status"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.active").value(true))
.andExpect(jsonPath("$.secondsLeft").value(greaterThan(0)));
Expand All @@ -138,7 +138,7 @@ void unlockVault_shouldReturnTrue_whenPasswordIsCorrect() throws Exception {
}
""";

mockMvc.perform(post("/ap1/v1/security/master-password")
mockMvc.perform(post("/api/v1/security/master-password")
.contentType(MediaType.APPLICATION_JSON)
.content(setupJson))
.andExpect(status().isNoContent());
Expand All @@ -154,7 +154,7 @@ void unlockVault_shouldReturnTrue_whenPasswordIsCorrect() throws Exception {
}
""";

mockMvc.perform(post("/ap1/v1/security/vault/unlock")
mockMvc.perform(post("/api/v1/security/vault/unlock")
.contentType(MediaType.APPLICATION_JSON)
.content(unlockJson))
.andExpect(status().isOk())
Expand All @@ -172,7 +172,7 @@ void unlockVault_shouldReturnUnauthorized_whenPasswordIsWrong() throws Exception
}
""";

mockMvc.perform(post("/ap1/v1/security/master-password")
mockMvc.perform(post("/api/v1/security/master-password")
.contentType(MediaType.APPLICATION_JSON)
.content(setupJson))
.andExpect(status().isNoContent());
Expand All @@ -186,7 +186,7 @@ void unlockVault_shouldReturnUnauthorized_whenPasswordIsWrong() throws Exception
}
""";

mockMvc.perform(post("/ap1/v1/security/vault/unlock")
mockMvc.perform(post("/api/v1/security/vault/unlock")
.contentType(MediaType.APPLICATION_JSON)
.content(unlockJson))
.andExpect(status().isUnauthorized())
Expand All @@ -203,7 +203,7 @@ void unlockVault_shouldReturnForbidden_whenNotConfigured() throws Exception {
}
""";

mockMvc.perform(post("/ap1/v1/security/vault/unlock")
mockMvc.perform(post("/api/v1/security/vault/unlock")
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isForbidden())
Expand All @@ -218,7 +218,7 @@ void unlockVault_shouldReturnBadRequest_whenPasswordTooShort() throws Exception
}
""";

mockMvc.perform(post("/ap1/v1/security/vault/unlock")
mockMvc.perform(post("/api/v1/security/vault/unlock")
.contentType(MediaType.APPLICATION_JSON)
.content(json))
.andExpect(status().isBadRequest())
Expand All @@ -231,7 +231,7 @@ void lockVault_shouldClearSessionAndReturnNoContent() throws Exception {
masterKeySessionPort.setKey(new SecretKeySpec(new byte[32], "AES"));
assertTrue(masterKeySessionPort.hasKey());

mockMvc.perform(post("/ap1/v1/security/vault/lock"))
mockMvc.perform(post("/api/v1/security/vault/lock"))
.andExpect(status().isNoContent());

assertFalse(masterKeySessionPort.hasKey());
Expand Down
Loading