From 3e4fe50dc71ed016c2cfedf805ca65ea1683f886 Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Fri, 22 Mar 2024 12:13:55 -0400 Subject: [PATCH 1/6] Testing out filtering --- .../manager/CACredentialRepository.java | 4 ++ .../CertificatePageController.java | 37 +++++++++---------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CACredentialRepository.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CACredentialRepository.java index 253d0a3d4..815c53e41 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CACredentialRepository.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CACredentialRepository.java @@ -15,6 +15,10 @@ public interface CACredentialRepository extends JpaRepository findByArchiveFlag(boolean archiveFlag); Page findByArchiveFlag(boolean archiveFlag, Pageable pageable); List findBySubject(String subject); + Page findByArchiveFlagOrderBySubjectAsc(boolean archiveFlag, Pageable pageable); + Page findByArchiveFlagOrderBySubjectDesc(boolean archiveFlag, Pageable pageable); + Page findByArchiveFlagOrderByIssuerAsc(boolean archiveFlag, Pageable pageable); + Page findByArchiveFlagOrderByIssuerDesc(boolean archiveFlag, Pageable pageable); List findBySubjectSorted(String subject); List findBySubjectAndArchiveFlag(String subject, boolean archiveFlag); List findBySubjectSortedAndArchiveFlag(String subject, boolean archiveFlag); diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java index 32f610cfe..ceeb0da48 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java @@ -20,6 +20,7 @@ import hirs.attestationca.persist.util.CredentialHelper; import hirs.attestationca.portal.datatables.DataTableInput; import hirs.attestationca.portal.datatables.DataTableResponse; +import hirs.attestationca.portal.datatables.Order; import hirs.attestationca.portal.page.Page; import hirs.attestationca.portal.page.PageController; import hirs.attestationca.portal.page.PageMessages; @@ -214,24 +215,9 @@ public DataTableResponse getTableData( String orderColumnName = input.getOrderColumnName(); log.debug("Ordering on column: " + orderColumnName); - // check that the alert is not archived and that it is in the specified report - CriteriaModifier criteriaModifier = new CriteriaModifier() { - @Override - public void modify(final CriteriaQuery criteriaQuery) { - Session session = entityManager.unwrap(Session.class); - CriteriaBuilder cb = session.getCriteriaBuilder(); - Root rimRoot = criteriaQuery.from(Reference.class); - criteriaQuery.select(rimRoot).distinct(true).where(cb.isNull(rimRoot.get(Certificate.ARCHIVE_FIELD))); - - // add a device alias if this query includes the device table - // for getting the device (e.g. device name). - // use left join, since device may be null. Query will return all - // Certs of this type, whether it has a Device or not (device field may be null) - if (hasDeviceTableToJoin(certificateType)) { -// criteria.createAlias("device", "device", JoinType.LEFT_OUTER_JOIN); - } - } - }; + Order order = input.getOrder().get(0); + + int currentPage = input.getStart() / input.getLength(); Pageable paging = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName)); @@ -289,7 +275,20 @@ public void modify(final CriteriaQuery criteriaQuery) { return new DataTableResponse<>(records, input); } else if (certificateType.equals(TRUSTCHAIN)) { FilteredRecordsList records = new FilteredRecordsList<>(); - org.springframework.data.domain.Page pagedResult = this.caCredentialRepository.findByArchiveFlag(false, paging); + org.springframework.data.domain.Page pagedResult = this.caCredentialRepository.findByArchiveFlag(false, paging);; + if (orderColumnName.equalsIgnoreCase("Issuer")) { + if (order.isAscending()) { + pagedResult = this.caCredentialRepository.findByArchiveFlagOrderByIssuerAsc(false, paging); + } else { + pagedResult = this.caCredentialRepository.findByArchiveFlagOrderByIssuerDesc(false, paging); + } + } else if (orderColumnName.equalsIgnoreCase("Subject")) { + if (order.isAscending()) { + pagedResult = this.caCredentialRepository.findByArchiveFlagOrderBySubjectAsc(false, paging); + } else { + pagedResult = this.caCredentialRepository.findByArchiveFlagOrderBySubjectDesc(false, paging); + } + } if (pagedResult.hasContent()) { records.addAll(pagedResult.getContent()); From 3fbc6bd30194f1f5d921106b28f1c229031d62ff Mon Sep 17 00:00:00 2001 From: iadgovuser58 <124906646+iadgovuser58@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:13:07 -0400 Subject: [PATCH 2/6] fixed error in DeviceInfoReportTest --- .../report/DeviceInfoReportTest.java | 3 ++- HIRS_AttestationCA/src/test/resources/VERSION | 1 - .../src/main/resources/application.properties | 2 +- .../IssuedCertificatesPageControllerTest.java | 9 ++++----- .../test/java/hirs/utils/VersionHelperTest.java | 17 ++++------------- HIRS_Utils/src/test/resources/VERSION | 1 - 6 files changed, 11 insertions(+), 22 deletions(-) delete mode 100644 HIRS_AttestationCA/src/test/resources/VERSION delete mode 100644 HIRS_Utils/src/test/resources/VERSION diff --git a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/entity/userdefined/report/DeviceInfoReportTest.java b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/entity/userdefined/report/DeviceInfoReportTest.java index 4e5db0ec5..c00511eb9 100644 --- a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/entity/userdefined/report/DeviceInfoReportTest.java +++ b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/entity/userdefined/report/DeviceInfoReportTest.java @@ -7,6 +7,7 @@ import hirs.attestationca.persist.entity.userdefined.info.HardwareInfo; import hirs.attestationca.persist.entity.userdefined.info.FirmwareInfo; +import hirs.utils.VersionHelper; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -21,7 +22,7 @@ public class DeviceInfoReportTest extends AbstractUserdefinedEntityTest { private final HardwareInfo hardwareInfo = createTestHardwareInfo(); private final TPMInfo tpmInfo = createTPMInfo(); - private static final String EXPECTED_CLIENT_VERSION = "Test.Version"; + private static final String EXPECTED_CLIENT_VERSION = VersionHelper.getVersion(); /** * Tests instantiation of a DeviceInfoReport. diff --git a/HIRS_AttestationCA/src/test/resources/VERSION b/HIRS_AttestationCA/src/test/resources/VERSION deleted file mode 100644 index b20b9417e..000000000 --- a/HIRS_AttestationCA/src/test/resources/VERSION +++ /dev/null @@ -1 +0,0 @@ -Test.Version diff --git a/HIRS_AttestationCAPortal/src/main/resources/application.properties b/HIRS_AttestationCAPortal/src/main/resources/application.properties index 1f5743155..af89b9488 100644 --- a/HIRS_AttestationCAPortal/src/main/resources/application.properties +++ b/HIRS_AttestationCAPortal/src/main/resources/application.properties @@ -26,7 +26,7 @@ server.tomcat.accesslog.suffix=.log server.tomcat.accesslog.rotate=true # Tomcat TLS support -server.port=8443 +server.port=8449 server.ssl.enabled=true server.ssl.trust-store-type=JKS server.ssl.trust-store=/etc/hirs/certificates/HIRS/TrustStore.jks diff --git a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java index d3fd2cbc4..127ff91ec 100644 --- a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java +++ b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.util.LinkedList; import java.util.List; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -20,12 +21,9 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import static hirs.attestationca.portal.page.Page.ISSUED_CERTIFICATES; import static org.hamcrest.Matchers.hasSize; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + /** * Integration tests that test the URL End Points of IssuedCertificatesPageController. */ @@ -135,7 +133,7 @@ public void beforeMethod() throws IOException { */ @Test @Rollback - public void getDeviceList() throws Exception { + public void getIssuedCertsList() throws Exception { // perform test getMockMvc().perform(MockMvcRequestBuilders.get(pagePath + "/list")) @@ -144,6 +142,7 @@ public void getDeviceList() throws Exception { .andExpect(jsonPath("$.data[0].platformCredentials", hasSize(platformCredentialList.size()))) .andReturn(); + } /** diff --git a/HIRS_Utils/src/test/java/hirs/utils/VersionHelperTest.java b/HIRS_Utils/src/test/java/hirs/utils/VersionHelperTest.java index f2cb4c34a..ce567c46d 100644 --- a/HIRS_Utils/src/test/java/hirs/utils/VersionHelperTest.java +++ b/HIRS_Utils/src/test/java/hirs/utils/VersionHelperTest.java @@ -2,6 +2,7 @@ import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -11,21 +12,11 @@ public class VersionHelperTest { /** - * Test that case where a version file does not exist. - */ - @Test - public void testGetVersionFail() { - String actual = VersionHelper.getVersion("somefile"); - assertTrue(actual.startsWith("")); - } - - /** - * Test that a version file exists and can be read properly. + * Test that a version file exists in /opt/hirs or /etc/hirs and is not empty. */ @Test public void testGetVersionDefault() { - String expected = "Test.Version"; - String actual = VersionHelper.getVersion("VERSION"); - assertEquals(expected, actual); + String actual = VersionHelper.getVersion(); + assertNotNull(actual); } } diff --git a/HIRS_Utils/src/test/resources/VERSION b/HIRS_Utils/src/test/resources/VERSION deleted file mode 100644 index b20b9417e..000000000 --- a/HIRS_Utils/src/test/resources/VERSION +++ /dev/null @@ -1 +0,0 @@ -Test.Version From 47ca5d90d74a1c68424a5584fa05a96b5ad83e8e Mon Sep 17 00:00:00 2001 From: iadgovuser58 <124906646+iadgovuser58@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:21:46 -0400 Subject: [PATCH 3/6] commented out non-working test --- .../IssuedCertificatesPageControllerTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java index 127ff91ec..81cb727c7 100644 --- a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java +++ b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java @@ -135,13 +135,13 @@ public void beforeMethod() throws IOException { @Rollback public void getIssuedCertsList() throws Exception { - // perform test - getMockMvc().perform(MockMvcRequestBuilders.get(pagePath + "/list")) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.data", hasSize(1))) - .andExpect(jsonPath("$.data[0].platformCredentials", - hasSize(platformCredentialList.size()))) - .andReturn(); +// // perform test +// getMockMvc().perform(MockMvcRequestBuilders.get(pagePath + "/list")) +// .andExpect(status().isOk()) +// .andExpect(jsonPath("$.data", hasSize(1))) +// .andExpect(jsonPath("$.data[0].platformCredentials", +// hasSize(platformCredentialList.size()))) +// .andReturn(); } From cc5db6e3ede38b6d1d282a5f23b7ea699e6b1ff5 Mon Sep 17 00:00:00 2001 From: iadgovuser58 <124906646+iadgovuser58@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:37:44 -0400 Subject: [PATCH 4/6] put correct port back in application.properties; removed * from imports in IssuedCertificatesPageControllerTest --- .../src/main/resources/application.properties | 2 +- .../controllers/IssuedCertificatesPageControllerTest.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/HIRS_AttestationCAPortal/src/main/resources/application.properties b/HIRS_AttestationCAPortal/src/main/resources/application.properties index af89b9488..1f5743155 100644 --- a/HIRS_AttestationCAPortal/src/main/resources/application.properties +++ b/HIRS_AttestationCAPortal/src/main/resources/application.properties @@ -26,7 +26,7 @@ server.tomcat.accesslog.suffix=.log server.tomcat.accesslog.rotate=true # Tomcat TLS support -server.port=8449 +server.port=8443 server.ssl.enabled=true server.ssl.trust-store-type=JKS server.ssl.trust-store=/etc/hirs/certificates/HIRS/TrustStore.jks diff --git a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java index 81cb727c7..94f63addb 100644 --- a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java +++ b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java @@ -21,7 +21,10 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import static hirs.attestationca.portal.page.Page.ISSUED_CERTIFICATES; import static org.hamcrest.Matchers.hasSize; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /** @@ -135,7 +138,7 @@ public void beforeMethod() throws IOException { @Rollback public void getIssuedCertsList() throws Exception { -// // perform test + // perform test // getMockMvc().perform(MockMvcRequestBuilders.get(pagePath + "/list")) // .andExpect(status().isOk()) // .andExpect(jsonPath("$.data", hasSize(1))) From f244afffe07dadbf6a2e718053772839d5c2c8e9 Mon Sep 17 00:00:00 2001 From: iadgovuser59 <133057011+iadgovuser59@users.noreply.github.com> Date: Thu, 28 Mar 2024 11:49:58 -0400 Subject: [PATCH 5/6] Making fix to null pointer exception (when fetching from /list). --- .../CertificatePageController.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java index ceeb0da48..970c11b60 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java @@ -215,9 +215,10 @@ public DataTableResponse getTableData( String orderColumnName = input.getOrderColumnName(); log.debug("Ordering on column: " + orderColumnName); - Order order = input.getOrder().get(0); - - + List orderList = input.getOrder(); + Order order = null; + if (orderList.size() > 0) + order = input.getOrder().get(0); int currentPage = input.getStart() / input.getLength(); Pageable paging = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName)); @@ -276,17 +277,19 @@ public DataTableResponse getTableData( } else if (certificateType.equals(TRUSTCHAIN)) { FilteredRecordsList records = new FilteredRecordsList<>(); org.springframework.data.domain.Page pagedResult = this.caCredentialRepository.findByArchiveFlag(false, paging);; - if (orderColumnName.equalsIgnoreCase("Issuer")) { - if (order.isAscending()) { - pagedResult = this.caCredentialRepository.findByArchiveFlagOrderByIssuerAsc(false, paging); - } else { - pagedResult = this.caCredentialRepository.findByArchiveFlagOrderByIssuerDesc(false, paging); - } - } else if (orderColumnName.equalsIgnoreCase("Subject")) { - if (order.isAscending()) { - pagedResult = this.caCredentialRepository.findByArchiveFlagOrderBySubjectAsc(false, paging); - } else { - pagedResult = this.caCredentialRepository.findByArchiveFlagOrderBySubjectDesc(false, paging); + if (order != null) { + if (orderColumnName.equalsIgnoreCase("Issuer")) { + if (order.isAscending()) { + pagedResult = this.caCredentialRepository.findByArchiveFlagOrderByIssuerAsc(false, paging); + } else { + pagedResult = this.caCredentialRepository.findByArchiveFlagOrderByIssuerDesc(false, paging); + } + } else if (orderColumnName.equalsIgnoreCase("Subject")) { + if (order.isAscending()) { + pagedResult = this.caCredentialRepository.findByArchiveFlagOrderBySubjectAsc(false, paging); + } else { + pagedResult = this.caCredentialRepository.findByArchiveFlagOrderBySubjectDesc(false, paging); + } } } @@ -626,8 +629,8 @@ public void ekBulkDownload(final HttpServletResponse response) } private ZipOutputStream bulkDownload(final ZipOutputStream zipOut, - final List certificates, - final String singleFileName) throws IOException { + final List certificates, + final String singleFileName) throws IOException { String zipFileName; // get all files for (Certificate certificate : certificates) { @@ -1012,4 +1015,4 @@ private void deleteComponentResults(final String platformSerial) { componentResultRepository.save(componentResult); } } -} +} \ No newline at end of file From b695772bfa5d6f2fa926d7e88a21a1f8f4a318fe Mon Sep 17 00:00:00 2001 From: iadgovuser59 <133057011+iadgovuser59@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:36:44 -0400 Subject: [PATCH 6/6] Uncommenting test. --- .../IssuedCertificatesPageControllerTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java index 94f63addb..3bc5bdb03 100644 --- a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java +++ b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java @@ -139,12 +139,12 @@ public void beforeMethod() throws IOException { public void getIssuedCertsList() throws Exception { // perform test -// getMockMvc().perform(MockMvcRequestBuilders.get(pagePath + "/list")) -// .andExpect(status().isOk()) -// .andExpect(jsonPath("$.data", hasSize(1))) -// .andExpect(jsonPath("$.data[0].platformCredentials", -// hasSize(platformCredentialList.size()))) -// .andReturn(); + getMockMvc().perform(MockMvcRequestBuilders.get(pagePath + "/list")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.data", hasSize(1))) + .andExpect(jsonPath("$.data[0].platformCredentials", + hasSize(platformCredentialList.size()))) + .andReturn(); }