Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) [#705] /list page Order fix #742

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -15,6 +15,10 @@ public interface CACredentialRepository extends JpaRepository<CertificateAuthori
List<CertificateAuthorityCredential> findByArchiveFlag(boolean archiveFlag);
Page<CertificateAuthorityCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
List<CertificateAuthorityCredential> findBySubject(String subject);
Page<CertificateAuthorityCredential> findByArchiveFlagOrderBySubjectAsc(boolean archiveFlag, Pageable pageable);
Page<CertificateAuthorityCredential> findByArchiveFlagOrderBySubjectDesc(boolean archiveFlag, Pageable pageable);
Page<CertificateAuthorityCredential> findByArchiveFlagOrderByIssuerAsc(boolean archiveFlag, Pageable pageable);
Page<CertificateAuthorityCredential> findByArchiveFlagOrderByIssuerDesc(boolean archiveFlag, Pageable pageable);
List<CertificateAuthorityCredential> findBySubjectSorted(String subject);
List<CertificateAuthorityCredential> findBySubjectAndArchiveFlag(String subject, boolean archiveFlag);
List<CertificateAuthorityCredential> findBySubjectSortedAndArchiveFlag(String subject, boolean archiveFlag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
1 change: 0 additions & 1 deletion HIRS_AttestationCA/src/test/resources/VERSION

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -214,24 +215,10 @@ public DataTableResponse<? extends Certificate> 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<Certificate> 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);
}
}
};
List<Order> 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));
Expand Down Expand Up @@ -289,7 +276,22 @@ public void modify(final CriteriaQuery criteriaQuery) {
return new DataTableResponse<>(records, input);
} else if (certificateType.equals(TRUSTCHAIN)) {
FilteredRecordsList<CertificateAuthorityCredential> records = new FilteredRecordsList<>();
org.springframework.data.domain.Page<CertificateAuthorityCredential> pagedResult = this.caCredentialRepository.findByArchiveFlag(false, paging);
org.springframework.data.domain.Page<CertificateAuthorityCredential> pagedResult = this.caCredentialRepository.findByArchiveFlag(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);
}
}
}

if (pagedResult.hasContent()) {
records.addAll(pagedResult.getContent());
Expand Down Expand Up @@ -627,8 +629,8 @@ public void ekBulkDownload(final HttpServletResponse response)
}

private ZipOutputStream bulkDownload(final ZipOutputStream zipOut,
final List<Certificate> certificates,
final String singleFileName) throws IOException {
final List<Certificate> certificates,
final String singleFileName) throws IOException {
String zipFileName;
// get all files
for (Certificate certificate : certificates) {
Expand Down Expand Up @@ -1013,4 +1015,4 @@ private void deleteComponentResults(final String platformSerial) {
componentResultRepository.save(componentResult);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,11 +21,11 @@
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.*;
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;


/**
* Integration tests that test the URL End Points of IssuedCertificatesPageController.
Expand Down Expand Up @@ -135,7 +136,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"))
Expand All @@ -144,6 +145,7 @@ public void getDeviceList() throws Exception {
.andExpect(jsonPath("$.data[0].platformCredentials",
hasSize(platformCredentialList.size())))
.andReturn();

}

/**
Expand Down
17 changes: 4 additions & 13 deletions HIRS_Utils/src/test/java/hirs/utils/VersionHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
1 change: 0 additions & 1 deletion HIRS_Utils/src/test/resources/VERSION

This file was deleted.

Loading