diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationServiceImpl.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationServiceImpl.java index d56cdea2..c4625135 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationServiceImpl.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationServiceImpl.java @@ -479,7 +479,7 @@ public class SupplyChainValidationServiceImpl implements SupplyChainValidationSe if (passed && supportReferenceManifest == null) { fwStatus = new AppraisalStatus(FAIL, - "Support Reference Integrity Manifest can not be found\n"); + "Support Reference Integrity Manifest can not be found"); passed = false; } diff --git a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageControllerTest.java b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageControllerTest.java deleted file mode 100644 index 17b5187d..00000000 --- a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageControllerTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package hirs.attestationca.portal.page.controllers; - -import hirs.data.persist.BaseReferenceManifest; -import hirs.data.persist.ReferenceManifest; -import hirs.persist.DBReferenceManifestManager; -import hirs.attestationca.portal.page.Page; -import hirs.attestationca.portal.page.PageController; -import hirs.attestationca.portal.page.PageControllerTest; -import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.Files; -import java.util.Map; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasProperty; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.web.servlet.MvcResult; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * Integration tests that test the URL End Points of - * EndorsementKeyCredentialsPageController. - */ -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -public class ReferenceManifestDetailsPageControllerTest extends PageControllerTest { - - private static final String GOOD_RIM_FILE = "/rims/generated_good.swidtag"; - private static final String ID = "046b6c7f-0b8a-43b9-b35d-6489e6daee91"; - - @Autowired - private DBReferenceManifestManager referenceManifestManager; - private ReferenceManifest referenceManifest; - - - /** - * Prepares tests. - * - * @throws IOException if test resources are not found - */ - @BeforeClass - public void prepareTests() throws IOException { - Path fPath; - try { - fPath = Paths.get(this.getClass().getResource(GOOD_RIM_FILE).toURI()); - } catch (URISyntaxException e) { - throw new IOException("Could not resolve path URI", e); - } - referenceManifest = new BaseReferenceManifest(Files.readAllBytes(fPath)); - referenceManifestManager.save(referenceManifest); - } - - /** - * Constructor. - */ - public ReferenceManifestDetailsPageControllerTest() { - super(Page.RIM_DETAILS); - } - - /** - * Tests initial page when the Reference Integrity Manifest - * was not found. - * @throws Exception if an exception occurs - */ - @Test - public void testInitPage() throws Exception { - // Get error message - getMockMvc() - .perform(MockMvcRequestBuilders.get("/" + getPage().getViewName()) - .param("id", ID)) - .andExpect(status().isOk()) - .andExpect(model().attribute(PageController.MESSAGES_ATTRIBUTE, - hasProperty("error", hasItem("Unable to find RIM with ID: " + ID)))) - .andReturn(); - } - - /** - * Tests initial page for an Reference Integrity Manifest. - * - * @throws Exception if an exception occurs - */ - @Test - @Rollback - @SuppressWarnings("unchecked") - public void testInitPageRim() throws Exception { - MvcResult result = getMockMvc() - .perform(MockMvcRequestBuilders.get("/" + getPage().getViewName()) - .param("id", referenceManifest.getId().toString()) - .param("swidTagId", referenceManifest.getTagId())) - .andExpect(status().isOk()) - .andExpect(model().attributeExists(PolicyPageController.INITIAL_DATA)) - .andReturn(); - - // Obtain initialData HashMap - Map initialData = (Map) result - .getModelAndView() - .getModel() - .get(PolicyPageController.INITIAL_DATA); - Assert.assertEquals(initialData.get("swidTagId"), referenceManifest.getTagId()); - } -} diff --git a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageControllerTest.java b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageControllerTest.java deleted file mode 100644 index 16208c99..00000000 --- a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageControllerTest.java +++ /dev/null @@ -1,191 +0,0 @@ -package hirs.attestationca.portal.page.controllers; - -import hirs.data.persist.BaseReferenceManifest; -import hirs.data.persist.ReferenceManifest; -import hirs.persist.ReferenceManifestManager; -import hirs.attestationca.portal.page.Page; -import hirs.attestationca.portal.page.PageControllerTest; -import hirs.attestationca.portal.page.PageMessages; -import java.io.IOException; -import java.util.Set; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.ClassPathResource; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.web.servlet.MvcResult; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.springframework.web.servlet.FlashMap; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -/** - * Integration tests that test the URL End Points of - * ReferenceManifestPageController. - */ -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -public class ReferenceManifestPageControllerTest extends PageControllerTest { - - private static final String GOOD_RIM_FILE = "generated_good.swidtag"; - private static final String BAD_RIM_FILE = "generated_bad.swidtag"; - - @Autowired - private ReferenceManifestManager referenceManifestManager; - private MockMultipartFile validRimFile; - private MockMultipartFile nonValidRimFile; - - /** - * Constructor. - */ - public ReferenceManifestPageControllerTest() { - super(Page.REFERENCE_MANIFESTS); - } - - /** - * Prepares tests. - * - * @throws IOException if test resources are not found - */ - @BeforeMethod - public void prepareTests() throws IOException { - // create a multi part file for the controller upload - validRimFile = new MockMultipartFile("file", GOOD_RIM_FILE, "", - new ClassPathResource("rims/" + GOOD_RIM_FILE).getInputStream()); - nonValidRimFile = new MockMultipartFile("file", BAD_RIM_FILE, "", - new ClassPathResource("rims/" + BAD_RIM_FILE).getInputStream()); - } - - private void archiveTestCert(final ReferenceManifest referenceManifest) throws Exception { - // now, archive the record - getMockMvc().perform(MockMvcRequestBuilders - .post("/reference-manifests/delete") - .param("id", referenceManifest.getId().toString())) - .andExpect(status().is3xxRedirection()) - .andReturn(); - - Set records - = referenceManifestManager.get(BaseReferenceManifest - .select(referenceManifestManager).includeArchived()); - Assert.assertEquals(records.size(), 1); - - Assert.assertTrue(records.iterator().next().isArchived()); - } - - /** - * Tests uploading a RIM that is a Reference Integrity Manifest, and - * archiving it. - * - * @throws Exception if an exception occurs - */ - @Test - @Rollback - public void uploadAndArchiveValidRim() throws Exception { - ReferenceManifest rim = uploadTestRim(); - archiveTestRim(rim); - } - - /** - * Tests uploading a rim that is not a valid Reference Integrity Manifest, - * which results in failure. - * - * @throws Exception if an exception occurs - */ - @Test - @Rollback - public void uploadNonValidRim() throws Exception { - MvcResult result = getMockMvc().perform(MockMvcRequestBuilders - .fileUpload("/reference-manifests/upload") - .file(nonValidRimFile)) - .andExpect(status().is3xxRedirection()) - .andReturn(); - - // verify redirection messages - FlashMap flashMap = result.getFlashMap(); - PageMessages pageMessages = (PageMessages) flashMap.get("messages"); - Assert.assertEquals(pageMessages.getSuccess().size(), 0); - Assert.assertEquals(pageMessages.getError().size(), 1); - } - - /** - * Tests that uploading a RIM when an identical RIM is archived will cause - * the existing RIM to be unarchived and updated. - * - * @throws Exception if an exception occurs - */ - @Test - @Rollback - public void uploadCausesUnarchive() throws Exception { - ReferenceManifest rim = uploadTestRim(); - archiveTestCert(rim); - - // upload the same cert again - MvcResult result = getMockMvc().perform(MockMvcRequestBuilders - .fileUpload("/reference-manifests/upload") - .file(validRimFile)) - .andExpect(status().is3xxRedirection()) - .andReturn(); - - // verify redirection messages - FlashMap flashMap = result.getFlashMap(); - PageMessages pageMessages = (PageMessages) flashMap.get("messages"); - Assert.assertEquals(pageMessages.getSuccess().size(), 1); - Assert.assertEquals(pageMessages.getError().size(), 0); - Assert.assertEquals(pageMessages.getSuccess().get(0), - "Pre-existing RIM found and unarchived (generated_good.swidtag): "); - - // verify the cert was actually stored - Set records = referenceManifestManager.get(BaseReferenceManifest.select( - referenceManifestManager)); - Assert.assertEquals(records.size(), 1); - - ReferenceManifest newRim = records.iterator().next(); - - // verify that the rim was unarchived - Assert.assertFalse(newRim.isArchived()); - // verify that the createTime was updated - Assert.assertTrue(newRim.getCreateTime().getTime() > rim.getCreateTime().getTime()); - } - - private ReferenceManifest uploadTestRim() throws Exception { - MvcResult result = getMockMvc().perform(MockMvcRequestBuilders - .fileUpload("/reference-manifests/upload") - .file(validRimFile)) - .andExpect(status().is3xxRedirection()) - .andReturn(); - - // verify redirection messages - FlashMap flashMap = result.getFlashMap(); - PageMessages pageMessages = (PageMessages) flashMap.get("messages"); - Assert.assertEquals(pageMessages.getSuccess().size(), 1); - Assert.assertEquals(pageMessages.getError().size(), 0); - - // verify the cert was actually stored - Set records - = referenceManifestManager.get(BaseReferenceManifest - .select(referenceManifestManager)); - Assert.assertEquals(records.size(), 1); - - ReferenceManifest rim = records.iterator().next(); - Assert.assertFalse(rim.isArchived()); - - return rim; - } - - private void archiveTestRim(final ReferenceManifest rim) throws Exception { - // now, archive the record - getMockMvc().perform(MockMvcRequestBuilders - .post("/reference-manifests/delete") - .param("id", rim.getId().toString())) - .andExpect(status().is3xxRedirection()) - .andReturn(); - - Set records - = referenceManifestManager.get(BaseReferenceManifest - .select(referenceManifestManager).includeArchived()); - Assert.assertEquals(records.size(), 1); - - Assert.assertTrue(records.iterator().next().isArchived()); - } -}