PKI revamp: general improvements

This commit is contained in:
Carlos Monastyrski
2025-10-17 15:47:41 -03:00
parent 4f23e6dc53
commit e195afba11
34 changed files with 601 additions and 579 deletions
@@ -559,7 +559,6 @@ describe("CertificateProfileService", () => {
expect(result).toEqual(sampleProfile);
expect(mockCertificateProfileDAL.findById).toHaveBeenCalledWith("profile-123");
expect(mockCertificateProfileDAL.isProfileInUse).toHaveBeenCalledWith("profile-123");
expect(mockCertificateProfileDAL.deleteById).toHaveBeenCalledWith("profile-123");
});
@@ -573,18 +572,6 @@ describe("CertificateProfileService", () => {
})
).rejects.toThrow(NotFoundError);
});
it("should throw ForbiddenRequestError when profile is in use", async () => {
(mockCertificateProfileDAL.isProfileInUse as any).mockResolvedValue(true);
await expect(
service.deleteProfile({
...mockActor,
profileId: "profile-123"
})
).rejects.toThrow(ForbiddenRequestError);
expect(mockCertificateProfileDAL.deleteById).not.toHaveBeenCalled();
});
});
describe("getProfileCertificates", () => {
@@ -841,23 +828,8 @@ describe("CertificateProfileService", () => {
expect(result.enrollmentType).toBe(EnrollmentType.EST);
});
it("should prevent deletion of profiles with active certificates", async () => {
it("should allow deletion of profiles", async () => {
(mockCertificateProfileDAL.findById as any).mockResolvedValue(sampleProfile);
(mockCertificateProfileDAL.isProfileInUse as any).mockResolvedValue(true);
await expect(
service.deleteProfile({
...mockActor,
profileId: "profile-123"
})
).rejects.toThrow(ForbiddenRequestError);
expect(mockCertificateProfileDAL.deleteById).not.toHaveBeenCalled();
});
it("should allow deletion of unused profiles", async () => {
(mockCertificateProfileDAL.findById as any).mockResolvedValue(sampleProfile);
(mockCertificateProfileDAL.isProfileInUse as any).mockResolvedValue(false);
(mockCertificateProfileDAL.deleteById as any).mockResolvedValue(sampleProfile);
const result = await service.deleteProfile({
@@ -866,7 +838,6 @@ describe("CertificateProfileService", () => {
});
expect(result).toEqual(sampleProfile);
expect(mockCertificateProfileDAL.isProfileInUse).toHaveBeenCalledWith("profile-123");
expect(mockCertificateProfileDAL.deleteById).toHaveBeenCalledWith("profile-123");
});
});
@@ -116,7 +116,7 @@ export const certificateProfileServiceFactory = ({
const existingSlugProfile = await certificateProfileDAL.findBySlugAndProjectId(data.slug, projectId);
if (existingSlugProfile) {
throw new ForbiddenRequestError({
message: "Certificate profile with this slug already exists in project"
message: "Certificate profile with this name already exists in project"
});
}
@@ -245,7 +245,7 @@ export const certificateProfileServiceFactory = ({
);
if (conflictingProfile && conflictingProfile.id !== profileId) {
throw new ForbiddenRequestError({
message: "Certificate profile with this slug already exists in project"
message: "Certificate profile with this name already exists in project"
});
}
}
@@ -521,14 +521,6 @@ export const certificateProfileServiceFactory = ({
ProjectPermissionSub.CertificateProfiles
);
// Check if profile is in use by any certificates
const isInUse = await certificateProfileDAL.isProfileInUse(profileId);
if (isInUse) {
throw new ForbiddenRequestError({
message: "Cannot delete certificate profile that has issued certificates"
});
}
const deletedProfile = await certificateProfileDAL.deleteById(profileId);
if (!deletedProfile) {
throw new NotFoundError({ message: "Failed to delete certificate profile" });