CertificateUtils { public boolean hasAddOrRemovePermission(UserDetails userDetails, SSLCertificateMetadataDetails certificateMetaData) { if (ObjectUtils.isEmpty(certificateMetaData)) { return false; } if (userDetails.isAdmin()) { return checkIfCertificateAdmin(userDetails, certificateMetaData); } else { return checkIfNonCertificateAdmin(userDetails, certificateMetaData); } }  boolean hasAddOrRemovePermission(UserDetails userDetails, SSLCertificateMetadataDetails certificateMetaData); SSLCertificateMetadataDetails getCertificateMetaData(String token, String certificateName, String certificateType);  }
@Test public void testHasAddOrRemovePermissionForAdminSuccessfully() { UserDetails userDetails = getMockUser(true); userDetails.setUsername(ADMIN_USER); SSLCertificateMetadataDetails certificateMetadata = getSSLCertificateMetadataDetails(); boolean canAdd = certificateUtils.hasAddOrRemovePermission(userDetails, certificateMetadata); assertTrue(canAdd); }
@Test public void testHasAddOrRemovePermissionForAdminFailed() { UserDetails userDetails = getMockUser(true); SSLCertificateMetadataDetails certificateMetadata = getSSLCertificateMetadataDetails(); boolean canAdd = certificateUtils.hasAddOrRemovePermission(userDetails, certificateMetadata); assertFalse(canAdd); }
@Test public void testHasAddOrRemovePermissionForAdminIfEmptyOwner() { UserDetails userDetails = getMockUser(true); SSLCertificateMetadataDetails certificateMetadata = getSSLCertificateMetadataDetails(); certificateMetadata.setCertOwnerNtid(null); boolean canAdd = certificateUtils.hasAddOrRemovePermission(userDetails, certificateMetadata); assertTrue(canAdd); }
@Test public void testHasAddOrRemovePermissionForNonAdminSuccessfully() { UserDetails userDetails = getMockUser(false); userDetails.setUsername(ADMIN_USER); SSLCertificateMetadataDetails certificateMetadata = getSSLCertificateMetadataDetails(); boolean canAdd = certificateUtils.hasAddOrRemovePermission(userDetails, certificateMetadata); assertTrue(canAdd); }
@Test public void testHasAddOrRemovePermissionForNonAdminFailed() { UserDetails userDetails = getMockUser(false); SSLCertificateMetadataDetails certificateMetadata = getSSLCertificateMetadataDetails(); boolean canAdd = certificateUtils.hasAddOrRemovePermission(userDetails, certificateMetadata); assertFalse(canAdd); }
@Test public void testHasAddOrRemovePermissionForEmptyMetadata() { UserDetails userDetails = getMockUser(false); SSLCertificateMetadataDetails certificateMetadata = null; boolean canAdd = certificateUtils.hasAddOrRemovePermission(userDetails, certificateMetadata); assertFalse(canAdd); }