mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-01-02 03:06:47 +00:00
Fixed all of the compiler styling errors (findbugs and checkstyles)
This commit is contained in:
parent
60e083a048
commit
fcb6170b93
@ -12,5 +12,13 @@ import java.util.UUID;
|
||||
@Repository
|
||||
public interface AppraiserRepository extends JpaRepository<Appraiser, UUID> {
|
||||
|
||||
/**
|
||||
* Finds a <code>Appraiser</code>.
|
||||
* If the <code>Appraiser</code> is successfully retrieved then a reference to
|
||||
* it is returned.
|
||||
*
|
||||
* @param name the name to search by
|
||||
* @return reference to saved appraiser
|
||||
*/
|
||||
Appraiser findByName(String name);
|
||||
}
|
||||
|
@ -13,5 +13,13 @@ import java.util.UUID;
|
||||
@Repository
|
||||
public interface DeviceRepository extends JpaRepository<Device, UUID> {
|
||||
|
||||
/**
|
||||
* Finds a <code>Device</code>.
|
||||
* If the <code>Device</code> is successfully retrieved then a reference to
|
||||
* it is returned.
|
||||
*
|
||||
* @param name the name to search by
|
||||
* @return reference to saved Device
|
||||
*/
|
||||
Device findByName(String name);
|
||||
}
|
||||
|
@ -8,10 +8,27 @@ import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Setting up for new creation for CRUD operations.
|
||||
* @param <T> super type for Policy child type
|
||||
*/
|
||||
@Repository
|
||||
public interface PolicyRepository<T extends Policy> extends JpaRepository<T, UUID> {
|
||||
|
||||
/**
|
||||
* Saves the <code>Policy</code> in the database. This creates a new
|
||||
* database session and saves the policy.
|
||||
*
|
||||
* @param policy Policy to save
|
||||
* @return reference to saved policy
|
||||
*/
|
||||
T save(T policy);
|
||||
|
||||
/**
|
||||
* Updates a <code>Policy</code>. This updates the database entries to
|
||||
* reflect the new values that should be set.
|
||||
*
|
||||
* @param policy Policy object to save
|
||||
* @param uuid UUID for the database object
|
||||
* @return a Policy object
|
||||
*/
|
||||
T updatePolicy(T policy, UUID uuid);
|
||||
}
|
||||
|
@ -13,13 +13,28 @@ import java.util.UUID;
|
||||
@Repository
|
||||
public interface ReferenceDigestValueRepository extends JpaRepository<ReferenceDigestValue, UUID> {
|
||||
|
||||
/**
|
||||
* Persists a new Reference Digest value.
|
||||
*
|
||||
* @param uuid associated with the base rim .
|
||||
* @return the persisted list of ReferenceDigestValue
|
||||
*/
|
||||
List<ReferenceDigestValue> findValuesByBaseRimId(UUID uuid);
|
||||
|
||||
/**
|
||||
* Persists a new Reference Digest value.
|
||||
*
|
||||
* @param uuid associated with the support rim.
|
||||
* @return the persisted list of ReferenceDigestValue
|
||||
*/
|
||||
List<ReferenceDigestValue> findValuesBySupportRimId(UUID uuid);
|
||||
|
||||
/**
|
||||
* List<String> results = session.createCriteria(User.class).add(Projections.projectionList().add(Projections.property("id")).add()....).list();
|
||||
* List<String> results = session.createCriteria(User.class).add(Projections.projectionList()
|
||||
* .add(Projections.property("id")).add()....).list();
|
||||
*
|
||||
* List<Object[]> result = session.createCriteria(User.class).setProjection(Projections.projectionList().add(Projections.groupProperty("lastName")).add(Projections.rowCount())).list();
|
||||
* List<Object[]> result = session.createCriteria(User.class).setProjection(Projections
|
||||
* .projectionList().add(Projections.groupProperty("lastName"))
|
||||
* .add(Projections.rowCount())).list();
|
||||
*/
|
||||
}
|
||||
|
@ -8,9 +8,18 @@ import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Setting up for new creation for CRUD operations.
|
||||
* @param <T> super type for ReferenceManifest child type
|
||||
*/
|
||||
@Repository
|
||||
public interface ReferenceManifestRepository<T extends ReferenceManifest>
|
||||
extends JpaRepository<ReferenceManifest, UUID> {
|
||||
|
||||
/**
|
||||
* Saves the <code>ReferenceManifest</code> in the database. This creates a new
|
||||
* database session and saves the device.
|
||||
*
|
||||
* @param rim ReferenceManifest to save
|
||||
* @return reference to saved rim
|
||||
*/
|
||||
T saveRIM(T rim);
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ package hirs.attestationca.rest;
|
||||
import hirs.attestationca.AbstractAttestationCertificateAuthority;
|
||||
import hirs.attestationca.validation.SupplyChainValidationService;
|
||||
import hirs.data.service.DeviceRegister;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.ReferenceEventManager;
|
||||
import hirs.persist.ReferenceManifestManager;
|
||||
import hirs.persist.service.CertificateService;
|
||||
import hirs.persist.service.ReferenceManifestService;
|
||||
import hirs.structs.converters.StructConverter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@ -36,7 +36,7 @@ public class RestfulAttestationCertificateAuthority
|
||||
* @param acaCertificate the ACA certificate
|
||||
* @param structConverter the struct converter
|
||||
* @param certificateService the certificate service
|
||||
* @param referenceManifestManager the referenceManifestManager
|
||||
* @param referenceManifestService the referenceManifestManager
|
||||
* @param deviceRegister the device register
|
||||
* @param validDays the number of days issued certs are valid
|
||||
* @param deviceManager the device manager
|
||||
@ -48,14 +48,14 @@ public class RestfulAttestationCertificateAuthority
|
||||
final SupplyChainValidationService supplyChainValidationService,
|
||||
final PrivateKey privateKey, final X509Certificate acaCertificate,
|
||||
final StructConverter structConverter,
|
||||
final CertificateManager certificateService,
|
||||
final ReferenceManifestManager referenceManifestManager,
|
||||
final CertificateService certificateService,
|
||||
final ReferenceManifestService referenceManifestService,
|
||||
final DeviceRegister deviceRegister,
|
||||
final DeviceManager deviceManager,
|
||||
final ReferenceEventManager referenceEventManager,
|
||||
@Value("${aca.certificates.validity}") final int validDays) {
|
||||
super(supplyChainValidationService, privateKey, acaCertificate, structConverter,
|
||||
certificateService, referenceManifestManager,
|
||||
certificateService, referenceManifestService,
|
||||
deviceRegister, validDays, deviceManager,
|
||||
referenceEventManager);
|
||||
}
|
||||
|
@ -65,6 +65,27 @@ public class CertificateServiceImpl extends DbServiceImpl<Certificate>
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Certificate updateCertificate(final Certificate certificate) {
|
||||
LOGGER.debug("Updating certificate: {}", certificate);
|
||||
Certificate dbCertificate;
|
||||
|
||||
if (certificate.getId() == null) {
|
||||
LOGGER.debug("Certificate not found: {}", certificate);
|
||||
dbCertificate = certificate;
|
||||
} else {
|
||||
// will not return null, throws and exception
|
||||
dbCertificate = certificateRepository.getReferenceById(certificate.getId());
|
||||
|
||||
// run through things that aren't equal and update
|
||||
|
||||
getCertificateClass(dbCertificate); // need to coming
|
||||
|
||||
}
|
||||
|
||||
return saveCertificate(dbCertificate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Certificate updateCertificate(final Certificate certificate,
|
||||
final UUID uuid) {
|
||||
@ -175,7 +196,7 @@ public class CertificateServiceImpl extends DbServiceImpl<Certificate>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean archive(UUID uuid) {
|
||||
public boolean archive(final UUID uuid) {
|
||||
LOGGER.debug("archiving object: {}", uuid);
|
||||
if (uuid == null) {
|
||||
LOGGER.debug("null name argument");
|
||||
|
@ -114,9 +114,10 @@ public abstract class DbServiceImpl<T> {
|
||||
* Archives the named object and updates it in the database.
|
||||
*
|
||||
* @param uuid unique id of the object to archive
|
||||
* @return true if the object was successfully found and archived, false if the object was not
|
||||
* found
|
||||
* @throws hirs.persist.DBManagerException if the object is not an instance of <code>ArchivableEntity</code>
|
||||
* @return true if the object was successfully found and archived,
|
||||
* false if the object was not found
|
||||
* @throws hirs.persist.DBManagerException if the object is not an instance
|
||||
* of <code>ArchivableEntity</code>
|
||||
*/
|
||||
public abstract boolean archive(final UUID uuid);
|
||||
public abstract boolean archive(UUID uuid);
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ public class DeviceServiceImpl extends DbServiceImpl<Device>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean archive(UUID uuid) {
|
||||
public boolean archive(final UUID uuid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,7 @@ public class PolicyServiceImpl extends DbServiceImpl<Policy>
|
||||
policyRepository.flush();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void deleteObjectById(final UUID uuid) {
|
||||
LOGGER.debug("Deleting policy by id: {}", uuid);
|
||||
@ -95,6 +96,7 @@ public class PolicyServiceImpl extends DbServiceImpl<Policy>
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Policy savePolicy(final Policy policy) {
|
||||
LOGGER.debug("Saving policy: {}", policy);
|
||||
@ -108,6 +110,7 @@ public class PolicyServiceImpl extends DbServiceImpl<Policy>
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Policy updatePolicy(final Policy policy, final UUID uuid) {
|
||||
LOGGER.debug("Updating policy: {}", policy);
|
||||
@ -192,8 +195,9 @@ public class PolicyServiceImpl extends DbServiceImpl<Policy>
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean archive(UUID uuid) {
|
||||
public boolean archive(final UUID uuid) {
|
||||
LOGGER.debug("archiving object: {}", uuid);
|
||||
if (uuid == null) {
|
||||
LOGGER.debug("null name argument");
|
||||
|
@ -186,7 +186,7 @@ public class ReferenceDigestValueServiceImpl extends DbServiceImpl<ReferenceDige
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean archive(UUID uuid) {
|
||||
public boolean archive(final UUID uuid) {
|
||||
LOGGER.debug("archiving object: {}", uuid);
|
||||
if (uuid == null) {
|
||||
LOGGER.debug("null name argument");
|
||||
|
@ -45,6 +45,7 @@ public class ReferenceManifestServiceImpl extends DbServiceImpl<ReferenceManifes
|
||||
public ReferenceManifestServiceImpl(final EntityManager em) {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ReferenceManifest saveRIM(final ReferenceManifest rim) {
|
||||
LOGGER.debug("Saving reference manifest: {}", rim);
|
||||
@ -59,6 +60,12 @@ public class ReferenceManifestServiceImpl extends DbServiceImpl<ReferenceManifes
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReferenceManifest updateReferenceManifest(final ReferenceManifest rim) {
|
||||
return updateReferenceManifest(rim, rim.getId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public ReferenceManifest updateReferenceManifest(final ReferenceManifest rim,
|
||||
final UUID uuid) {
|
||||
@ -91,6 +98,7 @@ public class ReferenceManifestServiceImpl extends DbServiceImpl<ReferenceManifes
|
||||
return new HashSet<>(0);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<ReferenceManifest> getList() {
|
||||
LOGGER.debug("Getting all reference manifest...");
|
||||
@ -116,6 +124,7 @@ public class ReferenceManifestServiceImpl extends DbServiceImpl<ReferenceManifes
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void deleteObjectById(final UUID uuid) {
|
||||
LOGGER.debug("Deleting reference manifest by id: {}", uuid);
|
||||
@ -150,6 +159,7 @@ public class ReferenceManifestServiceImpl extends DbServiceImpl<ReferenceManifes
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean archive(final UUID uuid) throws DBManagerException {
|
||||
LOGGER.debug("archiving object: {}", uuid);
|
||||
|
@ -265,7 +265,7 @@ public class DBDeviceManager extends DBManager<Device> implements
|
||||
Root<Device> root = criteriaQuery.from(Device.class);
|
||||
root.join("group.name", JoinType.LEFT).alias("group");
|
||||
Predicate recordPredicate = criteriaBuilder
|
||||
.and(criteriaBuilder.equal(root.get("group.name"), DeviceGroup.DEFAULT_GROUP));
|
||||
.and(criteriaBuilder.equal(root.get("group.name"), "Default Group"));
|
||||
criteriaQuery.select(root).where(recordPredicate).distinct(true);
|
||||
Query<Device> query = session.createQuery(criteriaQuery);
|
||||
List<Device> results = query.getResultList();
|
||||
@ -298,9 +298,6 @@ public class DBDeviceManager extends DBManager<Device> implements
|
||||
*
|
||||
* @param name of the device to be deleted
|
||||
* @return true if successfully found and deleted, false if otherwise
|
||||
* @throws hirs.persist.DeviceGroupManagerException
|
||||
* if unable to find the device group or delete it from the
|
||||
* database
|
||||
*/
|
||||
@Override
|
||||
public final boolean deleteDevice(final String name)
|
||||
|
@ -181,30 +181,18 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
Transaction tx = session.beginTransaction();
|
||||
try {
|
||||
CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<DeviceGroup> deviceGroupCriteriaQuery = criteriaBuilder
|
||||
.createQuery(DeviceGroup.class);
|
||||
CriteriaQuery<PolicyMapper> policyMapperCriteriaQuery = criteriaBuilder
|
||||
.createQuery(PolicyMapper.class);
|
||||
Root<DeviceGroup> deviceGroupRoot = deviceGroupCriteriaQuery.from(DeviceGroup.class);
|
||||
Root<PolicyMapper> policyMapperRoot = policyMapperCriteriaQuery
|
||||
.from(PolicyMapper.class);
|
||||
Predicate deviceGroupPredicate = criteriaBuilder.and(
|
||||
criteriaBuilder.equal(deviceGroupRoot.get("name"), DeviceGroup.DEFAULT_GROUP));
|
||||
Predicate policyPredicate = criteriaBuilder.and(
|
||||
criteriaBuilder.equal(policyMapperRoot.get("appraiser"), appraiser),
|
||||
criteriaBuilder.equal(policyMapperRoot.get("group.name"),
|
||||
DeviceGroup.DEFAULT_GROUP));
|
||||
deviceGroupCriteriaQuery.select(deviceGroupRoot).where(deviceGroupPredicate);
|
||||
"Default Group"));
|
||||
policyMapperCriteriaQuery.select(policyMapperRoot).where(policyPredicate);
|
||||
|
||||
LOGGER.debug("finding existing policy mapper from db where "
|
||||
+ "appraiser = {}", appraiser);
|
||||
DeviceGroup group = null;
|
||||
Query<DeviceGroup> deviceGroupQuery = session.createQuery(deviceGroupCriteriaQuery);
|
||||
List<DeviceGroup> deviceGroups = deviceGroupQuery.getResultList();
|
||||
if (deviceGroups != null && !deviceGroups.isEmpty()) {
|
||||
group = deviceGroups.get(0);
|
||||
}
|
||||
|
||||
LOGGER.debug("finding existing policy mapper from db where "
|
||||
+ "appraiser = {}", appraiser);
|
||||
@ -231,7 +219,7 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
LOGGER.info("setting default policy {} on appraiser {}",
|
||||
policy, appraiser);
|
||||
if (mapper == null) {
|
||||
session.save(new PolicyMapper(appraiser, policy, group));
|
||||
session.save(new PolicyMapper(appraiser, policy));
|
||||
} else {
|
||||
mapper.setPolicy(policy);
|
||||
session.update(mapper);
|
||||
@ -264,8 +252,7 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
* If the default <code>Policy</code> has not been set then this returns
|
||||
* null.
|
||||
*
|
||||
* @param appraiser
|
||||
* appraiser
|
||||
* @param appraiser appraiser
|
||||
* @return default policy
|
||||
*/
|
||||
@Override
|
||||
@ -288,7 +275,7 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
Root<PolicyMapper> root = criteriaQuery.from(PolicyMapper.class);
|
||||
Predicate recordPredicate = criteriaBuilder.and(
|
||||
criteriaBuilder.equal(root.get("appraiser"), appraiser),
|
||||
criteriaBuilder.equal(root.get("group.name"), DeviceGroup.DEFAULT_GROUP));
|
||||
criteriaBuilder.equal(root.get("group.name"), "Default Group"));
|
||||
criteriaQuery.select(root).where(recordPredicate);
|
||||
Query<PolicyMapper> query = session.createQuery(criteriaQuery);
|
||||
List<PolicyMapper> results = query.getResultList();
|
||||
@ -364,17 +351,13 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
// final Criteria deviceCr = session.createCriteria(Device.class)
|
||||
// .add(Restrictions.eq("name", device.getName()));
|
||||
// final Device retrievedDevice = (Device) deviceCr.uniqueResult();
|
||||
DeviceGroup deviceGroup = null;
|
||||
if (retrievedDevice != null) {
|
||||
deviceGroup = retrievedDevice.getDeviceGroup();
|
||||
}
|
||||
|
||||
final CriteriaBuilder policyCriteriaBuilder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<PolicyMapper> policyCriteriaQuery = policyCriteriaBuilder
|
||||
.createQuery(PolicyMapper.class);
|
||||
Root<PolicyMapper> policyRoot = policyCriteriaQuery.from(PolicyMapper.class);
|
||||
Predicate policyPredicate = policyCriteriaBuilder.and(
|
||||
policyCriteriaBuilder.equal(policyRoot.get("appraiser"), appraiser),
|
||||
policyCriteriaBuilder.equal(policyRoot.get("deviceGroup"), deviceGroup));
|
||||
policyCriteriaBuilder.equal(policyRoot.get("appraiser"), appraiser));
|
||||
policyCriteriaQuery.select(policyRoot).where(policyPredicate);
|
||||
Query<PolicyMapper> policyQuery = session.createQuery(policyCriteriaQuery);
|
||||
List<PolicyMapper> policyResults = policyQuery.getResultList();
|
||||
@ -383,8 +366,7 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
// .add(Restrictions.eq("deviceGroup", deviceGroup));
|
||||
// final PolicyMapper mapper = (PolicyMapper) cr.uniqueResult();
|
||||
if (policyResults == null) {
|
||||
LOGGER.debug("no policy mapper found for appraiser {} and "
|
||||
+ "device group {}", appraiser, deviceGroup);
|
||||
LOGGER.debug("no policy mapper found for appraiser {}", appraiser);
|
||||
} else {
|
||||
ret = policyResults.get(0).getPolicy();
|
||||
}
|
||||
@ -409,10 +391,7 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
* policy for the given appraiser. If neither the specific policy for the
|
||||
* device group or the default policy is found, null is returned.
|
||||
*
|
||||
* @param appraiser
|
||||
* appraiser
|
||||
* @param deviceGroup
|
||||
* device group
|
||||
* @param appraiser appraiser
|
||||
* @return policy associated with the appraiser-device group pair or null if
|
||||
* there is none
|
||||
*/
|
||||
@ -462,9 +441,6 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
|
||||
if (ret == null) {
|
||||
String groupName = "null";
|
||||
if (deviceGroup != null) {
|
||||
groupName = deviceGroup.getName();
|
||||
}
|
||||
final String msg = String.format("unable to find policy for appraiser '%s'"
|
||||
+ " for device group '%s'", appraiser.getName(), groupName);
|
||||
LOGGER.debug(msg);
|
||||
@ -478,33 +454,23 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
* <code>DeviceGroup</code> pair. This updates the database to reflect this
|
||||
* change so that when this class is loaded it should read that property.
|
||||
*
|
||||
* @param appraiser
|
||||
* appraiser
|
||||
* @param deviceGroup
|
||||
* device group
|
||||
* @param policy
|
||||
* policy
|
||||
* @param appraiser appraiser
|
||||
* @param policy policy
|
||||
*/
|
||||
@Override
|
||||
public final void setPolicy(final Appraiser appraiser,
|
||||
final DeviceGroup deviceGroup, final Policy policy) {
|
||||
public final void setPolicy(final Appraiser appraiser, final Policy policy) {
|
||||
Preconditions.checkNotNull(appraiser, "Cannot set policy on null appraiser");
|
||||
Preconditions.checkNotNull(deviceGroup, "Cannot set policy on null device group");
|
||||
|
||||
Transaction tx = null;
|
||||
Session session = getSession();
|
||||
try {
|
||||
tx = session.beginTransaction();
|
||||
LOGGER.debug("Finding existing policy mapper from db where "
|
||||
+ "appraiser = {} and device group = {}", appraiser,
|
||||
deviceGroup);
|
||||
CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<PolicyMapper> criteriaQuery = criteriaBuilder
|
||||
.createQuery(PolicyMapper.class);
|
||||
Root<PolicyMapper> root = criteriaQuery.from(PolicyMapper.class);
|
||||
Predicate recordPredicate = criteriaBuilder.and(
|
||||
criteriaBuilder.equal(root.get("appraiser"), appraiser),
|
||||
criteriaBuilder.equal(root.get("deviceGroup"), deviceGroup));
|
||||
criteriaBuilder.equal(root.get("appraiser"), appraiser));
|
||||
criteriaQuery.select(root).where(recordPredicate);
|
||||
Query<PolicyMapper> query = session.createQuery(criteriaQuery);
|
||||
List<PolicyMapper> results = query.getResultList();
|
||||
@ -523,10 +489,9 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
}
|
||||
} else {
|
||||
LOGGER.info("Setting policy {} on appraiser {} on device "
|
||||
+ "group {}", policy, appraiser, deviceGroup);
|
||||
+ "group {}", policy, appraiser);
|
||||
if (mapper == null) {
|
||||
session.save(new PolicyMapper(appraiser, policy,
|
||||
deviceGroup));
|
||||
session.save(new PolicyMapper(appraiser, policy));
|
||||
} else {
|
||||
mapper.setPolicy(policy);
|
||||
session.update(mapper);
|
||||
|
@ -533,7 +533,7 @@ public class SupplyChainValidationServiceImpl implements SupplyChainValidationSe
|
||||
if (measurement.getPlatformManufacturer().equals(manufacturer)) {
|
||||
tcgMeasurementLog = new TCGEventLog(measurement.getRimBytes());
|
||||
eventValue = this.referenceDigestValueService
|
||||
.getValuesByRimId(baseReferenceManifest.getId());
|
||||
.getValuesByBaseRimId(baseReferenceManifest.getId());
|
||||
for (ReferenceDigestValue rdv : eventValue) {
|
||||
eventValueMap.put(rdv.getDigestValue(), rdv);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package hirs.attestationca;
|
||||
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.persist.service.CertificateService;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
@ -18,7 +18,7 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class CredentialManagementHelperTest {
|
||||
|
||||
private CertificateManager certMan;
|
||||
private CertificateService certMan;
|
||||
|
||||
private static final String EK_HEADER_TRUNCATED
|
||||
= "/certificates/nuc-1/ek_cert_7_byte_header_removed.cer";
|
||||
@ -30,7 +30,7 @@ public class CredentialManagementHelperTest {
|
||||
*/
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
certMan = mock(CertificateManager.class);
|
||||
certMan = mock(CertificateService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,542 +0,0 @@
|
||||
package hirs.attestationca.data.persist;
|
||||
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.enums.HealthStatus;
|
||||
import hirs.persist.ScheduledJobInfo;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static hirs.data.persist.DeviceGroup.DEFAULT_REPORT_DELAY_THRESHOLD;
|
||||
import static hirs.data.persist.DeviceGroup.MINIMUM_THRESHOLD_INTERVAL_MS;
|
||||
|
||||
/**
|
||||
* Unit tests for <code>DeviceGroup</code>s.
|
||||
*
|
||||
*/
|
||||
public class DeviceGroupTest {
|
||||
|
||||
/**
|
||||
* Tests instantiation of a <code>DeviceGroup</code> object.
|
||||
*/
|
||||
@Test
|
||||
public final void testDeviceGroup() {
|
||||
new DeviceGroup("TestDeviceGroup", "TestDeviceGroupDescription");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a NullPointerException is thrown with a null name.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public final void testDeviceGroupNullName() {
|
||||
new DeviceGroup(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getName() returns the correct name.
|
||||
*/
|
||||
@Test
|
||||
public final void testGetName() {
|
||||
final String name = "TestDeviceGroup";
|
||||
DeviceGroup deviceGroup = new DeviceGroup(name);
|
||||
Assert.assertEquals(deviceGroup.getName(), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getDescription() returns the correct description.
|
||||
*/
|
||||
@Test
|
||||
public final void testGetDescription() {
|
||||
final String name = "TestDeviceGroup";
|
||||
final String description = "TestDescription";
|
||||
DeviceGroup deviceGroup = new DeviceGroup(name, description);
|
||||
Assert.assertEquals(deviceGroup.getDescription(), description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getDescription() returns empty if there is no description.
|
||||
*/
|
||||
@Test
|
||||
public final void testGetDescriptionNull() {
|
||||
final String name = "TestDeviceGroup";
|
||||
DeviceGroup deviceGroup = new DeviceGroup(name);
|
||||
Assert.assertEquals("", deviceGroup.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the name of a device group can be set.
|
||||
*/
|
||||
@Test
|
||||
public final void testSetName() {
|
||||
final String name = "TestDeviceGroup";
|
||||
DeviceGroup deviceGroup = new DeviceGroup(name);
|
||||
Assert.assertEquals(deviceGroup.getName(), name);
|
||||
|
||||
final String newName = "TestNewName";
|
||||
deviceGroup.setName(newName);
|
||||
Assert.assertEquals(deviceGroup.getName(), newName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the description of a device group can be set.
|
||||
*/
|
||||
@Test
|
||||
public final void testSetDescription() {
|
||||
final String name = "TestDeviceGroup";
|
||||
final String description = "TestDescription";
|
||||
DeviceGroup deviceGroup = new DeviceGroup(name, description);
|
||||
Assert.assertEquals(deviceGroup.getDescription(), description);
|
||||
|
||||
final String newDescription = "TestNewDescription";
|
||||
deviceGroup.setDescription(newDescription);
|
||||
Assert.assertEquals(deviceGroup.getDescription(), newDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the description of a device group can be set to null.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public final void testSetDescriptionNull() {
|
||||
final String name = "TestDeviceGroup";
|
||||
DeviceGroup deviceGroup = new DeviceGroup(name);
|
||||
deviceGroup.setDescription(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a name cannot be set to null.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public final void setNameNull() {
|
||||
final String name = "TestDeviceGroup";
|
||||
DeviceGroup deviceGroup = new DeviceGroup(name);
|
||||
deviceGroup.setName(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a <code>DeviceGroup</code> with no description.
|
||||
*/
|
||||
@Test
|
||||
public final void testDeviceGroupNullDescription() {
|
||||
new DeviceGroup("TestDeviceGroup");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests that the ScheduleJobInfo field can be get and set, and has a valid default value.
|
||||
*/
|
||||
@Test
|
||||
public final void scheduleJobInfoProperty() {
|
||||
DeviceGroup group = new DeviceGroup("periodic_group");
|
||||
Assert.assertNotNull(group.getScheduledJobInfo());
|
||||
|
||||
final long frequencyMs = 777;
|
||||
ScheduledJobInfo jobInfo = new ScheduledJobInfo(frequencyMs);
|
||||
group.setScheduledJobInfo(jobInfo);
|
||||
|
||||
Assert.assertSame(group.getScheduledJobInfo(), jobInfo);
|
||||
}
|
||||
/**
|
||||
* Tests is and set <code>enablePeriodicReportDelayAlert</code> of a <code>DeviceGroup</code>.
|
||||
*/
|
||||
@Test
|
||||
public final void testEnablePeriodicReportDelayAlert() {
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
Assert.assertFalse(deviceGroup.isEnablePeriodicReportDelayAlert(),
|
||||
"Enable Periodic Report Delay Alert was not false after constructor.");
|
||||
|
||||
deviceGroup.setEnablePeriodicReportDelayAlert(true);
|
||||
Assert.assertTrue(deviceGroup.isEnablePeriodicReportDelayAlert(),
|
||||
"Enable Periodic Report Delay Alert did not match after being set.");
|
||||
|
||||
deviceGroup.setEnablePeriodicReportDelayAlert(false);
|
||||
Assert.assertFalse(deviceGroup.isEnablePeriodicReportDelayAlert(),
|
||||
"Enable Periodic Report Delay Alert did not match after being set.");
|
||||
|
||||
}
|
||||
|
||||
private void testMinPeriodicReportDelayThreshold(final DeviceGroup group, final long interval) {
|
||||
try {
|
||||
group.setPeriodicReportDelayThreshold(interval);
|
||||
Assert.fail("Setting Periodic Report Delay Threshold below minimum did not throw"
|
||||
+ " exception.");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Assert.assertEquals("Periodic Report Delay Threshold must be greater than or equal to "
|
||||
+ MINIMUM_THRESHOLD_INTERVAL_MS + " milliseconds. Received " + interval,
|
||||
ex.getMessage(),
|
||||
"Periodic Report Delay Threshold interval error message was incorrect.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests get and set <code>periodicReportInterval</code> of a <code>DeviceGroup</code>.
|
||||
*/
|
||||
@Test
|
||||
public final void testPeriodicReportDelayThreshold() {
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
Assert.assertEquals(deviceGroup.getPeriodicReportDelayThreshold(),
|
||||
DEFAULT_REPORT_DELAY_THRESHOLD, "Periodic Report Delay Threshold was not "
|
||||
+ DEFAULT_REPORT_DELAY_THRESHOLD + " after constructor.");
|
||||
|
||||
testMinPeriodicReportDelayThreshold(deviceGroup, 0);
|
||||
testMinPeriodicReportDelayThreshold(deviceGroup, MINIMUM_THRESHOLD_INTERVAL_MS - 1);
|
||||
|
||||
deviceGroup.setPeriodicReportDelayThreshold(MINIMUM_THRESHOLD_INTERVAL_MS);
|
||||
Assert.assertEquals(MINIMUM_THRESHOLD_INTERVAL_MS,
|
||||
deviceGroup.getPeriodicReportDelayThreshold(),
|
||||
"Periodic Report Delay Threshold did not match after being set.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a <code>Device</code> can be added to a device group.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public final void testAddDevice() throws Exception {
|
||||
Device device = DeviceTest.getTestDevice("TestDevice");
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
deviceGroup.addDevice(device);
|
||||
Set<Device> devices = deviceGroup.getDevices();
|
||||
Assert.assertNotNull(devices);
|
||||
Assert.assertEquals(devices.size(), 1);
|
||||
Assert.assertEquals(deviceGroup, device.getDeviceGroup());
|
||||
Assert.assertEquals(devices.iterator().next(), device);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a <code>NullPointerException</code> is thrown if a null device is added.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public final void testAddDeviceNull() {
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
deviceGroup.addDevice(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the device group will ignore a duplicate device that is added.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public final void testAddDuplicateDevice() throws Exception {
|
||||
Device device = DeviceTest.getTestDevice("TestDevice");
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
deviceGroup.addDevice(device);
|
||||
deviceGroup.addDevice(device);
|
||||
Set<Device> devices = deviceGroup.getDevices();
|
||||
Assert.assertNotNull(devices);
|
||||
Assert.assertEquals(devices.size(), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a device can be successfully removed.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public final void testRemoveDevice() throws Exception {
|
||||
Device device = DeviceTest.getTestDevice("TestDevice");
|
||||
Device device2 = DeviceTest.getTestDevice("TestDevice2");
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
deviceGroup.addDevice(device);
|
||||
deviceGroup.addDevice(device2);
|
||||
Set<Device> devices = deviceGroup.getDevices();
|
||||
Assert.assertEquals(devices.size(), 2);
|
||||
|
||||
Assert.assertTrue(deviceGroup.removeDevice(device));
|
||||
Assert.assertEquals(devices.size(), 1);
|
||||
Set<Device> expectedSet = new HashSet<>(Arrays.asList(device2));
|
||||
Assert.assertEquals(devices, expectedSet);
|
||||
Assert.assertEquals(device.getDeviceGroup(), null);
|
||||
Assert.assertEquals(device2.getDeviceGroup(), deviceGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a device can be successfully removed using the name of the device.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public final void testRemoveDeviceByName() throws Exception {
|
||||
String testDeviceName = "TestDevice";
|
||||
Device device = DeviceTest.getTestDevice(testDeviceName);
|
||||
Device device2 = DeviceTest.getTestDevice("TestDevice2");
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
deviceGroup.addDevice(device);
|
||||
deviceGroup.addDevice(device2);
|
||||
Set<Device> devices = deviceGroup.getDevices();
|
||||
Assert.assertEquals(devices.size(), 2);
|
||||
|
||||
Assert.assertTrue(deviceGroup.removeDevice(testDeviceName));
|
||||
Assert.assertEquals(devices.size(), 1);
|
||||
Set<Device> expectedSet = new HashSet<>(Arrays.asList(device2));
|
||||
Assert.assertEquals(devices, expectedSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that removeDevice() returns false and doesn't delete anything if passed null as a
|
||||
* parameter (cast as a Device).
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public final void testRemoveDeviceNull() throws Exception {
|
||||
Device device = DeviceTest.getTestDevice("TestDevice");
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
deviceGroup.addDevice(device);
|
||||
Assert.assertEquals(deviceGroup.getDevices().size(), 1);
|
||||
|
||||
Assert.assertFalse(deviceGroup.removeDevice((Device) null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that removeDevice() returns false and doesn't delete anything if an unknown device is
|
||||
* requested to be removed.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public final void testRemoveDeviceUnknown() throws Exception {
|
||||
Device device = DeviceTest.getTestDevice("TestDevice");
|
||||
Device device2 = DeviceTest.getTestDevice("TestDevice2");
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
deviceGroup.addDevice(device);
|
||||
Set<Device> expectedSet = new HashSet<>(Arrays.asList(device));
|
||||
Set<Device> devices = deviceGroup.getDevices();
|
||||
Assert.assertEquals(devices, expectedSet);
|
||||
Assert.assertEquals(device.getDeviceGroup(), deviceGroup);
|
||||
Assert.assertEquals(devices.iterator().next(), device);
|
||||
|
||||
Assert.assertFalse(deviceGroup.removeDevice(device2));
|
||||
Assert.assertEquals(devices, expectedSet);
|
||||
Assert.assertEquals(device.getDeviceGroup(), deviceGroup);
|
||||
Assert.assertEquals(devices.iterator().next(), device);
|
||||
Assert.assertNull(device2.getDeviceGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that removeDevice() returns false and doesn't delete anything if passed null as a
|
||||
* parameter (cast a String).
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public final void testRemoveDeviceNullString() throws Exception {
|
||||
Device device = DeviceTest.getTestDevice("TestDevice");
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
deviceGroup.addDevice(device);
|
||||
Assert.assertEquals(deviceGroup.getDevices().size(), 1);
|
||||
|
||||
Assert.assertFalse(deviceGroup.removeDevice((String) null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that false if returned if the device is attempted to be removed twice.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public final void testRemoveDeviceTwice() throws Exception {
|
||||
Device device = DeviceTest.getTestDevice("TestDevice");
|
||||
Device device2 = DeviceTest.getTestDevice("TestDevice2");
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
deviceGroup.addDevice(device);
|
||||
deviceGroup.addDevice(device2);
|
||||
Set<Device> devices = deviceGroup.getDevices();
|
||||
Assert.assertEquals(devices.size(), 2);
|
||||
|
||||
Assert.assertTrue(deviceGroup.removeDevice(device));
|
||||
Assert.assertFalse(deviceGroup.removeDevice(device));
|
||||
|
||||
Assert.assertEquals(devices.size(), 1);
|
||||
Set<Device> expectedSet = new HashSet<>(Arrays.asList(device2));
|
||||
Assert.assertEquals(devices, expectedSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the enableWaitForAppraisalCompletion property can be set and get correctly.
|
||||
* Also verifies default value.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testEnableWaitForAppraisalCompletionProperty() throws Exception {
|
||||
Device device = DeviceTest.getTestDevice("TestDevice");
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
deviceGroup.addDevice(device);
|
||||
|
||||
Assert.assertFalse(deviceGroup.isWaitForAppraisalCompletionEnabled());
|
||||
|
||||
deviceGroup.setWaitForAppraisalCompletionEnabled(true);
|
||||
Assert.assertTrue(deviceGroup.isWaitForAppraisalCompletionEnabled());
|
||||
|
||||
deviceGroup.setWaitForAppraisalCompletionEnabled(false);
|
||||
Assert.assertFalse(deviceGroup.isWaitForAppraisalCompletionEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the group health is unknown if there are no devices.
|
||||
*/
|
||||
@Test
|
||||
public void groupHealthWithNoDevices() {
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
Assert.assertEquals(deviceGroup.getHealthStatus(), HealthStatus.UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the group health is trusted if all devices are trusted.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void groupHealthTrusted() throws Exception {
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
Device device1 = DeviceTest.getTestDevice("d1");
|
||||
device1.setHealthStatus(HealthStatus.TRUSTED);
|
||||
Device device2 = DeviceTest.getTestDevice("d2");
|
||||
device2.setHealthStatus(HealthStatus.TRUSTED);
|
||||
Device device3 = DeviceTest.getTestDevice("d3");
|
||||
device3.setHealthStatus(HealthStatus.TRUSTED);
|
||||
|
||||
deviceGroup.addDevice(device1);
|
||||
deviceGroup.addDevice(device2);
|
||||
deviceGroup.addDevice(device3);
|
||||
|
||||
Assert.assertEquals(deviceGroup.getHealthStatus(), HealthStatus.TRUSTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the group health is untrusted if a device is untrusted and the remaining devices
|
||||
* are trusted.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void groupHealthUntrustedNoUnknowns() throws Exception {
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
Device device1 = DeviceTest.getTestDevice("d1");
|
||||
device1.setHealthStatus(HealthStatus.TRUSTED);
|
||||
Device device2 = DeviceTest.getTestDevice("d2");
|
||||
device2.setHealthStatus(HealthStatus.UNTRUSTED);
|
||||
Device device3 = DeviceTest.getTestDevice("d3");
|
||||
device3.setHealthStatus(HealthStatus.TRUSTED);
|
||||
|
||||
deviceGroup.addDevice(device1);
|
||||
deviceGroup.addDevice(device2);
|
||||
deviceGroup.addDevice(device3);
|
||||
|
||||
Assert.assertEquals(deviceGroup.getHealthStatus(), HealthStatus.UNTRUSTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the group health is untrusted if a device is untrusted and another device has
|
||||
* unknown trust.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void groupHealthUntrustedSomeUnknowns() throws Exception {
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
Device device1 = DeviceTest.getTestDevice("d1");
|
||||
device1.setHealthStatus(HealthStatus.TRUSTED);
|
||||
Device device2 = DeviceTest.getTestDevice("d2");
|
||||
device2.setHealthStatus(HealthStatus.UNTRUSTED);
|
||||
Device device3 = DeviceTest.getTestDevice("d3");
|
||||
device3.setHealthStatus(HealthStatus.UNKNOWN);
|
||||
|
||||
deviceGroup.addDevice(device1);
|
||||
deviceGroup.addDevice(device2);
|
||||
deviceGroup.addDevice(device3);
|
||||
|
||||
Assert.assertEquals(deviceGroup.getHealthStatus(), HealthStatus.UNTRUSTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the group health is unknown if a device has unknown trust and no devices are
|
||||
* untrusted.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void groupHealthUntrusted() throws Exception {
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
Device device1 = DeviceTest.getTestDevice("d1");
|
||||
device1.setHealthStatus(HealthStatus.TRUSTED);
|
||||
Device device2 = DeviceTest.getTestDevice("d2");
|
||||
device2.setHealthStatus(HealthStatus.TRUSTED);
|
||||
Device device3 = DeviceTest.getTestDevice("d3");
|
||||
device3.setHealthStatus(HealthStatus.UNKNOWN);
|
||||
|
||||
deviceGroup.addDevice(device1);
|
||||
deviceGroup.addDevice(device2);
|
||||
deviceGroup.addDevice(device3);
|
||||
|
||||
Assert.assertEquals(deviceGroup.getHealthStatus(), HealthStatus.UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that getNumberOfDevices returns an accurate count.
|
||||
* @throws Exception if DeviceTest.getTestDevice has a problem.
|
||||
*/
|
||||
@Test
|
||||
public void testGetNumberOfDevices() throws Exception {
|
||||
final int numDevices = 3;
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
Device device1 = DeviceTest.getTestDevice("d1");
|
||||
Device device2 = DeviceTest.getTestDevice("d2");
|
||||
Device device3 = DeviceTest.getTestDevice("d3");
|
||||
|
||||
deviceGroup.addDevice(device1);
|
||||
deviceGroup.addDevice(device2);
|
||||
deviceGroup.addDevice(device3);
|
||||
|
||||
Assert.assertEquals(deviceGroup.getNumberOfDevices(), numDevices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that getNumberOfDevices returns an accurate count.
|
||||
* @throws Exception if DeviceTest.getTestDevice has a problem.
|
||||
*/
|
||||
@Test
|
||||
public void testGetNumberOfTrustedDevices() throws Exception {
|
||||
final int numTrustedDevices = 2;
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
Device device1 = DeviceTest.getTestDevice("d1");
|
||||
device1.setHealthStatus(HealthStatus.TRUSTED);
|
||||
Device device2 = DeviceTest.getTestDevice("d1");
|
||||
device2.setHealthStatus(HealthStatus.UNTRUSTED);
|
||||
Device device3 = DeviceTest.getTestDevice("d2");
|
||||
device3.setHealthStatus(HealthStatus.TRUSTED);
|
||||
Device device4 = DeviceTest.getTestDevice("d3");
|
||||
device4.setHealthStatus(HealthStatus.UNKNOWN);
|
||||
|
||||
deviceGroup.addDevice(device1);
|
||||
deviceGroup.addDevice(device2);
|
||||
deviceGroup.addDevice(device3);
|
||||
deviceGroup.addDevice(device4);
|
||||
|
||||
Assert.assertEquals(deviceGroup.getNumberOfTrustedDevices(), numTrustedDevices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that getAllDevices do not return the device group.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public final void testGetAllDevices() throws Exception {
|
||||
Device device = DeviceTest.getTestDevice("TestDevice");
|
||||
Device device2 = DeviceTest.getTestDevice("TestDevice2");
|
||||
DeviceGroup deviceGroup = new DeviceGroup("TestDeviceGroup");
|
||||
deviceGroup.addDevice(device);
|
||||
deviceGroup.addDevice(device2);
|
||||
Set<Device> devices = deviceGroup.getAllDevices();
|
||||
Assert.assertEquals(devices.size(), 2);
|
||||
Assert.assertNull(devices.iterator().next().getDeviceGroup());
|
||||
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.attestationca.servicemanager.DBCertificateManager;
|
||||
import hirs.data.persist.certificate.CertificateAuthorityCredential;
|
||||
import hirs.persist.CertificateManager;
|
||||
import org.springframework.util.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* This class contains simple tests some of the functionality of
|
||||
* {@link hirs.persist.CertificateSelector}.
|
||||
* For actual functional tests that test certificate retrieval using the class, see
|
||||
* {@link DBCertificateManagerTest}.
|
||||
*/
|
||||
public class CertificateSelectorTest extends SpringPersistenceTest {
|
||||
private CertificateManager certMan;
|
||||
|
||||
/**
|
||||
* Sets up a certificate manager for this test.
|
||||
*/
|
||||
@BeforeClass
|
||||
public void setUp() {
|
||||
certMan = new DBCertificateManager(sessionFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a new CertificateSelector can be constructed.
|
||||
*/
|
||||
@Test
|
||||
public void testConstruction() {
|
||||
Assert.notNull(CertificateAuthorityCredential.select(certMan),
|
||||
"testConstruction is not null.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a new CertificateSelector cannot be constructed
|
||||
* with a null CertificateManager.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testConstructionNullManager() {
|
||||
CertificateAuthorityCredential.select(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a null issuer cannot be set.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testNullByIssuer() {
|
||||
CertificateAuthorityCredential.select(certMan).byIssuer(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an empty issuer cannot be set.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testEmptyByIssuer() {
|
||||
CertificateAuthorityCredential.select(certMan).byIssuer("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a null subject cannot be set.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testNullBySubject() {
|
||||
CertificateAuthorityCredential.select(certMan).bySubject(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an empty subject cannot be set.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testEmptyBySubject() {
|
||||
CertificateAuthorityCredential.select(certMan).bySubject("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a null encoded public key cannot be set.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testNullByEncodedPublicKey() {
|
||||
CertificateAuthorityCredential.select(certMan).byEncodedPublicKey(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an empty encoded public key cannot be set.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testEmptyByEncodedPublicKey() {
|
||||
CertificateAuthorityCredential.select(certMan).byEncodedPublicKey(new byte[]{});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an empty public key modulus cannot be set.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testNullByPublicKeyModulus() {
|
||||
CertificateAuthorityCredential.select(certMan).byPublicKeyModulus(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an empty organization cannot be set.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testNullByIssuerOrganization() {
|
||||
CertificateAuthorityCredential.select(certMan).byIssuerSorted(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an empty organization cannot be set.
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testNullBySubjectOrganization() {
|
||||
CertificateAuthorityCredential.select(certMan).bySubjectSorted(null);
|
||||
}
|
||||
}
|
@ -1,934 +0,0 @@
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.attestationca.servicemanager.DBCertificateManager;
|
||||
import hirs.attestationca.servicemanager.DBDeviceManager;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
import hirs.data.persist.certificate.CertificateAuthorityCredential;
|
||||
import hirs.data.persist.certificate.CertificateTest;
|
||||
import hirs.data.persist.certificate.ConformanceCredential;
|
||||
import hirs.data.persist.certificate.DeviceAssociatedCertificate;
|
||||
import hirs.data.persist.certificate.EndorsementCredential;
|
||||
import hirs.data.persist.certificate.IssuedAttestationCertificate;
|
||||
import hirs.data.persist.certificate.PlatformCredential;
|
||||
import hirs.data.persist.certificate.PlatformCredentialTest;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.persist.CertificateSelector;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.DeviceManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.query.Query;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static hirs.data.persist.certificate.CertificateTest.ISSUED_CLIENT_CERT;
|
||||
|
||||
/**
|
||||
* This class tests the storage, retrieval, and deletion of {@link Certificate}s.
|
||||
*/
|
||||
public class DBCertificateManagerTest extends SpringPersistenceTest {
|
||||
private static final Logger LOGGER = LogManager.getLogger(DBCertificateManagerTest.class);
|
||||
|
||||
private Certificate rootCert;
|
||||
private Certificate intelIntermediateCert;
|
||||
private Certificate sgiIntermediateCert;
|
||||
private Certificate anotherSelfSignedCert;
|
||||
private Certificate intelPlatformCert;
|
||||
private Certificate stmEkCert;
|
||||
private Certificate stmInt02CaCert;
|
||||
private Certificate stmRootCaCert;
|
||||
private Certificate gsTpmRootCaCert;
|
||||
private Certificate hirsClientCert;
|
||||
|
||||
private Map<Class<? extends Certificate>, Certificate> testCertificates = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Set up a session factory for the tests.
|
||||
*/
|
||||
@BeforeClass
|
||||
public void setup() {
|
||||
LOGGER.debug("retrieving session factory");
|
||||
}
|
||||
|
||||
/**
|
||||
* Release resources associated with the test.
|
||||
*/
|
||||
@AfterClass
|
||||
public void tearDown() {
|
||||
LOGGER.debug("closing session factory");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method (re)instantiates some common objects used by the tests below.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificates
|
||||
*/
|
||||
@BeforeMethod
|
||||
public void setupTestObjects() throws IOException {
|
||||
// create individual test certificates
|
||||
rootCert = CertificateTest.getTestCertificate(CertificateTest.FAKE_ROOT_CA_FILE);
|
||||
intelIntermediateCert = CertificateTest.getTestCertificate(
|
||||
CertificateTest.FAKE_INTEL_INT_CA_FILE
|
||||
);
|
||||
sgiIntermediateCert = CertificateTest.getTestCertificate(
|
||||
CertificateTest.FAKE_SGI_INT_CA_FILE
|
||||
);
|
||||
intelPlatformCert = CertificateTest.getTestCertificate(
|
||||
PlatformCredential.class,
|
||||
PlatformCredentialTest.TEST_PLATFORM_CERT_2
|
||||
);
|
||||
anotherSelfSignedCert = CertificateTest.getTestCertificate(
|
||||
CertificateTest.ANOTHER_SELF_SIGNED_FILE
|
||||
);
|
||||
|
||||
hirsClientCert = CertificateTest.getTestCertificate(IssuedAttestationCertificate.class,
|
||||
ISSUED_CLIENT_CERT);
|
||||
|
||||
stmEkCert = CertificateTest.getTestCertificate(EndorsementCredential.class,
|
||||
CertificateTest.STM_NUC1_EC);
|
||||
|
||||
stmInt02CaCert = CertificateTest.getTestCertificate(CertificateTest.STM_INT_02_CA);
|
||||
|
||||
stmRootCaCert = CertificateTest.getTestCertificate(CertificateTest.STM_ROOT_CA);
|
||||
|
||||
gsTpmRootCaCert = CertificateTest.getTestCertificate(CertificateTest.GS_ROOT_CA);
|
||||
|
||||
// create a collection of test certificates, one of each type
|
||||
testCertificates.put(
|
||||
CertificateAuthorityCredential.class,
|
||||
CertificateTest.getTestCertificate(
|
||||
CertificateAuthorityCredential.class,
|
||||
CertificateTest.FAKE_ROOT_CA_FILE
|
||||
)
|
||||
);
|
||||
|
||||
testCertificates.put(
|
||||
ConformanceCredential.class,
|
||||
CertificateTest.getTestCertificate(
|
||||
ConformanceCredential.class,
|
||||
CertificateTest.FAKE_INTEL_INT_CA_FILE
|
||||
)
|
||||
);
|
||||
|
||||
EndorsementCredential endorsementCredential =
|
||||
(EndorsementCredential) CertificateTest.getTestCertificate(
|
||||
EndorsementCredential.class,
|
||||
CertificateTest.TEST_EC
|
||||
);
|
||||
testCertificates.put(EndorsementCredential.class, endorsementCredential);
|
||||
|
||||
PlatformCredential platformCredential =
|
||||
(PlatformCredential) CertificateTest.getTestCertificate(
|
||||
PlatformCredential.class,
|
||||
PlatformCredentialTest.TEST_PLATFORM_CERT_2
|
||||
);
|
||||
|
||||
testCertificates.put(PlatformCredential.class, platformCredential);
|
||||
|
||||
//Set up multi-platform cert Attestation Cert
|
||||
Set<PlatformCredential> platformCredentials = new HashSet<>();
|
||||
platformCredentials.add(platformCredential);
|
||||
|
||||
IssuedAttestationCertificate issuedCert =
|
||||
(IssuedAttestationCertificate)
|
||||
CertificateTest.getTestCertificate(IssuedAttestationCertificate.class,
|
||||
ISSUED_CLIENT_CERT, endorsementCredential, platformCredentials);
|
||||
|
||||
testCertificates.put(IssuedAttestationCertificate.class, issuedCert);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the test state to a known good state. This resets
|
||||
* the database by removing all {@link Certificate} objects.
|
||||
*/
|
||||
@AfterMethod
|
||||
public void resetTestState() {
|
||||
LOGGER.debug("reset test states");
|
||||
resetCertificateTestState();
|
||||
resetDeviceTestState();
|
||||
resetDeviceGroupTestState();
|
||||
}
|
||||
|
||||
private void resetCertificateTestState() {
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Certificate> criteriaQuery = builder.createQuery(Certificate.class);
|
||||
Root<Certificate> root = criteriaQuery.from(Certificate.class);
|
||||
criteriaQuery.select(root);
|
||||
Query<Certificate> query = session.createQuery(criteriaQuery);
|
||||
List<Certificate> objects = query.getResultList();
|
||||
|
||||
for (Object o : objects) {
|
||||
LOGGER.debug("deleting object: {}", o);
|
||||
session.delete(o);
|
||||
}
|
||||
LOGGER.debug("all {} removed", Certificate.class);
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
private void resetDeviceTestState() {
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Device> criteriaQuery = builder.createQuery(Device.class);
|
||||
Root<Device> root = criteriaQuery.from(Device.class);
|
||||
criteriaQuery.select(root);
|
||||
Query<Device> query = session.createQuery(criteriaQuery);
|
||||
List<Device> objects = query.getResultList();
|
||||
|
||||
for (Object o : objects) {
|
||||
LOGGER.debug("deleting object: {}", o);
|
||||
session.delete(o);
|
||||
}
|
||||
LOGGER.debug("all {} removed", Device.class);
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
private void resetDeviceGroupTestState() {
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<DeviceGroup> criteriaQuery = builder.createQuery(DeviceGroup.class);
|
||||
Root<DeviceGroup> root = criteriaQuery.from(DeviceGroup.class);
|
||||
criteriaQuery.select(root);
|
||||
Query<DeviceGroup> query = session.createQuery(criteriaQuery);
|
||||
List<DeviceGroup> objects = query.getResultList();
|
||||
|
||||
for (Object o : objects) {
|
||||
LOGGER.debug("deleting object: {}", o);
|
||||
session.delete(o);
|
||||
}
|
||||
LOGGER.debug("all {} removed", DeviceGroup.class);
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a Certificate can be stored in the database.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
*/
|
||||
@Test
|
||||
public void testSave() throws IOException {
|
||||
DBCertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
saveTestCertsToDb(certMan);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a Certificate can be stored in and subsequently retrieved from the database.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGet() throws IOException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
saveTestCertsToDb(certMan);
|
||||
|
||||
Assert.assertEquals(
|
||||
testCertificates.get(CertificateAuthorityCredential.class),
|
||||
CertificateAuthorityCredential.select(certMan).getCertificate()
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
testCertificates.get(ConformanceCredential.class),
|
||||
ConformanceCredential.select(certMan).getCertificate()
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
testCertificates.get(EndorsementCredential.class),
|
||||
EndorsementCredential.select(certMan).getCertificate()
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
testCertificates.get(PlatformCredential.class),
|
||||
PlatformCredential.select(certMan).getCertificate()
|
||||
);
|
||||
|
||||
IssuedAttestationCertificate issuedAttestationCertificate =
|
||||
IssuedAttestationCertificate.select(certMan).getCertificate();
|
||||
Assert.assertEquals(
|
||||
testCertificates.get(IssuedAttestationCertificate.class),
|
||||
issuedAttestationCertificate);
|
||||
|
||||
// verify issued cert's references
|
||||
Assert.assertTrue(issuedAttestationCertificate.getEndorsementCredential()
|
||||
.equals(EndorsementCredential.select(certMan).getCertificate()));
|
||||
|
||||
Assert.assertTrue(issuedAttestationCertificate.getPlatformCredentials()
|
||||
.containsAll(PlatformCredential.select(certMan).getCertificates()));
|
||||
|
||||
}
|
||||
|
||||
private void saveTestCertsToDb(final CertificateManager certMan) {
|
||||
saveTestCertsToDb(certMan, false);
|
||||
}
|
||||
|
||||
private void saveTestCertsToDb(final CertificateManager certMan, final boolean isArchived) {
|
||||
// save IssuedCerts last, as they reference other certs which aren't stored yet.
|
||||
// Ensure that the dependent certs are stored prior to storing Issued certs.
|
||||
List<Certificate> secondaryCertsToSave = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<Class<? extends Certificate>, Certificate> entry
|
||||
: testCertificates.entrySet()) {
|
||||
if (isArchived) {
|
||||
entry.getValue().archive();
|
||||
}
|
||||
if (entry.getKey() != IssuedAttestationCertificate.class) {
|
||||
Certificate savedCert = certMan.saveCertificate(entry.getValue());
|
||||
Assert.assertEquals(entry.getValue(), savedCert);
|
||||
Assert.assertNotNull(savedCert.getId());
|
||||
} else {
|
||||
secondaryCertsToSave.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
for (Certificate cert : secondaryCertsToSave) {
|
||||
Certificate savedCert = certMan.saveCertificate(cert);
|
||||
Assert.assertEquals(cert, savedCert);
|
||||
Assert.assertNotNull(savedCert.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verifies that by default, the selector excludes certs that have been archived, but that
|
||||
* they can be retrieved when includeArchived() is called.
|
||||
* @throws IOException if an IO exception occurs
|
||||
*/
|
||||
@Test
|
||||
public void testGetArchivedCert() throws IOException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
saveTestCertsToDb(certMan, true);
|
||||
|
||||
CertificateAuthorityCredential cert =
|
||||
CertificateAuthorityCredential.select(certMan).getCertificate();
|
||||
|
||||
Assert.assertNull(cert);
|
||||
|
||||
cert = CertificateAuthorityCredential.select(certMan).includeArchived().getCertificate();
|
||||
|
||||
Assert.assertNotNull(cert);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that multiple Certificates can retrieved by their common type.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllByType() throws IOException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
Certificate savedRootCert = certMan.saveCertificate(rootCert);
|
||||
Certificate savedIntelIntermediateCert = certMan.saveCertificate(intelIntermediateCert);
|
||||
Certificate savedSGIIntermediateCert = certMan.saveCertificate(sgiIntermediateCert);
|
||||
|
||||
Set<CertificateAuthorityCredential> retrievedCerts =
|
||||
CertificateAuthorityCredential.select(certMan)
|
||||
.getCertificates();
|
||||
|
||||
Assert.assertEquals(retrievedCerts, new HashSet<>(
|
||||
Arrays.asList(savedRootCert, savedIntelIntermediateCert, savedSGIIntermediateCert))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that multiple Certificates can retrieved by their common type and issuer.
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllByIssuer() throws IOException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
Certificate savedRootCert = certMan.saveCertificate(rootCert);
|
||||
Certificate savedIntelIntermediateCert = certMan.saveCertificate(intelIntermediateCert);
|
||||
Certificate savedSGIIntermediateCert = certMan.saveCertificate(sgiIntermediateCert);
|
||||
|
||||
Set<CertificateAuthorityCredential> retrievedCerts =
|
||||
CertificateAuthorityCredential.select(certMan)
|
||||
.byIssuer(intelIntermediateCert.getX509Certificate().getIssuerDN().getName())
|
||||
.getCertificates();
|
||||
|
||||
Assert.assertEquals(
|
||||
retrievedCerts,
|
||||
new HashSet<>(Arrays.asList(
|
||||
savedRootCert, savedIntelIntermediateCert, savedSGIIntermediateCert
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that multiple Certificates can retrieved by their common type and subject organization.
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllBySubjectOrganization() throws IOException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
certMan.saveCertificate(stmRootCaCert);
|
||||
certMan.saveCertificate(stmEkCert);
|
||||
Certificate savedStmInt02Cert = certMan.saveCertificate(stmInt02CaCert);
|
||||
Certificate savedGsRootCa = certMan.saveCertificate(gsTpmRootCaCert);
|
||||
|
||||
Set<CertificateAuthorityCredential> retrievedCerts =
|
||||
CertificateAuthorityCredential.select(certMan)
|
||||
.bySubjectSorted(stmEkCert.getIssuerSorted())
|
||||
.getCertificates();
|
||||
|
||||
Assert.assertEquals(
|
||||
retrievedCerts,
|
||||
new HashSet<>(Arrays.asList(
|
||||
savedStmInt02Cert))
|
||||
);
|
||||
|
||||
Set<CertificateAuthorityCredential> secondRetrievedCerts =
|
||||
CertificateAuthorityCredential.select(certMan)
|
||||
.bySubjectSorted(stmRootCaCert.getIssuerSorted())
|
||||
.getCertificates();
|
||||
|
||||
Assert.assertEquals(
|
||||
secondRetrievedCerts,
|
||||
new HashSet<>(Arrays.asList(
|
||||
savedGsRootCa))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that multiple Certificates can retrieved by their common type and issuer organization.
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllByIssuerOrganization() throws IOException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
Certificate savedStmRootCert = certMan.saveCertificate(stmRootCaCert);
|
||||
certMan.saveCertificate(stmEkCert);
|
||||
certMan.saveCertificate(gsTpmRootCaCert);
|
||||
|
||||
Set<CertificateAuthorityCredential> retrievedCerts =
|
||||
CertificateAuthorityCredential.select(certMan)
|
||||
.byIssuerSorted(stmRootCaCert.getIssuerSorted())
|
||||
.getCertificates();
|
||||
|
||||
Assert.assertEquals(
|
||||
retrievedCerts,
|
||||
new HashSet<>(Arrays.asList(
|
||||
savedStmRootCert, gsTpmRootCaCert))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a IssuedAttestationCertificate can be retrieved by its deviceId.
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetIssuedAttestationByDeviceId() throws IOException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
DeviceManager deviceManager = new DBDeviceManager(sessionFactory);
|
||||
DeviceGroupManager deviceGroupManager = new DBDeviceGroupManager(sessionFactory);
|
||||
|
||||
Device device = new Device("test_device");
|
||||
DeviceGroup dg = new DeviceGroup("Default");
|
||||
DeviceGroup savedDg = deviceGroupManager.saveDeviceGroup(dg);
|
||||
device.setDeviceGroup(savedDg);
|
||||
Device savedDevice = deviceManager.saveDevice(device);
|
||||
((DeviceAssociatedCertificate) hirsClientCert).setDevice(savedDevice);
|
||||
Certificate savedCert = certMan.saveCertificate(hirsClientCert);
|
||||
|
||||
Set<IssuedAttestationCertificate> retrievedCerts =
|
||||
IssuedAttestationCertificate.select(certMan).byDeviceId(savedDevice.getId()).
|
||||
getCertificates();
|
||||
Assert.assertEquals(retrievedCerts.size(), 1);
|
||||
for (IssuedAttestationCertificate cert: retrievedCerts) {
|
||||
Assert.assertEquals(savedCert.getId(), cert.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an Endorsement Credential can be retrieved by its deviceId.
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetEndorsementByDeviceId() throws IOException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
DeviceManager deviceManager = new DBDeviceManager(sessionFactory);
|
||||
DeviceGroupManager deviceGroupManager = new DBDeviceGroupManager(sessionFactory);
|
||||
|
||||
Device device = new Device("test_device");
|
||||
DeviceGroup dg = new DeviceGroup("Default");
|
||||
DeviceGroup savedDg = deviceGroupManager.saveDeviceGroup(dg);
|
||||
device.setDeviceGroup(savedDg);
|
||||
Device savedDevice = deviceManager.saveDevice(device);
|
||||
|
||||
EndorsementCredential endorsementCredential =
|
||||
(EndorsementCredential) CertificateTest.getTestCertificate(
|
||||
EndorsementCredential.class, CertificateTest.TEST_EC);
|
||||
endorsementCredential.setDevice(savedDevice);
|
||||
Certificate savedCert = certMan.saveCertificate(endorsementCredential);
|
||||
|
||||
Set<EndorsementCredential> retrievedCerts =
|
||||
EndorsementCredential.select(certMan).byDeviceId(savedDevice.getId()).
|
||||
getCertificates();
|
||||
Assert.assertEquals(retrievedCerts.size(), 1);
|
||||
for (EndorsementCredential cert: retrievedCerts) {
|
||||
Assert.assertEquals(savedCert.getId(), cert.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an Endorsement Credential can be retrieved by its deviceId.
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetPlatformByDeviceId() throws IOException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
DeviceManager deviceManager = new DBDeviceManager(sessionFactory);
|
||||
DeviceGroupManager deviceGroupManager = new DBDeviceGroupManager(sessionFactory);
|
||||
|
||||
Device device = new Device("test_device");
|
||||
DeviceGroup dg = new DeviceGroup("Default");
|
||||
DeviceGroup savedDg = deviceGroupManager.saveDeviceGroup(dg);
|
||||
device.setDeviceGroup(savedDg);
|
||||
Device savedDevice = deviceManager.saveDevice(device);
|
||||
|
||||
PlatformCredential platformCert = (PlatformCredential) CertificateTest.getTestCertificate(
|
||||
PlatformCredential.class, PlatformCredentialTest.TEST_PLATFORM_CERT_2);
|
||||
platformCert.setDevice(savedDevice);
|
||||
Certificate savedCert = certMan.saveCertificate(platformCert);
|
||||
|
||||
Set<PlatformCredential> retrievedCerts =
|
||||
PlatformCredential.select(certMan).byDeviceId(savedDevice.getId()).
|
||||
getCertificates();
|
||||
Assert.assertEquals(retrievedCerts.size(), 1);
|
||||
for (PlatformCredential cert: retrievedCerts) {
|
||||
Assert.assertEquals(savedCert.getId(), cert.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests that a single Certificate can be retrieved amongst many stored Certificates according
|
||||
* to its type and subject.
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetBySubject() throws IOException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
certMan.saveCertificate(rootCert);
|
||||
certMan.saveCertificate(sgiIntermediateCert);
|
||||
Certificate savedIntelIntermediateCert = certMan.saveCertificate(intelIntermediateCert);
|
||||
|
||||
Set<CertificateAuthorityCredential> retrievedCerts =
|
||||
CertificateAuthorityCredential.select(certMan)
|
||||
.bySubject(intelIntermediateCert.getX509Certificate().getSubjectDN().getName())
|
||||
.getCertificates();
|
||||
Assert.assertEquals(retrievedCerts, Collections.singleton(savedIntelIntermediateCert));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a single Certificate can be retrieved amongst many stored Certificates according
|
||||
* to its type and serial number.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetSingleBySerialNumber() throws IOException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
certMan.saveCertificate(rootCert);
|
||||
certMan.saveCertificate(sgiIntermediateCert);
|
||||
Certificate savedIntelIntermediateCert = certMan.saveCertificate(intelIntermediateCert);
|
||||
|
||||
Set<CertificateAuthorityCredential> retrievedCerts =
|
||||
CertificateAuthorityCredential.select(certMan)
|
||||
.bySerialNumber(
|
||||
intelIntermediateCert.getX509Certificate().getSerialNumber()
|
||||
)
|
||||
.getCertificates();
|
||||
Assert.assertEquals(retrievedCerts, Collections.singleton(savedIntelIntermediateCert));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a single Certificate can be retrieved amongst many stored Certificates according
|
||||
* to its type and encoded public key.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetSingleByPublicKey() throws IOException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
certMan.saveCertificate(rootCert);
|
||||
certMan.saveCertificate(sgiIntermediateCert);
|
||||
Certificate savedIntelIntermediateCert = certMan.saveCertificate(intelIntermediateCert);
|
||||
|
||||
Set<CertificateAuthorityCredential> retrievedCerts =
|
||||
CertificateAuthorityCredential.select(certMan)
|
||||
.byEncodedPublicKey(
|
||||
intelIntermediateCert.getX509Certificate().getPublicKey().getEncoded()
|
||||
)
|
||||
.getCertificates();
|
||||
Assert.assertEquals(retrievedCerts, Collections.singleton(savedIntelIntermediateCert));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a single Certificate can be retrieved amongst many stored Certificates according
|
||||
* to its type and public key modulus.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetSingleByPublicKeyModulus() throws IOException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
certMan.saveCertificate(rootCert);
|
||||
certMan.saveCertificate(sgiIntermediateCert);
|
||||
Certificate savedIntelIntermediateCert = certMan.saveCertificate(intelIntermediateCert);
|
||||
|
||||
Set<CertificateAuthorityCredential> retrievedCerts =
|
||||
CertificateAuthorityCredential.select(certMan)
|
||||
.byPublicKeyModulus(Certificate.getPublicKeyModulus(
|
||||
savedIntelIntermediateCert.getX509Certificate()
|
||||
))
|
||||
.getCertificates();
|
||||
Assert.assertEquals(retrievedCerts, Collections.singleton(savedIntelIntermediateCert));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a single certificate can be retrieved amongst many other stored certificates, only
|
||||
* according to its type.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetSingleByType() throws IOException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
Certificate platformSgiCert = CertificateTest.getTestCertificate(
|
||||
PlatformCredential.class, PlatformCredentialTest.TEST_PLATFORM_CERT_2
|
||||
);
|
||||
|
||||
certMan.saveCertificate(rootCert);
|
||||
certMan.saveCertificate(intelIntermediateCert);
|
||||
certMan.saveCertificate(platformSgiCert);
|
||||
|
||||
Set<PlatformCredential> retrievedCerts = PlatformCredential.select(certMan)
|
||||
.getCertificates();
|
||||
Assert.assertEquals(retrievedCerts, Collections.singleton(platformSgiCert));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a single Certificate can be retrieved amongst many stored Certificates according
|
||||
* to its type and subject key identifier.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetCertAuthByCriteria() throws IOException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
CertificateAuthorityCredential savedRootCert = (CertificateAuthorityCredential)
|
||||
certMan.saveCertificate(rootCert);
|
||||
certMan.saveCertificate(sgiIntermediateCert);
|
||||
certMan.saveCertificate(intelIntermediateCert);
|
||||
|
||||
byte[] subjectKeyIdentifier = savedRootCert.getSubjectKeyIdentifier();
|
||||
|
||||
Set<CertificateAuthorityCredential> retrievedCerts =
|
||||
CertificateAuthorityCredential.select(certMan)
|
||||
.bySubjectKeyIdentifier(subjectKeyIdentifier)
|
||||
.getCertificates();
|
||||
Assert.assertEquals(retrievedCerts, Collections.singleton(savedRootCert));
|
||||
|
||||
String issuer = savedRootCert.getX509Certificate().getIssuerDN().getName();
|
||||
BigInteger serialNumber = savedRootCert.getX509Certificate().getSerialNumber();
|
||||
byte[] encodedPublicKey = savedRootCert.getX509Certificate().getPublicKey()
|
||||
.getEncoded();
|
||||
|
||||
retrievedCerts = CertificateAuthorityCredential.select(certMan)
|
||||
.bySubjectKeyIdentifier(subjectKeyIdentifier)
|
||||
.byIssuer(issuer)
|
||||
.bySerialNumber(serialNumber)
|
||||
.byEncodedPublicKey(encodedPublicKey)
|
||||
.getCertificates();
|
||||
|
||||
Assert.assertEquals(retrievedCerts, Collections.singleton(savedRootCert));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a PlatformCredential can be retrieved by its fields.
|
||||
*
|
||||
* @throws IOException if there is a problem constructing test certificates
|
||||
*/
|
||||
@Test
|
||||
public void testGetPlatformByCriteria() throws IOException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
saveTestCertsToDb(certMan);
|
||||
|
||||
PlatformCredential platformCredentialByManufacturer
|
||||
= PlatformCredential
|
||||
.select(certMan)
|
||||
.byManufacturer("Intel")
|
||||
.getCertificate();
|
||||
|
||||
Assert.assertEquals(
|
||||
testCertificates.get(PlatformCredential.class),
|
||||
platformCredentialByManufacturer
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
testCertificates.get(PlatformCredential.class),
|
||||
PlatformCredential.select(certMan).byModel("DE3815TYKH")
|
||||
.getCertificate()
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
testCertificates.get(PlatformCredential.class),
|
||||
PlatformCredential.select(certMan).byVersion("H26998-402")
|
||||
.getCertificate()
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
testCertificates.get(PlatformCredential.class),
|
||||
PlatformCredential.select(certMan).byIssuer(
|
||||
"C=US,ST=CA,L=Santa Clara,O=Intel Corporation,"
|
||||
+ "OU=Transparent Supply Chain,CN=www.intel.com"
|
||||
).getCertificate()
|
||||
);
|
||||
|
||||
|
||||
UUID uuid = platformCredentialByManufacturer.getId();
|
||||
|
||||
Assert.assertEquals(
|
||||
testCertificates.get(PlatformCredential.class),
|
||||
PlatformCredential.select(certMan).byEntityId(uuid).getCertificate()
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
testCertificates.get(PlatformCredential.class),
|
||||
PlatformCredential.select(certMan)
|
||||
.byManufacturer("Intel")
|
||||
.byModel("DE3815TYKH")
|
||||
.byVersion("H26998-402")
|
||||
.byIssuer(
|
||||
"C=US,ST=CA,L=Santa Clara,O=Intel Corporation,"
|
||||
+ "OU=Transparent Supply Chain,CN=www.intel.com"
|
||||
).getCertificate()
|
||||
);
|
||||
|
||||
Assert.assertNull(
|
||||
PlatformCredential.select(certMan).byBoardSerialNumber(
|
||||
"BQKP52840678"
|
||||
).getCertificate()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a {@link hirs.persist.CertificateSelector} can be used to
|
||||
* retrieve certificates in various
|
||||
* forms, including {@link Certificate}.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws KeyStoreException if there is a problem constructing the resultant KeyStore
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testGetSingleInDifferentForms()
|
||||
throws IOException, KeyStoreException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
certMan.saveCertificate(rootCert);
|
||||
certMan.saveCertificate(intelIntermediateCert);
|
||||
certMan.saveCertificate(sgiIntermediateCert);
|
||||
|
||||
String issuer = intelIntermediateCert.getX509Certificate().getIssuerDN().getName();
|
||||
BigInteger serialNumber = intelIntermediateCert.getX509Certificate().getSerialNumber();
|
||||
byte[] encodedPublicKey = intelIntermediateCert.getX509Certificate().getPublicKey()
|
||||
.getEncoded();
|
||||
byte[] subjectKeyIdentifier =
|
||||
((CertificateAuthorityCredential) intelIntermediateCert).getSubjectKeyIdentifier();
|
||||
UUID certId = intelIntermediateCert.getId();
|
||||
|
||||
CertificateSelector certSelector = CertificateAuthorityCredential.select(certMan)
|
||||
.bySubjectKeyIdentifier(subjectKeyIdentifier)
|
||||
.byIssuer(issuer)
|
||||
.bySerialNumber(serialNumber)
|
||||
.byEncodedPublicKey(encodedPublicKey)
|
||||
.byEntityId(certId);
|
||||
|
||||
Assert.assertEquals(
|
||||
certSelector.getCertificate(),
|
||||
intelIntermediateCert
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
certSelector.getCertificates(),
|
||||
Collections.singleton(intelIntermediateCert)
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
certSelector.getX509Certificate(),
|
||||
intelIntermediateCert.getX509Certificate()
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
certSelector.getX509Certificates(),
|
||||
Collections.singleton(intelIntermediateCert.getX509Certificate())
|
||||
);
|
||||
|
||||
Assert.assertNotNull(
|
||||
certSelector.getKeyStore().getCertificateAlias(
|
||||
intelIntermediateCert.getX509Certificate()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that selecting on criteria that no stored Certificates match returns either null,
|
||||
* an empty set, or an empty KeyStore, as appropriate.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws KeyStoreException if there is a problem constructing the resultant KeyStore
|
||||
*/
|
||||
@Test
|
||||
public void testGetNone() throws IOException, KeyStoreException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
certMan.saveCertificate(rootCert);
|
||||
certMan.saveCertificate(intelIntermediateCert);
|
||||
certMan.saveCertificate(sgiIntermediateCert);
|
||||
|
||||
CertificateSelector certSelector = CertificateAuthorityCredential.select(certMan)
|
||||
.byIssuer("An issuer that doesn't exist");
|
||||
|
||||
Assert.assertEquals(certSelector.getCertificates(), Collections.EMPTY_SET);
|
||||
|
||||
Assert.assertEquals(certSelector.getCertificate(), null);
|
||||
|
||||
Assert.assertEquals(certSelector.getX509Certificates(), Collections.EMPTY_SET);
|
||||
|
||||
Assert.assertEquals(certSelector.getX509Certificate(), null);
|
||||
|
||||
Assert.assertEquals(certSelector.getKeyStore().size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a certificate cannot be stored twice in the database.
|
||||
*/
|
||||
@Test(expectedExceptions = DBManagerException.class)
|
||||
public void testStoreDuplicate() {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
certMan.saveCertificate(rootCert);
|
||||
certMan.saveCertificate(rootCert);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a certificate can be stored twice under different roles in the database.
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
*/
|
||||
@Test
|
||||
public void testStoreSameBinaryCertDifferentCertClass() throws IOException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
Certificate caCert = CertificateTest.getTestCertificate(
|
||||
CertificateAuthorityCredential.class, CertificateTest.FAKE_ROOT_CA_FILE
|
||||
);
|
||||
certMan.saveCertificate(caCert);
|
||||
|
||||
Certificate ecCert = CertificateTest.getTestCertificate(
|
||||
EndorsementCredential.class, CertificateTest.FAKE_ROOT_CA_FILE
|
||||
);
|
||||
certMan.saveCertificate(ecCert);
|
||||
|
||||
Assert.assertEquals(caCert.getCertificateHash(), ecCert.getCertificateHash());
|
||||
|
||||
Assert.assertEquals(
|
||||
CertificateAuthorityCredential
|
||||
.select(certMan)
|
||||
.byHashCode(caCert.getCertificateHash())
|
||||
.getCertificate(),
|
||||
caCert
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
EndorsementCredential
|
||||
.select(certMan)
|
||||
.byHashCode(ecCert.getCertificateHash())
|
||||
.getCertificate(),
|
||||
ecCert
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a certificate can be deleted from the database.
|
||||
*
|
||||
* @throws IOException if there is a problem creating the certificate
|
||||
* @throws CertificateException if there is a problem deserializing the original X509Certificate
|
||||
*/
|
||||
@Test
|
||||
public void testDelete() throws IOException, CertificateException {
|
||||
CertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
|
||||
certMan.saveCertificate(rootCert);
|
||||
certMan.saveCertificate(sgiIntermediateCert);
|
||||
Certificate savedIntelIntermediateCert = certMan.saveCertificate(intelIntermediateCert);
|
||||
|
||||
Assert.assertTrue(certMan.delete(savedIntelIntermediateCert));
|
||||
|
||||
Certificate retrievedIntelCert = CertificateAuthorityCredential.select(certMan)
|
||||
.bySerialNumber(
|
||||
intelIntermediateCert.getX509Certificate().getSerialNumber()
|
||||
)
|
||||
.getCertificate();
|
||||
Assert.assertNull(retrievedIntelCert);
|
||||
|
||||
Certificate retrievedRootCert = CertificateAuthorityCredential.select(certMan)
|
||||
.bySerialNumber(
|
||||
rootCert.getX509Certificate().getSerialNumber()
|
||||
)
|
||||
.getCertificate();
|
||||
Assert.assertEquals(retrievedRootCert, rootCert);
|
||||
|
||||
Certificate retrievedSGICert = CertificateAuthorityCredential.select(certMan)
|
||||
.bySerialNumber(
|
||||
sgiIntermediateCert.getX509Certificate().getSerialNumber()
|
||||
)
|
||||
.getCertificate();
|
||||
Assert.assertEquals(retrievedSGICert, sgiIntermediateCert);
|
||||
}
|
||||
}
|
@ -1,19 +1,12 @@
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.appraiser.Appraiser;
|
||||
import hirs.appraiser.TestAppraiser;
|
||||
import hirs.attestationca.servicemanager.DBAppraiserManager;
|
||||
import hirs.attestationca.servicemanager.DBDeviceManager;
|
||||
import hirs.attestationca.servicemanager.DBPolicyManager;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceInfoReport;
|
||||
import hirs.attestationca.data.persist.DeviceTest;
|
||||
import hirs.data.persist.policy.Policy;
|
||||
import hirs.data.persist.TestPolicy;
|
||||
import hirs.persist.AppraiserManager;
|
||||
import hirs.persist.DBUtility;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.PolicyManager;
|
||||
import hirs.persist.PolicyMapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -23,10 +16,6 @@ import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Unit tests for the <code>DBDeviceGroupManager</code> class.
|
||||
*/
|
||||
@ -70,166 +59,6 @@ public final class DBDeviceGroupManagerTest extends SpringPersistenceTest {
|
||||
DBUtility.removeAllInstances(sessionFactory, PolicyMapper.class);
|
||||
DBUtility.removeAllInstances(sessionFactory, Appraiser.class);
|
||||
DBUtility.removeAllInstances(sessionFactory, Policy.class);
|
||||
DBUtility.removeAllInstances(sessionFactory, DeviceGroup.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> can save a
|
||||
* <code>DeviceGroup</code>.
|
||||
*/
|
||||
@Test
|
||||
public void testSave() {
|
||||
LOGGER.debug("testSave test started");
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceGroup.class), 0);
|
||||
final DeviceGroup deviceGroup = new DeviceGroup(deviceGroupName);
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
final DeviceGroup savedDeviceGroup = mgr.saveDeviceGroup(deviceGroup);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceGroup.class), 1);
|
||||
Assert.assertEquals(savedDeviceGroup, deviceGroup);
|
||||
Assert.assertTrue(
|
||||
DBUtility.isInDatabase(sessionFactory, DeviceGroup.class, deviceGroupName)
|
||||
);
|
||||
final UUID deviceGroupID = savedDeviceGroup.getId();
|
||||
Assert.assertNotNull(deviceGroupID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> can save a
|
||||
* <code>DeviceGroup</code>.
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testSaveWithDevices() throws Exception {
|
||||
LOGGER.debug("testSave test started");
|
||||
final String deviceName2 = "Test Device 2";
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceGroup.class), 0);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 0);
|
||||
|
||||
final DeviceGroup deviceGroup = new DeviceGroup(deviceGroupName);
|
||||
Device device1 = getSavedTestDevice(deviceName);
|
||||
Device device2 = getSavedTestDevice(deviceName2);
|
||||
deviceGroup.addDevice(device1);
|
||||
deviceGroup.addDevice(device2);
|
||||
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
final DeviceGroup savedDeviceGroup = mgr.saveDeviceGroup(deviceGroup);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 2);
|
||||
Assert.assertEquals(savedDeviceGroup, deviceGroup);
|
||||
Assert.assertTrue(
|
||||
DBUtility.isInDatabase(sessionFactory, DeviceGroup.class, deviceGroupName)
|
||||
);
|
||||
|
||||
final UUID deviceGroupID = savedDeviceGroup.getId();
|
||||
Assert.assertNotNull(deviceGroupID);
|
||||
Assert.assertEquals(savedDeviceGroup.getDevices(),
|
||||
deviceGroup.getDevices());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> can save a
|
||||
* <code>DeviceGroup</code>.
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveAndSaveWithDevices() throws Exception {
|
||||
LOGGER.debug("testSave test started");
|
||||
final String deviceName2 = "Test Device 2";
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceGroup.class), 0);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 0);
|
||||
|
||||
final DeviceGroup deviceGroup = new DeviceGroup(deviceGroupName);
|
||||
Device device1 = getSavedTestDevice(deviceName);
|
||||
Device device2 = getSavedTestDevice(deviceName2);
|
||||
deviceGroup.addDevice(device1);
|
||||
deviceGroup.addDevice(device2);
|
||||
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
final DeviceGroup savedDeviceGroup = mgr.saveDeviceGroup(deviceGroup);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 2);
|
||||
Assert.assertEquals(savedDeviceGroup, deviceGroup);
|
||||
Assert.assertTrue(
|
||||
DBUtility.isInDatabase(sessionFactory, DeviceGroup.class, deviceGroupName)
|
||||
);
|
||||
|
||||
final UUID deviceGroupID = savedDeviceGroup.getId();
|
||||
Assert.assertNotNull(deviceGroupID);
|
||||
Assert.assertEquals(savedDeviceGroup.getDevices(),
|
||||
deviceGroup.getDevices());
|
||||
|
||||
Assert.assertEquals(device1.getDeviceGroup().getId(), deviceGroupID);
|
||||
Assert.assertEquals(device2.getDeviceGroup().getId(), deviceGroupID);
|
||||
|
||||
savedDeviceGroup.removeDevice(device1);
|
||||
mgr.deleteDeviceGroup(deviceName);
|
||||
Assert.assertTrue(DBUtility.isInDatabase(sessionFactory, Device.class, deviceName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> can save a
|
||||
* <code>DeviceGroup</code>.
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testChangeDeviceGroups() throws Exception {
|
||||
LOGGER.debug("testSave test started");
|
||||
final String deviceName2 = "Test Device 2";
|
||||
final String deviceGroupName2 = "Test Device Group 2";
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceGroup.class), 0);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 0);
|
||||
|
||||
final DeviceGroup deviceGroup = new DeviceGroup(deviceGroupName);
|
||||
Device device1 = getSavedTestDevice(deviceName);
|
||||
Device device2 = getSavedTestDevice(deviceName2);
|
||||
deviceGroup.addDevice(device1);
|
||||
deviceGroup.addDevice(device2);
|
||||
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
final DeviceGroup savedDeviceGroup = mgr.saveDeviceGroup(deviceGroup);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 2);
|
||||
Assert.assertEquals(savedDeviceGroup, deviceGroup);
|
||||
Assert.assertTrue(
|
||||
DBUtility.isInDatabase(sessionFactory, DeviceGroup.class, deviceGroupName)
|
||||
);
|
||||
|
||||
final DeviceGroup deviceGroup2 = new DeviceGroup(deviceGroupName2);
|
||||
final DeviceManager deviceMgr = new DBDeviceManager(sessionFactory);
|
||||
final DeviceGroup savedDeviceGroup2 = mgr.saveDeviceGroup(deviceGroup2);
|
||||
device1.setDeviceGroup(deviceGroup2);
|
||||
deviceMgr.updateDevice(device1);
|
||||
|
||||
Assert.assertFalse(savedDeviceGroup.getDevices().contains(device1));
|
||||
Assert.assertTrue(savedDeviceGroup2.getDevices().contains(device1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> throws a
|
||||
* <code>DeviceGroupManagerException</code> if a <code>DeviceGroup</code> is
|
||||
* saved twice.
|
||||
*/
|
||||
@Test(expectedExceptions = DeviceGroupManagerException.class)
|
||||
public void testSaveTwice() {
|
||||
LOGGER.debug("testSaveTwice test started");
|
||||
final DeviceGroup deviceGroup = new DeviceGroup(deviceGroupName);
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
final DeviceGroup savedDeviceGroup = mgr.saveDeviceGroup(deviceGroup);
|
||||
mgr.saveDeviceGroup(savedDeviceGroup);
|
||||
Assert.fail("second save did not fail");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> throws a
|
||||
* <code>DeviceGroupManagerException</code> if a <code>DeviceGroup</code> is
|
||||
* saved with the same name as an existing <code>DeviceGroup</code>.
|
||||
*/
|
||||
@Test(expectedExceptions = DeviceGroupManagerException.class)
|
||||
public void testSaveSameName() {
|
||||
final DeviceGroup deviceGroup = new DeviceGroup(deviceGroupName);
|
||||
final DeviceGroup deviceGroup2 = new DeviceGroup(deviceGroupName);
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
final DeviceGroup savedDeviceGroup = mgr.saveDeviceGroup(deviceGroup);
|
||||
Assert.assertNotNull(savedDeviceGroup);
|
||||
mgr.saveDeviceGroup(deviceGroup2);
|
||||
Assert.fail("second save did not fail");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,100 +73,6 @@ public final class DBDeviceGroupManagerTest extends SpringPersistenceTest {
|
||||
Assert.fail("save did not fail");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> can update a
|
||||
* <code>DeviceGroup</code>.
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testUpdate() throws Exception {
|
||||
LOGGER.debug("testUpdate test started");
|
||||
LOGGER.debug("asserting db is empty");
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceGroup.class), 0);
|
||||
|
||||
LOGGER.debug("saving new device group in db");
|
||||
DeviceGroup deviceGroup = new DeviceGroup(deviceGroupName);
|
||||
deviceGroup.setWaitForAppraisalCompletionEnabled(true);
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
DeviceGroup savedDeviceGroup = mgr.saveDeviceGroup(deviceGroup);
|
||||
|
||||
Assert.assertTrue(savedDeviceGroup.isWaitForAppraisalCompletionEnabled());
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceGroup.class), 1);
|
||||
|
||||
LOGGER.debug("updating device group with new device");
|
||||
Device device = getSavedTestDevice(deviceName);
|
||||
savedDeviceGroup.addDevice(device);
|
||||
savedDeviceGroup.setWaitForAppraisalCompletionEnabled(false);
|
||||
updateDevice(device);
|
||||
|
||||
LOGGER.debug("verifying updated device group");
|
||||
final DeviceGroup updatedDeviceGroup =
|
||||
mgr.getDeviceGroup(deviceGroupName);
|
||||
Assert.assertEquals(savedDeviceGroup, updatedDeviceGroup);
|
||||
Assert.assertEquals(savedDeviceGroup.getDevices(),
|
||||
updatedDeviceGroup.getDevices());
|
||||
Assert.assertFalse(updatedDeviceGroup.isWaitForAppraisalCompletionEnabled());
|
||||
|
||||
//Includes the DefaultGroup that is always present
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceGroup.class), 2);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests that when a <code>Device</code> is removed from the
|
||||
* <code>DeviceGroup</code> then the device is not removed from the
|
||||
* database.
|
||||
* @throws Exception if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateNullReport() throws Exception {
|
||||
LOGGER.debug("testUpdate test started");
|
||||
LOGGER.debug("asserting db is empty");
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 0);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceInfoReport.class), 0);
|
||||
|
||||
LOGGER.debug("saving new device group in db");
|
||||
final DeviceGroup deviceGroup = new DeviceGroup(deviceGroupName);
|
||||
deviceGroup.addDevice(getSavedTestDevice(deviceName));
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
final DeviceGroup savedDeviceGroup = mgr.saveDeviceGroup(deviceGroup);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceGroup.class), 2);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 1);
|
||||
|
||||
LOGGER.debug("removing device from device group");
|
||||
savedDeviceGroup.removeDevice(deviceName);
|
||||
mgr.updateDeviceGroup(savedDeviceGroup);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceGroup.class), 2);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> fails to update a
|
||||
* <code>DeviceGroup</code> that has the same name as an existing
|
||||
* <code>DeviceGroup</code>.
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateSameName() {
|
||||
LOGGER.debug("testUpdateSameName test started");
|
||||
final String name1 = "Test Device Group 1";
|
||||
final String name2 = "Test Device Group 2";
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
DeviceGroup d1 = new DeviceGroup(name1);
|
||||
DeviceGroup d2 = new DeviceGroup(name2);
|
||||
mgr.saveDeviceGroup(d1);
|
||||
d2 = mgr.saveDeviceGroup(d2);
|
||||
d2.setName(name1);
|
||||
DeviceGroupManagerException expected = null;
|
||||
try {
|
||||
mgr.updateDeviceGroup(d2);
|
||||
} catch (DeviceGroupManagerException e) {
|
||||
expected = e;
|
||||
}
|
||||
Assert.assertNotNull(expected);
|
||||
Assert.assertTrue(DBUtility.isInDatabase(sessionFactory, DeviceGroup.class, name1));
|
||||
Assert.assertTrue(DBUtility.isInDatabase(sessionFactory, DeviceGroup.class, name2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> throws a
|
||||
* <code>DeviceManagerException</code> if the device parameter is null.
|
||||
@ -349,192 +84,4 @@ public final class DBDeviceGroupManagerTest extends SpringPersistenceTest {
|
||||
mgr.updateDevice(null);
|
||||
Assert.fail("save did not fail");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> returns null when null
|
||||
* name is passed to get.
|
||||
*/
|
||||
@Test
|
||||
public void testGetNull() {
|
||||
LOGGER.debug("testGetNull test started");
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
Assert.assertNull(mgr.getDeviceGroup(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> returns null when an
|
||||
* unknown device group name is passed to get.
|
||||
*/
|
||||
@Test
|
||||
public void testGetUnknown() {
|
||||
LOGGER.debug("testGetUnknown test started");
|
||||
final String unknown = "Some Unknown Device Group";
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
Assert.assertNull(mgr.getDeviceGroup(unknown));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that Groups assigned to a particular policy can be returned.
|
||||
*
|
||||
* @throws Exception
|
||||
* if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testGetGroupsForPolicy() throws Exception {
|
||||
LOGGER.debug("testGetGroupsForPolicy test started");
|
||||
|
||||
final DeviceGroupManager groupManager = new DBDeviceGroupManager(sessionFactory);
|
||||
final PolicyManager policyManager = new DBPolicyManager(sessionFactory);
|
||||
final AppraiserManager appraiserManager = new DBAppraiserManager(sessionFactory);
|
||||
|
||||
Appraiser appraiser = new TestAppraiser("Test Appraiser");
|
||||
Appraiser savedAppraiser = appraiserManager.saveAppraiser(appraiser);
|
||||
|
||||
TestPolicy policy = new TestPolicy("TEST_POLICY");
|
||||
policy = (TestPolicy) policyManager.savePolicy(policy);
|
||||
|
||||
DeviceGroup deviceGroup = createDeviceGroup("Test Device Group", "Test Device");
|
||||
DeviceGroup deviceGroup2 = createDeviceGroup("Test Device Group 2", "Test Device 2");
|
||||
policyManager.setPolicy(savedAppraiser, deviceGroup, policy);
|
||||
policyManager.setPolicy(savedAppraiser, deviceGroup2, policy);
|
||||
|
||||
Set<DeviceGroup> groups = groupManager.getGroupsAssignedToPolicy(policy);
|
||||
|
||||
Assert.assertEquals(groups.size(), 2);
|
||||
Assert.assertTrue(groups.contains(deviceGroup));
|
||||
Assert.assertTrue(groups.contains(deviceGroup2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> returns a complete list
|
||||
* of all the device groups that it manages.
|
||||
*/
|
||||
@Test
|
||||
public void testGetDeviceList() {
|
||||
LOGGER.debug("testGetDeviceList test started");
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
final String[] names = {"DeviceGroup1", "DeviceGroup2",
|
||||
"DeviceGroup3", "DeviceGroup4"};
|
||||
final Set<DeviceGroup> deviceGroupSet = new HashSet<>();
|
||||
for (String name : names) {
|
||||
final DeviceGroup deviceGroup = new DeviceGroup(name);
|
||||
mgr.saveDeviceGroup(deviceGroup);
|
||||
deviceGroupSet.add(deviceGroup);
|
||||
}
|
||||
final Set<DeviceGroup> dbNames = mgr.getDeviceGroupSet();
|
||||
Assert.assertEquals(dbNames, deviceGroupSet);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> returns an empty list
|
||||
* when get list is called when there are no items in the database.
|
||||
*/
|
||||
@Test
|
||||
public void testGetDeviceGroupListEmptyList() {
|
||||
LOGGER.debug("testGetDeviceGroupListEmptyList test started");
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
final Set<DeviceGroup> deviceGroupSet = new HashSet<>();
|
||||
final Set<DeviceGroup> dbDeviceGroupSet = mgr.getDeviceGroupSet();
|
||||
Assert.assertEquals(deviceGroupSet, dbDeviceGroupSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that when a <code>DeviceGroup</code> is deleted, the
|
||||
* <code>Device</code>s that were part of the <code>DeviceGroup</code> are
|
||||
* not deleted.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test device
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteDeviceGroup() throws Exception {
|
||||
LOGGER.debug("testDeleteDeviceGroup");
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceGroup.class), 0);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 0);
|
||||
|
||||
final DeviceGroup deviceGroup = new DeviceGroup(deviceGroupName);
|
||||
Device device = getSavedTestDevice(deviceName);
|
||||
deviceGroup.addDevice(device);
|
||||
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
final DeviceGroup savedDeviceGroup = mgr.saveDeviceGroup(deviceGroup);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 1);
|
||||
Assert.assertEquals(savedDeviceGroup, deviceGroup);
|
||||
Assert.assertTrue(
|
||||
DBUtility.isInDatabase(sessionFactory, DeviceGroup.class, deviceGroupName)
|
||||
);
|
||||
Assert.assertTrue(DBUtility.isInDatabase(sessionFactory, Device.class, deviceName));
|
||||
|
||||
final UUID deviceGroupID = savedDeviceGroup.getId();
|
||||
Assert.assertNotNull(deviceGroupID);
|
||||
Assert.assertEquals(savedDeviceGroup.getDevices(),
|
||||
deviceGroup.getDevices());
|
||||
boolean deleteSuccessful = mgr.deleteDeviceGroup(deviceGroupName);
|
||||
Assert.assertTrue(deleteSuccessful);
|
||||
Assert.assertFalse(
|
||||
DBUtility.isInDatabase(sessionFactory, DeviceGroup.class, deviceGroupName)
|
||||
);
|
||||
|
||||
Assert.assertTrue(DBUtility.isInDatabase(sessionFactory, Device.class, deviceName));
|
||||
final DeviceManager deviceManager = new DBDeviceManager(sessionFactory);
|
||||
Device savedDevice = deviceManager.getDevice(deviceName);
|
||||
Assert.assertEquals(savedDevice.getDeviceGroup().getName(), DeviceGroup.DEFAULT_GROUP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> can successfully handle
|
||||
* delete calls when the device group name is unknown.
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteUnknown() {
|
||||
LOGGER.debug("testDeleteUnknown test started");
|
||||
final String unknown = "My Unknown Device Group";
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
Assert.assertNull(mgr.getDeviceGroup(unknown));
|
||||
Assert.assertFalse(mgr.deleteDeviceGroup(unknown));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceGroupManager</code> can successfully handle
|
||||
* delete calls when the device name is null.
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteNull() {
|
||||
LOGGER.debug("testDeleteNull test started");
|
||||
final DeviceGroupManager mgr = new DBDeviceGroupManager(sessionFactory);
|
||||
Assert.assertFalse(mgr.deleteDeviceGroup(null));
|
||||
}
|
||||
|
||||
private Device getSavedTestDevice(final String name) throws Exception {
|
||||
final DeviceGroupManager groupManager = new DBDeviceGroupManager(sessionFactory);
|
||||
DeviceGroup group = groupManager.getDeviceGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
if (group == null) {
|
||||
group = groupManager.saveDeviceGroup(new DeviceGroup(DeviceGroup.DEFAULT_GROUP));
|
||||
}
|
||||
final Device device = DeviceTest.getTestDevice(name);
|
||||
device.setDeviceGroup(group);
|
||||
final DeviceManager mgr = new DBDeviceManager(sessionFactory);
|
||||
return mgr.saveDevice(device);
|
||||
}
|
||||
|
||||
private void updateDevice(final Device device) {
|
||||
final DeviceManager mgr = new DBDeviceManager(sessionFactory);
|
||||
mgr.updateDevice(device);
|
||||
}
|
||||
|
||||
private DeviceGroup createDeviceGroup(final String deviceGroupName,
|
||||
final String deviceName) throws Exception {
|
||||
DeviceGroupManager deviceGroupManager =
|
||||
new DBDeviceGroupManager(sessionFactory);
|
||||
DeviceManager deviceManager = new DBDeviceManager(sessionFactory);
|
||||
Device device = DeviceTest.getTestDevice(deviceName);
|
||||
DeviceGroup deviceGroup = new DeviceGroup(deviceGroupName);
|
||||
deviceGroup = deviceGroupManager.saveDeviceGroup(deviceGroup);
|
||||
deviceGroup.addDevice(device);
|
||||
device.setDeviceGroup(deviceGroup);
|
||||
deviceManager.saveDevice(device);
|
||||
|
||||
deviceGroupManager.updateDeviceGroup(deviceGroup);
|
||||
return deviceGroup;
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,14 @@
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.attestationca.data.persist.DeviceTest;
|
||||
import hirs.attestationca.servicemanager.DBDeviceManager;
|
||||
import hirs.attestationca.servicemanager.DBReportManager;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceInfoReport;
|
||||
import hirs.attestationca.data.persist.DeviceTest;
|
||||
import hirs.data.persist.enums.HealthStatus;
|
||||
import hirs.data.persist.info.NetworkInfo;
|
||||
import hirs.persist.DBUtility;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.DeviceManagerException;
|
||||
import hirs.persist.ReportManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.testng.Assert;
|
||||
@ -19,7 +17,6 @@ import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -65,7 +62,6 @@ public final class DBDeviceManagerTest extends SpringPersistenceTest {
|
||||
@AfterMethod
|
||||
public void resetTestState() {
|
||||
DBUtility.removeAllInstances(sessionFactory, Device.class);
|
||||
DBUtility.removeAllInstances(sessionFactory, DeviceGroup.class);
|
||||
DBUtility.removeAllInstances(sessionFactory, DeviceInfoReport.class);
|
||||
}
|
||||
|
||||
@ -82,8 +78,6 @@ public final class DBDeviceManagerTest extends SpringPersistenceTest {
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 0);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceInfoReport.class), 0);
|
||||
final Device device = DeviceTest.getTestDevice(deviceName);
|
||||
final DeviceGroup group = createGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
device.setDeviceGroup(group);
|
||||
final DeviceManager mgr = new DBDeviceManager(sessionFactory);
|
||||
final Device d2 = mgr.saveDevice(device);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 1);
|
||||
@ -97,27 +91,6 @@ public final class DBDeviceManagerTest extends SpringPersistenceTest {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceManager</code> throws a
|
||||
* <code>DeviceManagerException</code> if a <code>Device</code> is saved
|
||||
* twice.
|
||||
*
|
||||
* @throws hirs.persist.DeviceManagerException if any unexpected errors occur
|
||||
* @throws Exception
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test(expectedExceptions = DeviceManagerException.class)
|
||||
public void testSaveTwice() throws DeviceManagerException, Exception {
|
||||
LOGGER.debug("testSaveTwice test started");
|
||||
final Device device = new Device(deviceName);
|
||||
final DeviceManager mgr = new DBDeviceManager(sessionFactory);
|
||||
final DeviceGroup group = createGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
device.setDeviceGroup(group);
|
||||
final Device b2 = mgr.saveDevice(device);
|
||||
mgr.saveDevice(b2);
|
||||
Assert.fail("second save did not fail");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceManager</code> throws a
|
||||
* <code>DeviceManagerException</code> if a <code>Device</code> is saved
|
||||
@ -151,35 +124,6 @@ public final class DBDeviceManagerTest extends SpringPersistenceTest {
|
||||
Assert.fail("save did not fail");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that when a <code>Device</code> is deleted, the
|
||||
* <code>Device</code> is removed from the DB.
|
||||
*
|
||||
* @throws Exception if error occurs while creating test device
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteDevice() throws Exception {
|
||||
LOGGER.debug("testDeleteDevice");
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 0);
|
||||
|
||||
final Device device = new Device(deviceName);
|
||||
final DeviceManager mgr = new DBDeviceManager(sessionFactory);
|
||||
final DeviceGroup group = createGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
device.setDeviceGroup(group);
|
||||
final Device savedDevice = mgr.saveDevice(device);
|
||||
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 1);
|
||||
Assert.assertTrue(DBUtility.isInDatabase(sessionFactory, Device.class, deviceName));
|
||||
|
||||
final UUID deviceID = savedDevice.getId();
|
||||
Assert.assertNotNull(deviceID);
|
||||
boolean deleteSuccessful = mgr.deleteDevice(deviceName);
|
||||
Assert.assertTrue(deleteSuccessful);
|
||||
Assert.assertFalse(
|
||||
DBUtility.isInDatabase(sessionFactory, DeviceGroup.class, deviceName)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceManager</code> can update a
|
||||
* <code>Device</code>.
|
||||
@ -195,8 +139,6 @@ public final class DBDeviceManagerTest extends SpringPersistenceTest {
|
||||
|
||||
LOGGER.debug("saving new device in db");
|
||||
final Device device = DeviceTest.getTestDevice(deviceName);
|
||||
final DeviceGroup group = createGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
device.setDeviceGroup(group);
|
||||
final DeviceManager mgr = new DBDeviceManager(sessionFactory);
|
||||
final Device d2 = mgr.saveDevice(device);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 1);
|
||||
@ -221,71 +163,6 @@ public final class DBDeviceManagerTest extends SpringPersistenceTest {
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceInfoReport.class), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests that when a <code>Device</code> is updated with a null
|
||||
* <code>DeviceInfoReport</code> then the old report is removed from the
|
||||
* database.
|
||||
*
|
||||
* @throws Exception
|
||||
* if any unexpected errors occur in getting a Device
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateNullReport() throws Exception {
|
||||
LOGGER.debug("testUpdate test started");
|
||||
LOGGER.debug("asserting db is empty");
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 0);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceInfoReport.class), 0);
|
||||
|
||||
LOGGER.debug("saving new device in db");
|
||||
final Device device = DeviceTest.getTestDevice(deviceName);
|
||||
final DeviceGroup group = createGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
device.setDeviceGroup(group);
|
||||
final DeviceManager mgr = new DBDeviceManager(sessionFactory);
|
||||
final Device d2 = mgr.saveDevice(device);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 1);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceInfoReport.class), 1);
|
||||
|
||||
LOGGER.debug("updating device will null device info");
|
||||
d2.setDeviceInfo(null);
|
||||
mgr.updateDevice(d2);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, Device.class), 1);
|
||||
Assert.assertEquals(DBUtility.getCount(sessionFactory, DeviceInfoReport.class), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceManager</code> fails to update a
|
||||
* <code>Device</code> that has the same name as an existing
|
||||
* <code>Device</code>.
|
||||
*
|
||||
* @throws DeviceManagerException if any unexpected errors occur
|
||||
* @throws Exception
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateSameName() throws DeviceManagerException, Exception {
|
||||
LOGGER.debug("testUpdateSameName test started");
|
||||
final String name1 = "Test Device 1";
|
||||
final String name2 = "Test Device 2";
|
||||
final DeviceManager mgr = new DBDeviceManager(sessionFactory);
|
||||
final DeviceGroup group = createGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
Device d1 = new Device(name1);
|
||||
Device d2 = new Device(name2);
|
||||
d1.setDeviceGroup(group);
|
||||
d2.setDeviceGroup(group);
|
||||
mgr.saveDevice(d1);
|
||||
d2 = mgr.saveDevice(d2);
|
||||
d2.setName(name1);
|
||||
DeviceManagerException expected = null;
|
||||
try {
|
||||
mgr.updateDevice(d2);
|
||||
} catch (DeviceManagerException e) {
|
||||
expected = e;
|
||||
}
|
||||
Assert.assertNotNull(expected);
|
||||
Assert.assertTrue(DBUtility.isInDatabase(sessionFactory, Device.class, name1));
|
||||
Assert.assertTrue(DBUtility.isInDatabase(sessionFactory, Device.class, name2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceManager</code> throws a
|
||||
* <code>DeviceManagerException</code> if the device parameter is null.
|
||||
@ -300,31 +177,6 @@ public final class DBDeviceManagerTest extends SpringPersistenceTest {
|
||||
Assert.fail("save did not fail");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceManager</code> can successfully return a
|
||||
* <code>Device</code> from the database.
|
||||
*
|
||||
* @throws Exception
|
||||
* if any unexpected errors occur in getting a Device
|
||||
*/
|
||||
@Test
|
||||
public void testGet() throws Exception {
|
||||
LOGGER.debug("testGet test started");
|
||||
final Device device = DeviceTest.getTestDevice(deviceName);
|
||||
final DeviceManager mgr = new DBDeviceManager(sessionFactory);
|
||||
final ReportManager reportMgr = new DBReportManager(sessionFactory);
|
||||
final DeviceGroup group = createGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
device.setDeviceGroup(group);
|
||||
final Device d2 = mgr.saveDevice(device);
|
||||
final UUID reportId = d2.getDeviceInfo().getId();
|
||||
final Device dbDevice = mgr.getDevice(d2.getName());
|
||||
Assert.assertEquals(dbDevice, d2);
|
||||
final DeviceInfoReport dbReport = (DeviceInfoReport) reportMgr
|
||||
.getReport(reportId);
|
||||
Assert.assertEquals(dbReport, device.getDeviceInfo());
|
||||
Assert.assertEquals(dbDevice.getHealthStatus(), HealthStatus.UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceManager</code> returns null when null name
|
||||
* is passed to get.
|
||||
@ -348,32 +200,6 @@ public final class DBDeviceManagerTest extends SpringPersistenceTest {
|
||||
Assert.assertNull(mgr.getDevice(unknown));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceManager</code> returns a complete list of
|
||||
* all the names of the devices that it manages.
|
||||
*
|
||||
* @throws Exception
|
||||
* if any unexpected errors occur in getting a Device
|
||||
*/
|
||||
@Test
|
||||
public void testGetDeviceNameList() throws Exception {
|
||||
LOGGER.debug("testGetDeviceNameList test started");
|
||||
final DeviceManager mgr = new DBDeviceManager(sessionFactory);
|
||||
final String[] names = {"Device1", "Device2", "Device3", "Device4"};
|
||||
final List<String> namesList = new LinkedList<>();
|
||||
final DeviceGroup group = createGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
|
||||
for (String name : names) {
|
||||
final Device device = DeviceTest.getTestDevice(name);
|
||||
device.setDeviceGroup(group);
|
||||
mgr.saveDevice(device);
|
||||
namesList.add(name);
|
||||
}
|
||||
final List<String> dbNames = mgr.getDeviceNameList();
|
||||
Collections.sort(dbNames);
|
||||
Assert.assertEquals(dbNames, namesList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceManager</code> returns an empty list when
|
||||
* get list is called when there are no items in the database.
|
||||
@ -394,26 +220,6 @@ public final class DBDeviceManagerTest extends SpringPersistenceTest {
|
||||
* if any unexpected errors occur in getting a Device
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testGetDeviceSet() throws Exception {
|
||||
LOGGER.debug("testGetDeviceSet test started");
|
||||
final DeviceManager mgr = new DBDeviceManager(sessionFactory);
|
||||
final String[] names = {"Device1", "Device2", "Device3", "Device4"};
|
||||
final Device[] expectedDevices = new Device[names.length];
|
||||
final DeviceGroup group = createGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
for (int i = 0; i < names.length; ++i) {
|
||||
final Device device = DeviceTest.getTestDevice(names[i]);
|
||||
expectedDevices[i] = device;
|
||||
device.setDeviceGroup(group);
|
||||
mgr.saveDevice(device);
|
||||
}
|
||||
final Set<Device> devices = mgr.getDeviceList();
|
||||
Assert.assertEquals(devices.size(), expectedDevices.length);
|
||||
for (int i = 0; i < expectedDevices.length; ++i) {
|
||||
Assert.assertTrue(devices.contains(expectedDevices[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBDeviceManager</code> returns an empty list when
|
||||
* get list is called when there are no items in the database.
|
||||
@ -426,10 +232,4 @@ public final class DBDeviceManagerTest extends SpringPersistenceTest {
|
||||
final Set<Device> devices = mgr.getDeviceList();
|
||||
Assert.assertEquals(devices, devicesList);
|
||||
}
|
||||
|
||||
private DeviceGroup createGroup(final String name) throws Exception {
|
||||
DeviceGroup group = new DeviceGroup(name);
|
||||
final DeviceGroupManager groupManager = new DBDeviceGroupManager(sessionFactory);
|
||||
return groupManager.saveDeviceGroup(group);
|
||||
}
|
||||
}
|
||||
|
@ -1,907 +0,0 @@
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.appraiser.Appraiser;
|
||||
import hirs.appraiser.TestAppraiser;
|
||||
import hirs.attestationca.data.persist.DeviceTest;
|
||||
import hirs.attestationca.servicemanager.DBDeviceManager;
|
||||
import hirs.attestationca.servicemanager.DBPolicyManager;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.policy.Policy;
|
||||
import hirs.data.persist.TestPolicy;
|
||||
import hirs.data.persist.TestPolicy2;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.PolicyManager;
|
||||
import hirs.persist.PolicyManagerException;
|
||||
import hirs.persist.PolicyMapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.query.Query;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <code>DBPolicyManagerTest</code> is a unit test class for the
|
||||
* <code>DBPolicyManager</code> class.
|
||||
*/
|
||||
public final class DBPolicyManagerTest extends SpringPersistenceTest {
|
||||
private static final Logger LOGGER = LogManager.getLogger(DBPolicyManagerTest.class);
|
||||
private static final String POLICY_NAME = "Test Policy";
|
||||
|
||||
private Appraiser appraiser;
|
||||
|
||||
/**
|
||||
* Creates a new <code>DBPolicyManagerTest</code>.
|
||||
*/
|
||||
public DBPolicyManagerTest() {
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a <code>SessionFactory</code>. The factory is used for an
|
||||
* in-memory database that is used for testing.
|
||||
*/
|
||||
@BeforeClass
|
||||
public void setup() {
|
||||
LOGGER.debug("retrieving session factory");
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the <code>SessionFactory</code> from setup.
|
||||
*/
|
||||
@AfterClass
|
||||
public void tearDown() {
|
||||
LOGGER.debug("closing session factory");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an <code>Appraiser</code> and stores it in the database.
|
||||
*/
|
||||
@BeforeMethod
|
||||
public void testSetup() {
|
||||
LOGGER.debug("setting up DBPolicyManager tests");
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
appraiser = new TestAppraiser("Test Appraiser");
|
||||
final Serializable id = session.save(appraiser);
|
||||
appraiser = (Appraiser) session.get(TestAppraiser.class, id);
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the test state to a known good state. This currently only resets
|
||||
* the database by removing all <code>Policy</code> objects.
|
||||
*/
|
||||
@AfterMethod
|
||||
public void resetTestState() {
|
||||
LOGGER.debug("reset test state");
|
||||
LOGGER.debug("deleting all policies and appraisers");
|
||||
resetPolicyMapperTestState();
|
||||
resetAppraiserTestState();
|
||||
resetPolicyTestState();
|
||||
resetDeviceTestState();
|
||||
resetDeviceGroupTestState();
|
||||
}
|
||||
|
||||
private void resetPolicyMapperTestState() {
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<PolicyMapper> criteriaQuery = builder.createQuery(PolicyMapper.class);
|
||||
Root<PolicyMapper> root = criteriaQuery.from(PolicyMapper.class);
|
||||
criteriaQuery.select(root);
|
||||
Query<PolicyMapper> query = session.createQuery(criteriaQuery);
|
||||
List<PolicyMapper> objects = query.getResultList();
|
||||
|
||||
for (Object o : objects) {
|
||||
LOGGER.debug("deleting object: {}", o);
|
||||
session.delete(o);
|
||||
}
|
||||
LOGGER.debug("all {} removed", PolicyMapper.class);
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
private void resetAppraiserTestState() {
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Appraiser> criteriaQuery = builder.createQuery(Appraiser.class);
|
||||
Root<Appraiser> root = criteriaQuery.from(Appraiser.class);
|
||||
criteriaQuery.select(root);
|
||||
Query<Appraiser> query = session.createQuery(criteriaQuery);
|
||||
List<Appraiser> objects = query.getResultList();
|
||||
|
||||
for (Object o : objects) {
|
||||
LOGGER.debug("deleting object: {}", o);
|
||||
session.delete(o);
|
||||
}
|
||||
LOGGER.debug("all {} removed", Appraiser.class);
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
private void resetPolicyTestState() {
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Policy> criteriaQuery = builder.createQuery(Policy.class);
|
||||
Root<Policy> root = criteriaQuery.from(Policy.class);
|
||||
criteriaQuery.select(root);
|
||||
Query<Policy> query = session.createQuery(criteriaQuery);
|
||||
List<Policy> objects = query.getResultList();
|
||||
|
||||
for (Object o : objects) {
|
||||
LOGGER.debug("deleting object: {}", o);
|
||||
session.delete(o);
|
||||
}
|
||||
LOGGER.debug("all {} removed", Policy.class);
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
private void resetDeviceTestState() {
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Device> criteriaQuery = builder.createQuery(Device.class);
|
||||
Root<Device> root = criteriaQuery.from(Device.class);
|
||||
criteriaQuery.select(root);
|
||||
Query<Device> query = session.createQuery(criteriaQuery);
|
||||
List<Device> objects = query.getResultList();
|
||||
|
||||
for (Object o : objects) {
|
||||
LOGGER.debug("deleting object: {}", o);
|
||||
session.delete(o);
|
||||
}
|
||||
LOGGER.debug("all {} removed", Device.class);
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
private void resetDeviceGroupTestState() {
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<DeviceGroup> criteriaQuery = builder.createQuery(DeviceGroup.class);
|
||||
Root<DeviceGroup> root = criteriaQuery.from(DeviceGroup.class);
|
||||
criteriaQuery.select(root);
|
||||
Query<DeviceGroup> query = session.createQuery(criteriaQuery);
|
||||
List<DeviceGroup> objects = query.getResultList();
|
||||
|
||||
for (Object o : objects) {
|
||||
LOGGER.debug("deleting object: {}", o);
|
||||
session.delete(o);
|
||||
}
|
||||
LOGGER.debug("all {} removed", DeviceGroup.class);
|
||||
session.getTransaction().commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> can save a
|
||||
* <code>Policy</code>.
|
||||
*
|
||||
* @throws hirs.persist.PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testSave() throws PolicyManagerException {
|
||||
final TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
final TestPolicy p2 = (TestPolicy) mgr.savePolicy(policy);
|
||||
Assert.assertEquals(p2, policy);
|
||||
Assert.assertTrue(isInDatabase(POLICY_NAME));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> throws a
|
||||
* <code>PolicyManagerException</code> if a <code>Policy</code> is saved
|
||||
* twice.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test(expectedExceptions = PolicyManagerException.class)
|
||||
public void testSaveTwice() throws PolicyManagerException {
|
||||
final TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
final TestPolicy p2 = (TestPolicy) mgr.savePolicy(policy);
|
||||
mgr.savePolicy(p2);
|
||||
Assert.fail("second save did not fail");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> throws a
|
||||
* <code>PolicyManagerException</code> if a <code>Policy</code> is saved
|
||||
* with the same name as an existing <code>Policy</code>.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test(expectedExceptions = PolicyManagerException.class)
|
||||
public void testSaveSameName() throws PolicyManagerException {
|
||||
final TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final TestPolicy policy2 = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
final TestPolicy p2 = (TestPolicy) mgr.savePolicy(policy);
|
||||
Assert.assertNotNull(p2);
|
||||
mgr.savePolicy(policy2);
|
||||
Assert.fail("second save did not fail");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> throws a
|
||||
* <code>PolicyManagerException</code> if the policy parameter is null.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testSaveNullPolicy() throws PolicyManagerException {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
mgr.savePolicy(null);
|
||||
Assert.fail("save did not fail");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> can update a
|
||||
* <code>Policy</code>.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testUpdate() throws PolicyManagerException {
|
||||
final String updatedName = "Updated Policy";
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
final Policy policy = createPolicy(mgr);
|
||||
policy.setName(updatedName);
|
||||
mgr.updatePolicy(policy);
|
||||
Assert.assertTrue(isInDatabase(updatedName));
|
||||
Assert.assertFalse(isInDatabase(POLICY_NAME));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> fails to update a
|
||||
* <code>Policy</code> that has the same name as an existing
|
||||
* <code>Policy</code>.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateSameName() throws PolicyManagerException {
|
||||
final String name1 = "Test Policy 1";
|
||||
final String name2 = "Test Policy 2";
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
createPolicy(mgr, name1);
|
||||
final Policy p2 = createPolicy(mgr, name2);
|
||||
p2.setName(name1);
|
||||
PolicyManagerException expected = null;
|
||||
try {
|
||||
mgr.updatePolicy(p2);
|
||||
} catch (PolicyManagerException e) {
|
||||
expected = e;
|
||||
}
|
||||
Assert.assertNotNull(expected);
|
||||
Assert.assertTrue(isInDatabase(name1));
|
||||
Assert.assertTrue(isInDatabase(name2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> throws a
|
||||
* <code>PolicyManagerException</code> if the policy parameter is null.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testUpdateNullPolicy() throws PolicyManagerException {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
mgr.updatePolicy(null);
|
||||
Assert.fail("save did not fail");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> can get a <code>Policy</code>
|
||||
* .
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testGet() throws PolicyManagerException {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
Assert.assertNull(mgr.getPolicy(POLICY_NAME));
|
||||
final Policy policy = createPolicy(mgr);
|
||||
final Policy getPolicy = mgr.getPolicy(POLICY_NAME);
|
||||
Assert.assertNotNull(getPolicy);
|
||||
Assert.assertEquals(getPolicy, policy);
|
||||
Assert.assertEquals(getPolicy.getId(), policy.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> returns null when an unknown
|
||||
* <code>Policy</code> is searched for.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testGetUnknown() throws PolicyManagerException {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
Assert.assertNull(mgr.getPolicy("Some Unknown Policy"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> returns null when the name is
|
||||
* set to null.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testGetNull() throws PolicyManagerException {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
Assert.assertNull(mgr.getPolicy(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a list of <code>Policy</code> names can be retrieved from the
|
||||
* repository.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testGetPolicyList() throws PolicyManagerException {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
final String[] names = {"Policy1", "Policy2", "Policy3"};
|
||||
final Policy[] expectedPolicies = new Policy[names.length];
|
||||
for (int i = 0; i < names.length; ++i) {
|
||||
expectedPolicies[i] = createPolicy(mgr, names[i]);
|
||||
}
|
||||
final List<Policy> policies = mgr.getPolicyList(Policy.class);
|
||||
Assert.assertEquals(policies.size(), expectedPolicies.length);
|
||||
for (int i = 0; i < expectedPolicies.length; ++i) {
|
||||
Assert.assertTrue(policies.contains(expectedPolicies[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a list of <code>Policy</code> names can be retrieved from the
|
||||
* repository with null <code>Class</code> given.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testGetPolicyListNullClass() throws PolicyManagerException {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
final String[] names = {"Policy1", "Policy2", "Policy3"};
|
||||
final Policy[] expectedPolicies = new Policy[names.length];
|
||||
for (int i = 0; i < names.length; ++i) {
|
||||
expectedPolicies[i] = createPolicy(mgr, names[i]);
|
||||
}
|
||||
final List<Policy> policies = mgr.getPolicyList(null);
|
||||
Assert.assertEquals(policies.size(), expectedPolicies.length);
|
||||
for (int i = 0; i < expectedPolicies.length; ++i) {
|
||||
Assert.assertTrue(policies.contains(expectedPolicies[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a list of <code>Policy</code> names can be retrieved from the
|
||||
* repository when a subclass of <code>Policy</code> is used.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testGetPolicyListDifferentClass()
|
||||
throws PolicyManagerException {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
final String[] names = {"Policy1", "Policy2", "Policy3"};
|
||||
final Policy[] expectedPolicies = new Policy[names.length];
|
||||
for (int i = 0; i < names.length; ++i) {
|
||||
expectedPolicies[i] = createPolicy(mgr, names[i]);
|
||||
}
|
||||
final List<Policy> policies = mgr.getPolicyList(TestPolicy.class);
|
||||
Assert.assertEquals(policies.size(), expectedPolicies.length);
|
||||
for (int i = 0; i < expectedPolicies.length; ++i) {
|
||||
Assert.assertTrue(policies.contains(expectedPolicies[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a list of <code>Policy</code> names can be retrieved from the
|
||||
* repository when a subclass of <code>Policy</code> is used and the list is
|
||||
* empty because all of the stored <code>Policy</code>s are of a different
|
||||
* class.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testGetPolicyListDifferentClassNoReturn()
|
||||
throws PolicyManagerException {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
final String[] names = {"Policy1", "Policy2", "Policy3"};
|
||||
for (int i = 0; i < names.length; ++i) {
|
||||
createPolicy(mgr, names[i]);
|
||||
}
|
||||
final List<Policy> policies = mgr.getPolicyList(TestPolicy2.class);
|
||||
Assert.assertEquals(policies.size(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> can archive a <code>Policy</code>.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testArchive() throws PolicyManagerException {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
Assert.assertNull(mgr.getPolicy(POLICY_NAME));
|
||||
createPolicy(mgr);
|
||||
Assert.assertNotNull(mgr.getPolicy(POLICY_NAME));
|
||||
boolean archived = mgr.archive(POLICY_NAME);
|
||||
Assert.assertTrue(archived);
|
||||
Assert.assertTrue(mgr.getPolicy(POLICY_NAME).isArchived());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> returns false when an unknown <code>Policy</code>
|
||||
* name is provided to the archive() method.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testArchiveUnknown() throws PolicyManagerException {
|
||||
final String name = "Some unknown policy";
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
boolean archived = mgr.archive(name);
|
||||
Assert.assertFalse(archived);
|
||||
Assert.assertNull(mgr.getPolicy(POLICY_NAME));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the <code>DBPolicyManager</code> returns false when a null name is provided to the
|
||||
* archive() method.
|
||||
*
|
||||
* @throws PolicyManagerException
|
||||
* if any unexpected errors occur
|
||||
*/
|
||||
@Test
|
||||
public void testArchiveNull() throws PolicyManagerException {
|
||||
final String name = null;
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
boolean archived = mgr.archive(name);
|
||||
Assert.assertFalse(archived);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a policy can be set for an appraiser and device group.
|
||||
*
|
||||
* @throws Exception
|
||||
* if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testSetAndGetPolicy() throws Exception {
|
||||
TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
policy = (TestPolicy) mgr.savePolicy(policy);
|
||||
DeviceGroup deviceGroup =
|
||||
createDeviceGroupWithDevice("Test Device Group", "Test Device");
|
||||
mgr.setPolicy(appraiser, deviceGroup, policy);
|
||||
final Policy retrievedPolicy = mgr.getPolicy(appraiser, deviceGroup);
|
||||
Assert.assertEquals(retrievedPolicy, policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a policy can be set for an appraiser and device group, and
|
||||
* retrieved using the device.
|
||||
*
|
||||
* @throws Exception
|
||||
* if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testSetAndGetPolicyUsingDevice() throws Exception {
|
||||
TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
policy = (TestPolicy) mgr.savePolicy(policy);
|
||||
DeviceGroup deviceGroup =
|
||||
createDeviceGroupWithDevice("Test Device Group", "Test Device");
|
||||
mgr.setPolicy(appraiser, deviceGroup, policy);
|
||||
final Policy retrievedPolicy = mgr.getPolicy(
|
||||
appraiser, deviceGroup.getDevices().iterator().next()
|
||||
);
|
||||
Assert.assertEquals(retrievedPolicy, policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a policy can be removed for an appraiser and device group.
|
||||
*
|
||||
* @throws Exception
|
||||
* if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testSetPolicyRemove() throws Exception {
|
||||
TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
policy = (TestPolicy) mgr.savePolicy(policy);
|
||||
DeviceGroup deviceGroup =
|
||||
createDeviceGroupWithDevice("Test Device Group", "Test Device");
|
||||
mgr.setPolicy(appraiser, deviceGroup, policy);
|
||||
Policy retrievedPolicy = mgr.getPolicy(appraiser, deviceGroup);
|
||||
Assert.assertEquals(retrievedPolicy, policy);
|
||||
|
||||
mgr.setPolicy(appraiser, deviceGroup, null);
|
||||
retrievedPolicy = mgr.getPolicy(appraiser, deviceGroup);
|
||||
Assert.assertNull(retrievedPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a <code>NullPointerExcpetion</code> is thrown if appraiser is
|
||||
* null.
|
||||
*
|
||||
* @throws Exception
|
||||
* if error occurs while creating test Device
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testSetPolicyNullAppraiser() throws Exception {
|
||||
TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
DeviceGroup deviceGroup =
|
||||
createDeviceGroupWithDevice("Test Device Group", "Test Device");
|
||||
policy = (TestPolicy) mgr.savePolicy(policy);
|
||||
mgr.setPolicy(null, deviceGroup, policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that default policy can be set multiple times for an appraiser.
|
||||
*
|
||||
* @throws Exception
|
||||
* if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testSetPolicyTwice() throws Exception {
|
||||
TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
policy = (TestPolicy) mgr.savePolicy(policy);
|
||||
DeviceGroup deviceGroup =
|
||||
createDeviceGroupWithDevice("Test Device Group", "Test Device");
|
||||
mgr.setPolicy(appraiser, deviceGroup, policy);
|
||||
Policy retrievedPolicy = mgr.getPolicy(appraiser, deviceGroup);
|
||||
Assert.assertEquals(retrievedPolicy, policy);
|
||||
|
||||
TestPolicy2 policy2 = new TestPolicy2("Other Policy");
|
||||
policy2 = (TestPolicy2) mgr.savePolicy(policy2);
|
||||
mgr.setPolicy(appraiser, deviceGroup, policy2);
|
||||
retrievedPolicy = mgr.getPolicy(appraiser, deviceGroup);
|
||||
Assert.assertEquals(retrievedPolicy, policy2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that if there are multiple device groups in the database, each with
|
||||
* different policies, the correct policies associated with each device
|
||||
* group are returned.
|
||||
*
|
||||
* @throws Exception
|
||||
* if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testSetDifferentPolicesOnDeviceGroups() throws Exception {
|
||||
TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final String policyName2 = "Test Policy 2";
|
||||
TestPolicy policy2 = new TestPolicy(policyName2);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
policy = (TestPolicy) mgr.savePolicy(policy);
|
||||
policy2 = (TestPolicy) mgr.savePolicy(policy2);
|
||||
DeviceGroup deviceGroup =
|
||||
createDeviceGroupWithDevice("Test Device Group", "Test Device");
|
||||
DeviceGroup deviceGroup2 =
|
||||
createDeviceGroupWithDevice("Test Device Group 2", "Test Device 2");
|
||||
mgr.setPolicy(appraiser, deviceGroup, policy);
|
||||
mgr.setPolicy(appraiser, deviceGroup2, policy2);
|
||||
Policy retrievedPolicy = mgr.getPolicy(appraiser, deviceGroup);
|
||||
Policy retrievedPolicy2 = mgr.getPolicy(appraiser, deviceGroup2);
|
||||
Assert.assertEquals(retrievedPolicy, policy);
|
||||
Assert.assertEquals(retrievedPolicy2, policy2);
|
||||
Assert.assertNotEquals(retrievedPolicy2, retrievedPolicy);
|
||||
|
||||
TestPolicy2 otherPolicy = new TestPolicy2("Other Policy");
|
||||
otherPolicy = (TestPolicy2) mgr.savePolicy(otherPolicy);
|
||||
mgr.setPolicy(appraiser, deviceGroup, otherPolicy);
|
||||
retrievedPolicy = mgr.getPolicy(appraiser, deviceGroup);
|
||||
Assert.assertEquals(retrievedPolicy, otherPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that if the policy for a device group is not set, then null
|
||||
* is returned.
|
||||
*
|
||||
* @throws Exception
|
||||
* if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testGetPolicyReturnsNullWhenDeviceGroupPolicyNotSet() throws Exception {
|
||||
final PolicyManager policyMgr = new DBPolicyManager(sessionFactory);
|
||||
|
||||
// save Test Policy
|
||||
TestPolicy testPolicy = new TestPolicy(POLICY_NAME);
|
||||
testPolicy = (TestPolicy) policyMgr.savePolicy(testPolicy);
|
||||
|
||||
// save Test Default Policy
|
||||
TestPolicy testDefaultPolicy = new TestPolicy("Test Default Policy");
|
||||
testDefaultPolicy = (TestPolicy) policyMgr.savePolicy(testDefaultPolicy);
|
||||
|
||||
// create device and put it in Default Group
|
||||
Device deviceInDefaultGroup = new Device("DeviceInDefaultGroup");
|
||||
DeviceGroup defaultGroup = createDeviceGroupWithDevice(
|
||||
DeviceGroup.DEFAULT_GROUP, deviceInDefaultGroup.getName()
|
||||
);
|
||||
|
||||
// create device and put it in Test Device Group
|
||||
Device deviceInTestGroup = new Device("DeviceInTestGroup");
|
||||
DeviceGroup testDeviceGroup = createDeviceGroupWithDevice(
|
||||
"Test Device Group", deviceInTestGroup.getName()
|
||||
);
|
||||
|
||||
// set default policy for TestAppraiser to Test Default Policy
|
||||
policyMgr.setDefaultPolicy(appraiser, testDefaultPolicy);
|
||||
|
||||
// set policy for TestAppraiser & Test Device Group to Test Policy
|
||||
policyMgr.setPolicy(appraiser, testDeviceGroup, testPolicy);
|
||||
|
||||
Assert.assertEquals(policyMgr.getPolicy(appraiser, defaultGroup), testDefaultPolicy);
|
||||
Assert.assertEquals(policyMgr.getPolicy(appraiser, testDeviceGroup), testPolicy);
|
||||
|
||||
Assert.assertEquals(
|
||||
policyMgr.getPolicy(appraiser, deviceInDefaultGroup),
|
||||
testDefaultPolicy
|
||||
);
|
||||
Assert.assertEquals(policyMgr.getPolicy(appraiser, deviceInTestGroup), testPolicy);
|
||||
|
||||
// remove policy for Test Group and make sure the policy for the device in the group is null
|
||||
policyMgr.setPolicy(appraiser, testDeviceGroup, null);
|
||||
Assert.assertNull(policyMgr.getPolicy(appraiser, testDeviceGroup));
|
||||
Assert.assertNull(policyMgr.getPolicy(appraiser, deviceInTestGroup));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that null is returned for null appraiser.
|
||||
*
|
||||
* @throws Exception
|
||||
* if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testGetPolicyNullAppraiser() throws Exception {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
DeviceGroup deviceGroup =
|
||||
createDeviceGroupWithDevice("Test Device Group", "Test Device");
|
||||
final Policy policy = mgr.getPolicy(null, deviceGroup);
|
||||
Assert.assertNull(policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that null is returned when a policy isn't set appraiser.
|
||||
*
|
||||
* @throws Exception
|
||||
* if error occurs while creating test Device
|
||||
*/
|
||||
@Test
|
||||
public void testGetPolicyNoneSet() throws Exception {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
DeviceGroup deviceGroup =
|
||||
createDeviceGroupWithDevice("Test Device Group", "Test Device");
|
||||
final Policy policy = mgr.getPolicy(appraiser, deviceGroup);
|
||||
Assert.assertNull(policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that default policy can be set for an appraiser.
|
||||
*
|
||||
* @throws Exception
|
||||
* occurs if device/deviceGroup could not be persisted
|
||||
*/
|
||||
@Test
|
||||
public void testSetAndGetDefaultPolicy() throws Exception {
|
||||
TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
policy = (TestPolicy) mgr.savePolicy(policy);
|
||||
createDeviceGroupWithDevice(DeviceGroup.DEFAULT_GROUP, "Test Device");
|
||||
mgr.setDefaultPolicy(appraiser, policy);
|
||||
final Policy defaultPolicy = mgr.getDefaultPolicy(appraiser);
|
||||
Assert.assertEquals(defaultPolicy, policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that default policy can be removed for an appraiser.
|
||||
*
|
||||
* @throws Exception
|
||||
* occurs if device/deviceGroup could not be persisted
|
||||
*/
|
||||
@Test
|
||||
public void testSetDefaultPolicyRemove() throws Exception {
|
||||
TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
policy = (TestPolicy) mgr.savePolicy(policy);
|
||||
createDeviceGroupWithDevice(DeviceGroup.DEFAULT_GROUP, "Test Device");
|
||||
mgr.setDefaultPolicy(appraiser, policy);
|
||||
Policy defaultPolicy = mgr.getDefaultPolicy(appraiser);
|
||||
Assert.assertEquals(defaultPolicy, policy);
|
||||
|
||||
mgr.setDefaultPolicy(appraiser, null);
|
||||
defaultPolicy = mgr.getDefaultPolicy(appraiser);
|
||||
Assert.assertNull(defaultPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a <code>NullPointerExcpetion</code> is thrown if appraiser is
|
||||
* null.
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testSetDefaultPolicyNullAppraiser() {
|
||||
TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
policy = (TestPolicy) mgr.savePolicy(policy);
|
||||
mgr.setDefaultPolicy(null, policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that default policy can be set multiple times for an appraiser.
|
||||
*
|
||||
* @throws Exception
|
||||
* occurs if device/deviceGroup could not be persisted
|
||||
*/
|
||||
@Test
|
||||
public void testSetDefaultPolicyTwice() throws Exception {
|
||||
TestPolicy policy = new TestPolicy(POLICY_NAME);
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
policy = (TestPolicy) mgr.savePolicy(policy);
|
||||
createDeviceGroupWithDevice(DeviceGroup.DEFAULT_GROUP, "Test Device");
|
||||
mgr.setDefaultPolicy(appraiser, policy);
|
||||
Policy defaultPolicy = mgr.getDefaultPolicy(appraiser);
|
||||
Assert.assertEquals(defaultPolicy, policy);
|
||||
|
||||
TestPolicy2 policy2 = new TestPolicy2("Other Policy");
|
||||
policy2 = (TestPolicy2) mgr.savePolicy(policy2);
|
||||
mgr.setDefaultPolicy(appraiser, policy2);
|
||||
defaultPolicy = mgr.getDefaultPolicy(appraiser);
|
||||
Assert.assertEquals(defaultPolicy, policy2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that null is returned for null appraiser.
|
||||
*/
|
||||
@Test
|
||||
public void testGetDefaultPolicyNullAppraiser() {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
final Policy policy = mgr.getDefaultPolicy(null);
|
||||
Assert.assertNull(policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that null is returned for null appraiser.
|
||||
*/
|
||||
@Test
|
||||
public void testGetDefaultPolicyNoneSet() {
|
||||
final PolicyManager mgr = new DBPolicyManager(sessionFactory);
|
||||
final Policy policy = mgr.getDefaultPolicy(appraiser);
|
||||
Assert.assertNull(policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the group count is returned for policies.
|
||||
* @throws Exception if createDeviceGroup fails.
|
||||
*/
|
||||
@Test
|
||||
public void testGetGroupCountForPolicy() throws Exception {
|
||||
LOGGER.debug("started testGetGroupCountForPolicy");
|
||||
final PolicyManager policyManager = new DBPolicyManager(sessionFactory);
|
||||
final Policy policy1 = new TestPolicy("Policy1");
|
||||
final Policy policy2 = new TestPolicy("Policy2");
|
||||
final Policy policy3 = new TestPolicy("Policy3");
|
||||
final Policy policy4 = new TestPolicy("Policy4");
|
||||
final DeviceGroup deviceGroup1 = createDeviceGroupWithDevice("Group1", "Device1");
|
||||
final DeviceGroup deviceGroup2 = createDeviceGroupWithDevice("Group2", "Device2");
|
||||
final DeviceGroup deviceGroup3 = createDeviceGroupWithDevice("Group3", "Device3");
|
||||
|
||||
policyManager.savePolicy(policy1);
|
||||
policyManager.savePolicy(policy2);
|
||||
policyManager.savePolicy(policy3);
|
||||
policyManager.savePolicy(policy4);
|
||||
|
||||
policyManager.setPolicy(appraiser, deviceGroup1, policy2);
|
||||
policyManager.setPolicy(appraiser, deviceGroup2, policy4);
|
||||
policyManager.setPolicy(appraiser, deviceGroup3, policy4);
|
||||
|
||||
Assert.assertEquals(policyManager.getGroupCountForPolicy(policy1), 0);
|
||||
Assert.assertEquals(policyManager.getGroupCountForPolicy(policy2), 1);
|
||||
Assert.assertEquals(policyManager.getGroupCountForPolicy(policy3), 0);
|
||||
Assert.assertEquals(policyManager.getGroupCountForPolicy(policy4), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the group count for a null policy is 0.
|
||||
* No group is using a null policy.
|
||||
*/
|
||||
@Test
|
||||
public void testGetGroupCountForPolicyNull() {
|
||||
LOGGER.debug("started testGetGroupCountForPolicyNull");
|
||||
final PolicyManager policyManager = new DBPolicyManager(sessionFactory);
|
||||
|
||||
Assert.assertEquals(policyManager.getGroupCountForPolicy(null), 0);
|
||||
}
|
||||
|
||||
private Policy createPolicy(final PolicyManager mgr)
|
||||
throws PolicyManagerException {
|
||||
return createPolicy(mgr, null);
|
||||
}
|
||||
|
||||
private Policy createPolicy(final PolicyManager mgr, final String name)
|
||||
throws PolicyManagerException {
|
||||
LOGGER.debug("creating policy in db");
|
||||
String policyName = name;
|
||||
if (name == null) {
|
||||
policyName = POLICY_NAME;
|
||||
}
|
||||
final TestPolicy policy = new TestPolicy(policyName);
|
||||
return mgr.savePolicy(policy);
|
||||
}
|
||||
|
||||
private DeviceGroup createDeviceGroupWithDevice(
|
||||
final String deviceGroupName, final String deviceName
|
||||
) throws Exception {
|
||||
DeviceGroupManager deviceGroupManager = new DBDeviceGroupManager(sessionFactory);
|
||||
DeviceManager deviceManager = new DBDeviceManager(sessionFactory);
|
||||
Device device = DeviceTest.getTestDevice(deviceName);
|
||||
DeviceGroup deviceGroup = new DeviceGroup(deviceGroupName);
|
||||
deviceGroup = deviceGroupManager.saveDeviceGroup(deviceGroup);
|
||||
deviceGroup.addDevice(device);
|
||||
device.setDeviceGroup(deviceGroup);
|
||||
deviceManager.saveDevice(device);
|
||||
deviceGroupManager.updateDeviceGroup(deviceGroup);
|
||||
return deviceGroup;
|
||||
}
|
||||
|
||||
private boolean isInDatabase(final String name) {
|
||||
LOGGER.debug("checking if policy {} is in database", name);
|
||||
Policy policy = null;
|
||||
Transaction tx = null;
|
||||
Session session = sessionFactory.unwrap(org.hibernate.Session.class);
|
||||
try {
|
||||
LOGGER.debug("retrieving policy");
|
||||
tx = session.beginTransaction();
|
||||
CriteriaBuilder builder = session.getCriteriaBuilder();
|
||||
CriteriaQuery<Policy> criteriaQuery = builder.createQuery(Policy.class);
|
||||
Root<Policy> root = criteriaQuery.from(Policy.class);
|
||||
criteriaQuery.select(root).where(builder.equal(root.get("name"), name));
|
||||
Query<Policy> query = session.createQuery(criteriaQuery);
|
||||
policy = query.getSingleResult();
|
||||
// policy =
|
||||
// (Policy) session.createCriteria(Policy.class)
|
||||
// .add(Restrictions.eq("name", name)).uniqueResult();
|
||||
session.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
final String msg = "unable to retrieve policy";
|
||||
LOGGER.error(msg, e);
|
||||
if (tx != null) {
|
||||
LOGGER.debug("rolling back transaction");
|
||||
tx.rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return policy != null;
|
||||
}
|
||||
}
|
@ -34,14 +34,10 @@ public class DBReportRequestStateManagerTest extends SpringPersistenceTest {
|
||||
*/
|
||||
@BeforeClass
|
||||
public final void setup() throws Exception {
|
||||
DeviceGroup group = new DeviceGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
new DBDeviceGroupManager(sessionFactory).saveDeviceGroup(group);
|
||||
|
||||
Device testDevice;
|
||||
DBDeviceManager dbDeviceManager = new DBDeviceManager(sessionFactory);
|
||||
for (int i = 0; i < NUMBER_OF_DEVICES; i++) {
|
||||
testDevice = DeviceTest.getTestDevice("Device " + i);
|
||||
testDevice.setDeviceGroup(group);
|
||||
testDevices.add(dbDeviceManager.save(testDevice));
|
||||
}
|
||||
}
|
||||
@ -72,7 +68,7 @@ public class DBReportRequestStateManagerTest extends SpringPersistenceTest {
|
||||
DBReportRequestStateManager mgr = new DBReportRequestStateManager(sessionFactory);
|
||||
Device device = testDevices.get(0);
|
||||
ReportRequestState state = getTestReportRequestState(device);
|
||||
state.setDueDate(DeviceGroup.MINUTE_MS_INTERVAL);
|
||||
state.setDueDate(ReportRequestState.MINUTE_MS_INTERVAL);
|
||||
mgr.saveState(state);
|
||||
|
||||
ReportRequestState retrievedState = mgr.getState(device);
|
||||
@ -117,7 +113,7 @@ public class DBReportRequestStateManagerTest extends SpringPersistenceTest {
|
||||
ReportRequestState newState = getTestReportRequestState(
|
||||
testDevices.get(0)
|
||||
);
|
||||
newState.setDueDate(DeviceGroup.MINUTE_MS_INTERVAL);
|
||||
newState.setDueDate(ReportRequestState.MINUTE_MS_INTERVAL);
|
||||
mgr.update(newState);
|
||||
Assert.assertEquals(mgr.getState(testDevices.get(0)), newState);
|
||||
}
|
||||
@ -130,7 +126,7 @@ public class DBReportRequestStateManagerTest extends SpringPersistenceTest {
|
||||
public final void testUpdateExistentState() {
|
||||
DBReportRequestStateManager mgr = new DBReportRequestStateManager(sessionFactory);
|
||||
ReportRequestState deviceState = getTestReportRequestState(testDevices.get(0));
|
||||
deviceState.setDueDate(DeviceGroup.MINUTE_MS_INTERVAL);
|
||||
deviceState.setDueDate(ReportRequestState.MINUTE_MS_INTERVAL);
|
||||
ReportRequestState newState = mgr.saveState(deviceState);
|
||||
newState.setReportRequestType(ReportRequestType.ON_DEMAND_REPORT);
|
||||
mgr.update(newState);
|
||||
@ -156,7 +152,7 @@ public class DBReportRequestStateManagerTest extends SpringPersistenceTest {
|
||||
public final void testDeleteExistentState() {
|
||||
DBReportRequestStateManager mgr = new DBReportRequestStateManager(sessionFactory);
|
||||
ReportRequestState deviceState = getTestReportRequestState(testDevices.get(0));
|
||||
deviceState.setDueDate(DeviceGroup.MINUTE_MS_INTERVAL);
|
||||
deviceState.setDueDate(ReportRequestState.MINUTE_MS_INTERVAL);
|
||||
ReportRequestState state = mgr.saveState(deviceState);
|
||||
mgr.deleteState(state);
|
||||
Assert.assertEquals(mgr.getList(ReportRequestState.class).size(), 0);
|
||||
|
@ -1,12 +1,13 @@
|
||||
package hirs.attestationca.service;
|
||||
|
||||
import hirs.attestationca.persist.SpringPersistenceTest;
|
||||
import hirs.appraiser.SupplyChainAppraiser;
|
||||
import hirs.attestationca.persist.SpringPersistenceTest;
|
||||
import hirs.attestationca.servicemanager.DBCertificateManager;
|
||||
import hirs.attestationca.servicemanager.DBDeviceManager;
|
||||
import hirs.attestationca.validation.SupplyChainValidationServiceImpl;
|
||||
import hirs.data.persist.AppraisalStatus;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceInfoReport;
|
||||
import hirs.data.persist.policy.SupplyChainPolicy;
|
||||
import hirs.data.persist.SupplyChainValidation;
|
||||
import hirs.data.persist.SupplyChainValidationSummary;
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
@ -14,15 +15,13 @@ import hirs.data.persist.certificate.CertificateAuthorityCredential;
|
||||
import hirs.data.persist.certificate.DeviceAssociatedCertificate;
|
||||
import hirs.data.persist.certificate.EndorsementCredential;
|
||||
import hirs.data.persist.certificate.PlatformCredential;
|
||||
import hirs.persist.AppraiserManager;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.data.persist.policy.SupplyChainPolicy;
|
||||
import hirs.persist.CrudManager;
|
||||
import hirs.attestationca.servicemanager.DBCertificateManager;
|
||||
import hirs.attestationca.servicemanager.DBDeviceManager;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.PolicyManager;
|
||||
import hirs.persist.ReferenceDigestManager;
|
||||
import hirs.persist.ReferenceEventManager;
|
||||
import hirs.persist.service.AppraiserService;
|
||||
import hirs.persist.service.CertificateService;
|
||||
import hirs.persist.service.PolicyService;
|
||||
import hirs.persist.service.ReferenceDigestValueService;
|
||||
import hirs.validation.CredentialValidator;
|
||||
import hirs.validation.SupplyChainCredentialValidator;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@ -75,13 +74,13 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
private static final String NUC_EC = "/certificates/nuc_ec.pem";
|
||||
|
||||
@Mock
|
||||
private PolicyManager policyManager;
|
||||
private PolicyService policyManager;
|
||||
|
||||
@Mock
|
||||
private AppraiserManager appraiserManager;
|
||||
private AppraiserService appraiserManager;
|
||||
|
||||
@Mock
|
||||
private CertificateManager certificateManager;
|
||||
private CertificateService certificateManager;
|
||||
|
||||
@Mock
|
||||
private CredentialValidator supplyChainCredentialValidator;
|
||||
@ -90,10 +89,7 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
private CrudManager<SupplyChainValidationSummary> supplyChainValidationSummaryDBManager;
|
||||
|
||||
@Mock
|
||||
private ReferenceDigestManager referenceDigestManager;
|
||||
|
||||
@Mock
|
||||
private ReferenceEventManager referenceEventManager;
|
||||
private ReferenceDigestValueService referenceEventManager;
|
||||
|
||||
@InjectMocks
|
||||
private SupplyChainValidationServiceImpl service;
|
||||
@ -179,11 +175,9 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
public void teardown() {
|
||||
DBCertificateManager certMan = new DBCertificateManager(sessionFactory);
|
||||
DBDeviceManager deviceMan = new DBDeviceManager(sessionFactory);
|
||||
DBDeviceGroupManager groupMan = new DBDeviceGroupManager(sessionFactory);
|
||||
|
||||
certMan.deleteAll();
|
||||
deviceMan.deleteAll();
|
||||
groupMan.deleteAll();
|
||||
}
|
||||
/**
|
||||
* All validations enabled, all pass.
|
||||
@ -439,7 +433,7 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
*/
|
||||
@Test
|
||||
public final void testGetCaChain() throws URISyntaxException, IOException, KeyStoreException {
|
||||
CertificateManager realCertMan = new DBCertificateManager(sessionFactory);
|
||||
CertificateServiceImpl realCertMan = new CertificateServiceImpl(sessionFactory);
|
||||
|
||||
// the main service in this class only uses mocked managers, we need a real DB certificate
|
||||
// manager for this test, so we make a second service.
|
||||
@ -450,7 +444,6 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
null,
|
||||
supplyChainValidationSummaryDBManager,
|
||||
supplyChainCredentialValidator,
|
||||
referenceDigestManager,
|
||||
referenceEventManager
|
||||
);
|
||||
|
||||
@ -486,9 +479,9 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
Assert.assertNull(ks.getCertificate(stmCaAlias));
|
||||
Assert.assertNull(ks.getCertificate(gsCaAlias));
|
||||
|
||||
realCertMan.delete(endorsementCredential);
|
||||
realCertMan.delete(rootCa);
|
||||
realCertMan.delete(globalSignCaCert);
|
||||
realCertMan.deleteObjectById(endorsementCredential.getId());
|
||||
realCertMan.deleteObjectById(rootCa.getId());
|
||||
realCertMan.deleteObjectById(globalSignCaCert.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -501,7 +494,7 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
@Test
|
||||
public final void testGetNotFullCaChain() throws URISyntaxException, IOException,
|
||||
KeyStoreException {
|
||||
CertificateManager realCertMan = new DBCertificateManager(sessionFactory);
|
||||
CertificateServiceImpl realCertMan = new CertificateServiceImpl(sessionFactory);
|
||||
|
||||
// the main service in this class only uses mocked managers, we need a real DB certificate
|
||||
// manager for this test, so we make a second service.
|
||||
@ -512,7 +505,6 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
null,
|
||||
supplyChainValidationSummaryDBManager,
|
||||
supplyChainCredentialValidator,
|
||||
referenceDigestManager,
|
||||
referenceEventManager
|
||||
);
|
||||
|
||||
@ -536,8 +528,8 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
Assert.assertNull(ks.getCertificate(stmCaAlias));
|
||||
Assert.assertEquals(ks.size(), 0);
|
||||
|
||||
realCertMan.delete(endorsementCredential);
|
||||
realCertMan.delete(rootCa);
|
||||
realCertMan.deleteObjectById(endorsementCredential.getId());
|
||||
realCertMan.deleteObjectById(rootCa.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -549,7 +541,7 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
@Test
|
||||
public final void testGetEmptyCaChain() throws URISyntaxException, IOException,
|
||||
KeyStoreException {
|
||||
CertificateManager realCertMan = new DBCertificateManager(sessionFactory);
|
||||
CertificateServiceImpl realCertMan = new CertificateServiceImpl(sessionFactory);
|
||||
|
||||
// the main service in this class only uses mocked managers, we need a real DB certificate
|
||||
// manager for this test, so we make a second service.
|
||||
@ -560,7 +552,6 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
null,
|
||||
supplyChainValidationSummaryDBManager,
|
||||
supplyChainCredentialValidator,
|
||||
referenceDigestManager,
|
||||
referenceEventManager
|
||||
);
|
||||
|
||||
@ -574,7 +565,7 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
|
||||
Assert.assertEquals(ks.size(), 0);
|
||||
|
||||
realCertMan.delete(endorsementCredential);
|
||||
realCertMan.deleteObjectById(endorsementCredential.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -587,7 +578,7 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
@Test
|
||||
public final void testGetCaChainWithExtraCerts() throws URISyntaxException, IOException,
|
||||
KeyStoreException {
|
||||
CertificateManager realCertMan = new DBCertificateManager(sessionFactory);
|
||||
CertificateServiceImpl realCertMan = new CertificateServiceImpl(sessionFactory);
|
||||
|
||||
// the main service in this class only uses mocked managers, we need a real DB certificate
|
||||
// manager for this test, so we make a second service.
|
||||
@ -598,7 +589,6 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
null,
|
||||
supplyChainValidationSummaryDBManager,
|
||||
supplyChainCredentialValidator,
|
||||
referenceDigestManager,
|
||||
referenceEventManager
|
||||
);
|
||||
|
||||
@ -635,10 +625,10 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
Assert.assertNull(ks.getCertificate(gsCaAlias));
|
||||
Assert.assertEquals(ks.size(), 0);
|
||||
|
||||
realCertMan.delete(endorsementCredential);
|
||||
realCertMan.delete(rootCa);
|
||||
realCertMan.delete(globalSignCaCert);
|
||||
realCertMan.delete(intelCa);
|
||||
realCertMan.deleteObjectById(endorsementCredential.getId());
|
||||
realCertMan.deleteObjectById(rootCa.getId());
|
||||
realCertMan.deleteObjectById(globalSignCaCert.getId());
|
||||
realCertMan.deleteObjectById(intelCa.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -649,7 +639,7 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
*/
|
||||
@Test
|
||||
public final void testGetPcCaChain() throws URISyntaxException, IOException, KeyStoreException {
|
||||
CertificateManager realCertMan = new DBCertificateManager(sessionFactory);
|
||||
CertificateServiceImpl realCertMan = new CertificateServiceImpl(sessionFactory);
|
||||
|
||||
// the main service in this class only uses mocked managers, we need a real DB certificate
|
||||
// manager for this test, so we make a second service.
|
||||
@ -660,7 +650,6 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
null,
|
||||
supplyChainValidationSummaryDBManager,
|
||||
supplyChainCredentialValidator,
|
||||
referenceDigestManager,
|
||||
referenceEventManager
|
||||
);
|
||||
|
||||
@ -683,8 +672,8 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
Assert.assertNotNull(ks.getCertificate(intelCaAlias));
|
||||
Assert.assertEquals(ks.size(), 1);
|
||||
|
||||
realCertMan.delete(platformCredential);
|
||||
realCertMan.delete(intelCa);
|
||||
realCertMan.deleteObjectById(platformCredential.getId());
|
||||
realCertMan.deleteObjectById(intelCa.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -697,7 +686,7 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
@Test
|
||||
public final void testGetPcCaChainNoMatches() throws URISyntaxException, IOException,
|
||||
KeyStoreException {
|
||||
CertificateManager realCertMan = new DBCertificateManager(sessionFactory);
|
||||
CertificateServiceImpl realCertMan = new CertificateServiceImpl(sessionFactory);
|
||||
|
||||
// the main service in this class only uses mocked managers, we need a real DB certificate
|
||||
// manager for this test, so we make a second service.
|
||||
@ -708,7 +697,6 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
null,
|
||||
supplyChainValidationSummaryDBManager,
|
||||
supplyChainCredentialValidator,
|
||||
referenceDigestManager,
|
||||
referenceEventManager
|
||||
);
|
||||
|
||||
@ -733,9 +721,9 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
|
||||
Assert.assertEquals(ks.size(), 0);
|
||||
|
||||
realCertMan.delete(platformCredential);
|
||||
realCertMan.delete(rootCa);
|
||||
realCertMan.delete(globalSignCaCert);
|
||||
realCertMan.deleteObjectById(platformCredential.getId());
|
||||
realCertMan.deleteObjectById(rootCa.getId());
|
||||
realCertMan.deleteObjectById(globalSignCaCert.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -751,7 +739,7 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
when(policy.isPcValidationEnabled()).thenReturn(false);
|
||||
when(policy.isPcAttributeValidationEnabled()).thenReturn(false);
|
||||
|
||||
CertificateManager realCertMan = new DBCertificateManager(sessionFactory);
|
||||
CertificateServiceImpl realCertMan = new CertificateServiceImpl(sessionFactory);
|
||||
Device storedDevice = getStoredTestDevice();
|
||||
|
||||
SupplyChainValidationServiceImpl mostlyMockedService = new SupplyChainValidationServiceImpl(
|
||||
@ -761,7 +749,6 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
null,
|
||||
supplyChainValidationSummaryDBManager,
|
||||
new SupplyChainCredentialValidator(),
|
||||
referenceDigestManager,
|
||||
referenceEventManager
|
||||
);
|
||||
|
||||
@ -807,20 +794,16 @@ public class SupplyChainValidationServiceImplTest extends SpringPersistenceTest
|
||||
|
||||
Assert.assertEquals(updatedStoredEc.getDevice().getId(), storedDevice.getId());
|
||||
|
||||
realCertMan.delete(stmTpmEkIntermediateCA);
|
||||
realCertMan.delete(globalSignTpmRoot);
|
||||
realCertMan.delete(stmEkRootCa);
|
||||
realCertMan.delete(nucEc);
|
||||
realCertMan.deleteObjectById(stmTpmEkIntermediateCA.getId());
|
||||
realCertMan.deleteObjectById(globalSignTpmRoot.getId());
|
||||
realCertMan.deleteObjectById(stmEkRootCa.getId());
|
||||
realCertMan.deleteObjectById(nucEc.getId());
|
||||
}
|
||||
|
||||
private Device getStoredTestDevice() {
|
||||
DeviceManager deviceManager = new DBDeviceManager(sessionFactory);
|
||||
DeviceGroupManager deviceGroupManager = new DBDeviceGroupManager(sessionFactory);
|
||||
|
||||
DeviceGroup testGroup = new DeviceGroup("group1");
|
||||
Device testDevice = new Device("SCVSI-test");
|
||||
|
||||
testDevice.setDeviceGroup(deviceGroupManager.saveDeviceGroup(testGroup));
|
||||
return deviceManager.saveDevice(testDevice);
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,11 @@ import hirs.data.persist.certificate.CertificateAuthorityCredential;
|
||||
import hirs.data.persist.certificate.EndorsementCredential;
|
||||
import hirs.data.persist.certificate.IssuedAttestationCertificate;
|
||||
import hirs.data.persist.certificate.PlatformCredential;
|
||||
import hirs.persist.service.CertificateService;
|
||||
import hirs.persist.CriteriaModifier;
|
||||
import hirs.persist.CrudManager;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.OrderedListQuerier;
|
||||
import hirs.persist.OrderedQuery;
|
||||
import hirs.persist.service.CertificateService;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bouncycastle.util.encoders.DecoderException;
|
||||
import org.hibernate.Criteria;
|
||||
@ -65,7 +65,7 @@ public class CertificateRequestPageController extends PageController<NoPageParam
|
||||
@Autowired
|
||||
private final CertificateService certificateService;
|
||||
@Autowired
|
||||
private final OrderedListQuerier<Certificate> dataTableQuerier;
|
||||
private final OrderedQuery<Certificate> dataTableQuerier;
|
||||
|
||||
private CertificateAuthorityCredential certificateAuthorityCredential;
|
||||
|
||||
|
@ -41,8 +41,9 @@ public class DevicesPageController extends PageController<NoPageParams> {
|
||||
|
||||
@Autowired
|
||||
private final DeviceService deviceService;
|
||||
// this may be what I need to do for all of them
|
||||
@Autowired
|
||||
private final DBManager<Certificate> certificateDBManager; // this may be what I need to do for all of them
|
||||
private final DBManager<Certificate> certificateDBManager;
|
||||
private static final Logger LOGGER = getLogger(DevicesPageController.class);
|
||||
|
||||
/**
|
||||
|
@ -13,10 +13,9 @@ import hirs.data.persist.SupportReferenceManifest;
|
||||
import hirs.data.persist.SwidResource;
|
||||
import hirs.data.persist.certificate.CertificateAuthorityCredential;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.ReferenceDigestManager;
|
||||
import hirs.persist.ReferenceEventManager;
|
||||
import hirs.persist.ReferenceManifestManager;
|
||||
import hirs.persist.service.CertificateService;
|
||||
import hirs.persist.service.ReferenceDigestValueService;
|
||||
import hirs.persist.service.ReferenceManifestService;
|
||||
import hirs.tpm.eventlog.TCGEventLog;
|
||||
import hirs.tpm.eventlog.TpmPcrEvent;
|
||||
import hirs.utils.ReferenceManifestValidator;
|
||||
@ -53,11 +52,9 @@ public class ReferenceManifestDetailsPageController
|
||||
extends PageController<ReferenceManifestDetailsPageParams> {
|
||||
|
||||
@Autowired
|
||||
private final ReferenceManifestManager referenceManifestManager;
|
||||
private final ReferenceManifestService referenceManifestService;
|
||||
@Autowired
|
||||
private final ReferenceDigestManager referenceDigestManager;
|
||||
@Autowired
|
||||
private final ReferenceEventManager referenceEventManager;
|
||||
private final ReferenceDigestValueService referenceDigestValueService;
|
||||
@Autowired
|
||||
private final CertificateService certificateService;
|
||||
private static final ReferenceManifestValidator RIM_VALIDATOR
|
||||
@ -68,21 +65,18 @@ public class ReferenceManifestDetailsPageController
|
||||
/**
|
||||
* Constructor providing the Page's display and routing specification.
|
||||
*
|
||||
* @param referenceManifestManager the reference manifest manager.
|
||||
* @param referenceDigestManager the reference digest manager.
|
||||
* @param referenceEventManager the reference event manager.
|
||||
* @param referenceManifestService the reference manifest service.
|
||||
* @param referenceDigestValueService the reference event service.
|
||||
* @param certificateService the certificate service.
|
||||
*/
|
||||
@Autowired
|
||||
public ReferenceManifestDetailsPageController(
|
||||
final ReferenceManifestManager referenceManifestManager,
|
||||
final ReferenceDigestManager referenceDigestManager,
|
||||
final ReferenceEventManager referenceEventManager,
|
||||
final ReferenceManifestService referenceManifestService,
|
||||
final ReferenceDigestValueService referenceDigestValueService,
|
||||
final CertificateService certificateService) {
|
||||
super(Page.RIM_DETAILS);
|
||||
this.referenceManifestManager = referenceManifestManager;
|
||||
this.referenceDigestManager = referenceDigestManager;
|
||||
this.referenceEventManager = referenceEventManager;
|
||||
this.referenceManifestService = referenceManifestService;
|
||||
this.referenceDigestValueService = referenceDigestValueService;
|
||||
this.certificateService = certificateService;
|
||||
}
|
||||
|
||||
@ -113,8 +107,8 @@ public class ReferenceManifestDetailsPageController
|
||||
} else {
|
||||
try {
|
||||
UUID uuid = UUID.fromString(params.getId());
|
||||
data.putAll(getRimDetailInfo(uuid, referenceManifestManager,
|
||||
referenceDigestManager, referenceEventManager, certificateService));
|
||||
data.putAll(getRimDetailInfo(uuid, referenceManifestService,
|
||||
referenceDigestValueService, certificateService));
|
||||
} catch (IllegalArgumentException iaEx) {
|
||||
String uuidError = "Failed to parse ID from: " + params.getId();
|
||||
messages.addError(uuidError);
|
||||
@ -141,9 +135,8 @@ public class ReferenceManifestDetailsPageController
|
||||
* Gathers all information and returns it for displays.
|
||||
*
|
||||
* @param uuid database reference for the requested RIM.
|
||||
* @param referenceManifestManager the reference manifest manager.
|
||||
* @param referenceDigestManager the reference digest manager.
|
||||
* @param referenceEventManager the reference event manager.
|
||||
* @param referenceManifestService the reference manifest service.
|
||||
* @param referenceDigestValueService the reference digest value service.
|
||||
* @param certificateService the certificate service.
|
||||
* @return mapping of the RIM information from the database.
|
||||
* @throws java.io.IOException error for reading file bytes.
|
||||
@ -151,34 +144,33 @@ public class ReferenceManifestDetailsPageController
|
||||
* @throws CertificateException if a certificate doesn't parse.
|
||||
*/
|
||||
public static HashMap<String, Object> getRimDetailInfo(final UUID uuid,
|
||||
final ReferenceManifestManager referenceManifestManager,
|
||||
final ReferenceDigestManager referenceDigestManager,
|
||||
final ReferenceEventManager referenceEventManager,
|
||||
final ReferenceManifestService referenceManifestService,
|
||||
final ReferenceDigestValueService referenceDigestValueService,
|
||||
final CertificateService certificateService)
|
||||
throws IOException,
|
||||
CertificateException, NoSuchAlgorithmException {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
|
||||
BaseReferenceManifest bRim = BaseReferenceManifest.select(referenceManifestManager)
|
||||
BaseReferenceManifest bRim = BaseReferenceManifest.select(referenceManifestService)
|
||||
.byEntityId(uuid).getRIM();
|
||||
|
||||
if (bRim != null) {
|
||||
data.putAll(getBaseRimInfo(bRim, referenceManifestManager, certificateService));
|
||||
data.putAll(getBaseRimInfo(bRim, referenceManifestService, certificateService));
|
||||
}
|
||||
|
||||
SupportReferenceManifest sRim = SupportReferenceManifest.select(referenceManifestManager)
|
||||
SupportReferenceManifest sRim = SupportReferenceManifest.select(referenceManifestService)
|
||||
.byEntityId(uuid).getRIM();
|
||||
|
||||
if (sRim != null) {
|
||||
data.putAll(getSupportRimInfo(sRim, referenceManifestManager));
|
||||
data.putAll(getSupportRimInfo(sRim, referenceManifestService));
|
||||
}
|
||||
|
||||
EventLogMeasurements bios = EventLogMeasurements.select(referenceManifestManager)
|
||||
EventLogMeasurements bios = EventLogMeasurements.select(referenceManifestService)
|
||||
.byEntityId(uuid).getRIM();
|
||||
|
||||
if (bios != null) {
|
||||
data.putAll(getMeasurementsRimInfo(bios, referenceManifestManager,
|
||||
referenceDigestManager, referenceEventManager));
|
||||
data.putAll(getMeasurementsRimInfo(bios, referenceManifestService,
|
||||
referenceDigestValueService));
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -189,7 +181,7 @@ public class ReferenceManifestDetailsPageController
|
||||
* Gathers all information and returns it for displays.
|
||||
*
|
||||
* @param baseRim established ReferenceManifest Type.
|
||||
* @param referenceManifestManager the reference manifest manager.
|
||||
* @param referenceManifestService the reference manifest service.
|
||||
* @param certificateService the certificate service.
|
||||
* @return mapping of the RIM information from the database.
|
||||
* @throws java.io.IOException error for reading file bytes.
|
||||
@ -198,7 +190,7 @@ public class ReferenceManifestDetailsPageController
|
||||
*/
|
||||
private static HashMap<String, Object> getBaseRimInfo(
|
||||
final BaseReferenceManifest baseRim,
|
||||
final ReferenceManifestManager referenceManifestManager,
|
||||
final ReferenceManifestService referenceManifestService,
|
||||
final CertificateService certificateService)
|
||||
throws IOException, CertificateException, NoSuchAlgorithmException {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
@ -232,7 +224,7 @@ public class ReferenceManifestDetailsPageController
|
||||
data.put("linkHref", baseRim.getLinkHref());
|
||||
data.put("linkHrefLink", "");
|
||||
for (BaseReferenceManifest bRim : BaseReferenceManifest
|
||||
.select(referenceManifestManager).getRIMs()) {
|
||||
.select(referenceManifestService).getRIMs()) {
|
||||
if (baseRim.getLinkHref().contains(bRim.getTagId())) {
|
||||
data.put("linkHrefLink", bRim.getId());
|
||||
}
|
||||
@ -253,7 +245,7 @@ public class ReferenceManifestDetailsPageController
|
||||
data.put("pcUriLocal", baseRim.getPcURILocal());
|
||||
data.put("rimLinkHash", baseRim.getRimLinkHash());
|
||||
if (baseRim.getRimLinkHash() != null) {
|
||||
ReferenceManifest rim = BaseReferenceManifest.select(referenceManifestManager)
|
||||
ReferenceManifest rim = BaseReferenceManifest.select(referenceManifestService)
|
||||
.byHexDecHash(baseRim.getRimLinkHash()).getRIM();
|
||||
if (rim != null) {
|
||||
data.put("rimLinkId", rim.getId());
|
||||
@ -269,14 +261,14 @@ public class ReferenceManifestDetailsPageController
|
||||
SupportReferenceManifest support = null;
|
||||
|
||||
if (baseRim.getAssociatedRim() == null) {
|
||||
support = SupportReferenceManifest.select(referenceManifestManager)
|
||||
support = SupportReferenceManifest.select(referenceManifestService)
|
||||
.byManufacturer(baseRim.getPlatformManufacturer())
|
||||
.getRIM();
|
||||
if (support != null) {
|
||||
baseRim.setAssociatedRim(support.getId());
|
||||
}
|
||||
} else {
|
||||
support = SupportReferenceManifest.select(referenceManifestManager)
|
||||
support = SupportReferenceManifest.select(referenceManifestService)
|
||||
.byEntityId(baseRim.getAssociatedRim()).getRIM();
|
||||
}
|
||||
// going to have to pull the filename and grab that from the DB
|
||||
@ -343,7 +335,7 @@ public class ReferenceManifestDetailsPageController
|
||||
* Gathers all information and returns it for displays.
|
||||
*
|
||||
* @param support established ReferenceManifest Type.
|
||||
* @param referenceManifestManager the reference manifest manager.
|
||||
* @param referenceManifestService the reference manifest service.
|
||||
* @return mapping of the RIM information from the database.
|
||||
* @throws java.io.IOException error for reading file bytes.
|
||||
* @throws NoSuchAlgorithmException If an unknown Algorithm is encountered.
|
||||
@ -351,21 +343,21 @@ public class ReferenceManifestDetailsPageController
|
||||
*/
|
||||
private static HashMap<String, Object> getSupportRimInfo(
|
||||
final SupportReferenceManifest support,
|
||||
final ReferenceManifestManager referenceManifestManager)
|
||||
final ReferenceManifestService referenceManifestService)
|
||||
throws IOException, CertificateException, NoSuchAlgorithmException {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
EventLogMeasurements measurements = null;
|
||||
|
||||
if (support.getAssociatedRim() == null) {
|
||||
Set<BaseReferenceManifest> baseRims = BaseReferenceManifest
|
||||
.select(referenceManifestManager)
|
||||
.select(referenceManifestService)
|
||||
.byRimType(ReferenceManifest.BASE_RIM).getRIMs();
|
||||
for (BaseReferenceManifest baseRim : baseRims) {
|
||||
if (baseRim != null && baseRim.getAssociatedRim() != null
|
||||
&& baseRim.getAssociatedRim().equals(support.getId())) {
|
||||
support.setAssociatedRim(baseRim.getId());
|
||||
try {
|
||||
referenceManifestManager.update(support);
|
||||
referenceManifestService.updateReferenceManifest(support);
|
||||
} catch (DBManagerException ex) {
|
||||
LOGGER.error("Failed to update Support RIM", ex);
|
||||
}
|
||||
@ -377,7 +369,7 @@ public class ReferenceManifestDetailsPageController
|
||||
// testing this independent of the above if statement because the above
|
||||
// starts off checking if associated rim is null; that is irrelevant for
|
||||
// this statement.
|
||||
measurements = EventLogMeasurements.select(referenceManifestManager)
|
||||
measurements = EventLogMeasurements.select(referenceManifestService)
|
||||
.byHexDecHash(support.getHexDecHash()).getRIM();
|
||||
|
||||
if (support.isSwidPatch()) {
|
||||
@ -503,9 +495,8 @@ public class ReferenceManifestDetailsPageController
|
||||
* Gathers all information and returns it for displays.
|
||||
*
|
||||
* @param measurements established ReferenceManifest Type.
|
||||
* @param referenceManifestManager the reference manifest manager.
|
||||
* @param referenceDigestManager the reference digest manager.
|
||||
* @param referenceEventManager the reference event manager.
|
||||
* @param referenceManifestService the reference manifest service.
|
||||
* @param referenceDigestValueService the reference digest value service.
|
||||
* @return mapping of the RIM information from the database.
|
||||
* @throws java.io.IOException error for reading file bytes.
|
||||
* @throws NoSuchAlgorithmException If an unknown Algorithm is encountered.
|
||||
@ -513,9 +504,8 @@ public class ReferenceManifestDetailsPageController
|
||||
*/
|
||||
private static HashMap<String, Object> getMeasurementsRimInfo(
|
||||
final EventLogMeasurements measurements,
|
||||
final ReferenceManifestManager referenceManifestManager,
|
||||
final ReferenceDigestManager referenceDigestManager,
|
||||
final ReferenceEventManager referenceEventManager)
|
||||
final ReferenceManifestService referenceManifestService,
|
||||
final ReferenceDigestValueService referenceDigestValueService)
|
||||
throws IOException, CertificateException, NoSuchAlgorithmException {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
LinkedList<TpmPcrEvent> livelogEvents = new LinkedList<>();
|
||||
@ -534,7 +524,7 @@ public class ReferenceManifestDetailsPageController
|
||||
List<ReferenceDigestValue> eventValues = new ArrayList<>();
|
||||
if (measurements.getDeviceName() != null) {
|
||||
supports.addAll(SupportReferenceManifest
|
||||
.select(referenceManifestManager)
|
||||
.select(referenceManifestService)
|
||||
.byDeviceName(measurements
|
||||
.getDeviceName()).getRIMs());
|
||||
for (SupportReferenceManifest support : supports) {
|
||||
@ -548,16 +538,18 @@ public class ReferenceManifestDetailsPageController
|
||||
data.put("supportId", baseSupport.getId());
|
||||
|
||||
base = BaseReferenceManifest
|
||||
.select(referenceManifestManager)
|
||||
.select(referenceManifestService)
|
||||
.byEntityId(baseSupport.getAssociatedRim())
|
||||
.getRIM();
|
||||
data.put("tagId", baseSupport.getTagId());
|
||||
|
||||
if (base != null) {
|
||||
data.put("associatedRim", base.getId());
|
||||
// this was moved from outside of the null check
|
||||
// for a reason I believe
|
||||
eventValues.addAll(referenceDigestValueService
|
||||
.getValuesByBaseRimId(base.getId()));
|
||||
}
|
||||
|
||||
eventValues.addAll(referenceEventManager.getValuesByRimId(base));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ import hirs.data.persist.certificate.Certificate;
|
||||
import hirs.persist.CriteriaModifier;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.ReferenceEventManager;
|
||||
import hirs.persist.ReferenceManifestManager;
|
||||
import hirs.persist.service.ReferenceManifestService;
|
||||
import hirs.tpm.eventlog.TCGEventLog;
|
||||
import hirs.tpm.eventlog.TpmPcrEvent;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
@ -77,7 +77,7 @@ public class ReferenceManifestPageController
|
||||
|
||||
private final BiosDateValidator biosValidator;
|
||||
@Autowired
|
||||
private final ReferenceManifestManager referenceManifestManager;
|
||||
private final ReferenceManifestService referenceManifestService;
|
||||
@Autowired
|
||||
private final ReferenceEventManager referenceEventManager;
|
||||
private static final Logger LOGGER
|
||||
@ -128,15 +128,15 @@ public class ReferenceManifestPageController
|
||||
/**
|
||||
* Constructor providing the Page's display and routing specification.
|
||||
*
|
||||
* @param referenceManifestManager the reference manifest manager
|
||||
* @param referenceManifestService the reference manifest service
|
||||
* @param referenceEventManager this is the reference event manager
|
||||
*/
|
||||
@Autowired
|
||||
public ReferenceManifestPageController(
|
||||
final ReferenceManifestManager referenceManifestManager,
|
||||
final ReferenceManifestService referenceManifestService,
|
||||
final ReferenceEventManager referenceEventManager) {
|
||||
super(Page.REFERENCE_MANIFESTS);
|
||||
this.referenceManifestManager = referenceManifestManager;
|
||||
this.referenceManifestService = referenceManifestService;
|
||||
this.referenceEventManager = referenceEventManager;
|
||||
this.biosValidator = new BiosDateValidator(BIOS_RELEASE_DATE_FORMAT);
|
||||
}
|
||||
@ -185,7 +185,7 @@ public class ReferenceManifestPageController
|
||||
FilteredRecordsList<ReferenceManifest> records
|
||||
= OrderedListQueryDataTableAdapter.getOrderedList(
|
||||
ReferenceManifest.class,
|
||||
referenceManifestManager,
|
||||
referenceManifestService,
|
||||
input, orderColumnName, criteriaModifier);
|
||||
|
||||
LOGGER.debug("Returning list of size: " + records.size());
|
||||
@ -246,7 +246,7 @@ public class ReferenceManifestPageController
|
||||
// Make sure we are getting the db version of the file
|
||||
updatedSupportRims.put(support.getHexDecHash(),
|
||||
SupportReferenceManifest
|
||||
.select(referenceManifestManager)
|
||||
.select(referenceManifestService)
|
||||
.byHexDecHash(support.getHexDecHash())
|
||||
.getRIM());
|
||||
}
|
||||
@ -289,7 +289,7 @@ public class ReferenceManifestPageController
|
||||
LOGGER.warn(notFoundMessage);
|
||||
} else {
|
||||
referenceManifest.archive();
|
||||
referenceManifestManager.update(referenceManifest);
|
||||
referenceManifestService.updateReferenceManifest(referenceManifest);
|
||||
|
||||
String deleteCompletedMessage = "RIM successfully deleted";
|
||||
messages.addInfo(deleteCompletedMessage);
|
||||
@ -382,9 +382,9 @@ public class ReferenceManifestPageController
|
||||
|
||||
List<ReferenceManifest> referenceManifestList = new LinkedList<>();
|
||||
referenceManifestList.addAll(BaseReferenceManifest
|
||||
.select(referenceManifestManager).getRIMs());
|
||||
.select(referenceManifestService).getRIMs());
|
||||
referenceManifestList.addAll(SupportReferenceManifest
|
||||
.select(referenceManifestManager).getRIMs());
|
||||
.select(referenceManifestService).getRIMs());
|
||||
|
||||
try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream())) {
|
||||
// get all files
|
||||
@ -423,16 +423,16 @@ public class ReferenceManifestPageController
|
||||
*/
|
||||
private ReferenceManifest getRimFromDb(final String id) throws IllegalArgumentException {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
ReferenceManifest rim = BaseReferenceManifest.select(referenceManifestManager)
|
||||
ReferenceManifest rim = BaseReferenceManifest.select(referenceManifestService)
|
||||
.byEntityId(uuid).getRIM();
|
||||
|
||||
if (rim == null) {
|
||||
rim = SupportReferenceManifest.select(referenceManifestManager)
|
||||
rim = SupportReferenceManifest.select(referenceManifestService)
|
||||
.byEntityId(uuid).getRIM();
|
||||
}
|
||||
|
||||
if (rim == null) {
|
||||
rim = EventLogMeasurements.select(referenceManifestManager)
|
||||
rim = EventLogMeasurements.select(referenceManifestService)
|
||||
.byEntityId(uuid).getRIM();
|
||||
}
|
||||
|
||||
@ -514,7 +514,7 @@ public class ReferenceManifestPageController
|
||||
digest.digest(referenceManifest.getRimBytes()));
|
||||
}
|
||||
existingManifest = SupportReferenceManifest
|
||||
.select(referenceManifestManager)
|
||||
.select(referenceManifestService)
|
||||
.byHexDecHash(rimHash)
|
||||
.includeArchived()
|
||||
.getRIM();
|
||||
@ -524,7 +524,7 @@ public class ReferenceManifestPageController
|
||||
digest.digest(referenceManifest.getRimBytes()));
|
||||
}
|
||||
existingManifest = BaseReferenceManifest
|
||||
.select(referenceManifestManager).byBase64Hash(rimHash)
|
||||
.select(referenceManifestService).byBase64Hash(rimHash)
|
||||
.includeArchived()
|
||||
.getRIM();
|
||||
}
|
||||
@ -538,7 +538,7 @@ public class ReferenceManifestPageController
|
||||
try {
|
||||
// save the new certificate if no match is found
|
||||
if (existingManifest == null) {
|
||||
referenceManifestManager.save(referenceManifest);
|
||||
referenceManifestService.saveRIM(referenceManifest);
|
||||
|
||||
final String successMsg = String.format("RIM successfully uploaded (%s): ",
|
||||
fileName);
|
||||
@ -558,7 +558,7 @@ public class ReferenceManifestPageController
|
||||
if (existingManifest != null && existingManifest.isArchived()) {
|
||||
existingManifest.restore();
|
||||
existingManifest.resetCreateTime();
|
||||
referenceManifestManager.update(existingManifest);
|
||||
referenceManifestService.updateReferenceManifest(existingManifest);
|
||||
|
||||
final String successMsg
|
||||
= String.format("Pre-existing RIM found and unarchived (%s): ", fileName);
|
||||
@ -579,7 +579,7 @@ public class ReferenceManifestPageController
|
||||
HashMap<String, BaseReferenceManifest> tempMap = new HashMap<>();
|
||||
for (BaseReferenceManifest base : uploadedBaseRims) {
|
||||
// this is done to make sure we have the version with the UUID
|
||||
dbBaseRim = BaseReferenceManifest.select(referenceManifestManager)
|
||||
dbBaseRim = BaseReferenceManifest.select(referenceManifestService)
|
||||
.byBase64Hash(base.getBase64Hash()).getRIM();
|
||||
if (dbBaseRim != null) {
|
||||
for (SwidResource swid : dbBaseRim.parseResource()) {
|
||||
@ -598,7 +598,7 @@ public class ReferenceManifestPageController
|
||||
Map<String, SupportReferenceManifest> updatedSupportRims = new HashMap<>();
|
||||
List<String> hashValues = new LinkedList<>(dbBaseRims.keySet());
|
||||
for (String supportHash : hashValues) {
|
||||
supportRim = SupportReferenceManifest.select(referenceManifestManager)
|
||||
supportRim = SupportReferenceManifest.select(referenceManifestService)
|
||||
.byHexDecHash(supportHash).getRIM();
|
||||
// I have to assume the baseRim is from the database
|
||||
// Updating the id values, manufacturer, model
|
||||
@ -610,7 +610,7 @@ public class ReferenceManifestPageController
|
||||
supportRim.setTagId(dbBaseRim.getTagId());
|
||||
supportRim.setAssociatedRim(dbBaseRim.getId());
|
||||
supportRim.setUpdated(true);
|
||||
referenceManifestManager.update(supportRim);
|
||||
referenceManifestService.updateReferenceManifest(supportRim);
|
||||
updatedSupportRims.put(supportHash, supportRim);
|
||||
}
|
||||
}
|
||||
@ -628,7 +628,7 @@ public class ReferenceManifestPageController
|
||||
if (supportRim != null && (supportRim.getId() != null
|
||||
&& !supportRim.getId().toString().equals(""))) {
|
||||
Set<BaseReferenceManifest> baseRims = BaseReferenceManifest
|
||||
.select(referenceManifestManager)
|
||||
.select(referenceManifestService)
|
||||
.byManufacturerModel(supportRim.getPlatformManufacturer(),
|
||||
supportRim.getPlatformModel()).getRIMs();
|
||||
|
||||
|
@ -337,7 +337,7 @@ public final class CertificateStringMapBuilder {
|
||||
data.put("holderIssuer", certificate.getHolderIssuer());
|
||||
if (certificate.isBase()) {
|
||||
EndorsementCredential ekCertificate = EndorsementCredential
|
||||
.select(certificateManager)
|
||||
.select(certificateService)
|
||||
.bySerialNumber(certificate.getHolderSerialNumber())
|
||||
.getCertificate();
|
||||
if (ekCertificate != null) {
|
||||
@ -347,7 +347,7 @@ public final class CertificateStringMapBuilder {
|
||||
if (certificate.getPlatformType() != null
|
||||
&& certificate.getPlatformType().equals("Delta")) {
|
||||
PlatformCredential holderCertificate = PlatformCredential
|
||||
.select(certificateManager)
|
||||
.select(certificateService)
|
||||
.bySerialNumber(certificate.getHolderSerialNumber())
|
||||
.getCertificate();
|
||||
if (holderCertificate != null) {
|
||||
@ -357,7 +357,7 @@ public final class CertificateStringMapBuilder {
|
||||
}
|
||||
|
||||
PlatformCredential prevCertificate = PlatformCredential
|
||||
.select(certificateManager)
|
||||
.select(certificateService)
|
||||
.byHolderSerialNumber(certificate.getSerialNumber())
|
||||
.getCertificate();
|
||||
|
||||
@ -397,7 +397,7 @@ public final class CertificateStringMapBuilder {
|
||||
if (certificate.getPlatformSerial() != null) {
|
||||
// link certificate chain
|
||||
List<PlatformCredential> chainCertificates = PlatformCredential
|
||||
.select(certificateManager)
|
||||
.select(certificateService)
|
||||
.byBoardSerialNumber(certificate.getPlatformSerial())
|
||||
.getCertificates().stream().collect(Collectors.toList());
|
||||
|
||||
|
@ -50,9 +50,6 @@ public class CertificateDetailsPageControllerTest extends PageControllerTest {
|
||||
@Autowired
|
||||
private DeviceManager deviceManager;
|
||||
|
||||
@Autowired
|
||||
private DeviceGroupManager deviceGroupManager;
|
||||
|
||||
private CertificateAuthorityCredential caCertificate;
|
||||
private CertificateAuthorityCredential caRootCertificate;
|
||||
private PlatformCredential platformCredential;
|
||||
@ -95,13 +92,8 @@ public class CertificateDetailsPageControllerTest extends PageControllerTest {
|
||||
|
||||
Set<PlatformCredential> pcCertSet = new HashSet<>();
|
||||
|
||||
//Create new device group
|
||||
DeviceGroup group = new DeviceGroup("default");
|
||||
group = deviceGroupManager.saveDeviceGroup(group);
|
||||
|
||||
//Create new device and save it
|
||||
Device device = new Device("Test");
|
||||
device.setDeviceGroup(group);
|
||||
device = deviceManager.saveDevice(device);
|
||||
|
||||
//Upload and save EK Cert
|
||||
|
@ -42,15 +42,11 @@ public class DevicesPageControllerTest extends PageControllerTest {
|
||||
private static final String TEST_PLATFORM_CREDENTIAL
|
||||
= "/platform_credentials/Intel_pc.cer";
|
||||
|
||||
private DeviceGroup group;
|
||||
private Device device;
|
||||
|
||||
@Autowired
|
||||
private DeviceManager deviceManager;
|
||||
|
||||
@Autowired
|
||||
private DeviceGroupManager deviceGroupManager;
|
||||
|
||||
@Autowired
|
||||
private CertificateManager certificateManager;
|
||||
|
||||
@ -67,14 +63,9 @@ public class DevicesPageControllerTest extends PageControllerTest {
|
||||
*/
|
||||
@BeforeClass
|
||||
public void beforeMethod() throws IOException {
|
||||
//Create new device group
|
||||
group = new DeviceGroup(DEVICE_GROUP_NAME);
|
||||
group = deviceGroupManager.saveDeviceGroup(group);
|
||||
|
||||
//Create new device and save it
|
||||
device = new Device(DEVICE_NAME);
|
||||
device.setSupplyChainStatus(AppraisalStatus.Status.PASS);
|
||||
device.setDeviceGroup(group);
|
||||
device = deviceManager.saveDevice(device);
|
||||
|
||||
//Upload and save EK Cert
|
||||
|
@ -1,10 +1,10 @@
|
||||
package hirs.attestationca.portal.page.controllers;
|
||||
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
import hirs.data.persist.certificate.EndorsementCredential;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.attestationca.portal.page.PageControllerTest;
|
||||
import hirs.attestationca.portal.page.PageMessages;
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
import hirs.data.persist.certificate.EndorsementCredential;
|
||||
import hirs.persist.service.CertificateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
@ -30,7 +30,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
public class EndorsementKeyCredentialsPageControllerTest extends PageControllerTest {
|
||||
|
||||
@Autowired
|
||||
private CertificateManager certificateManager;
|
||||
private CertificateService certificateService;
|
||||
|
||||
private static final String EKCERT = "fakeIntelIntermediateCA.pem";
|
||||
private static final String BADEKCERT = "badCert.pem";
|
||||
@ -87,8 +87,8 @@ public class EndorsementKeyCredentialsPageControllerTest extends PageControllerT
|
||||
|
||||
// verify the cert was actually stored
|
||||
Set<Certificate> records =
|
||||
certificateManager.getCertificate(
|
||||
EndorsementCredential.select(certificateManager));
|
||||
certificateService.getCertificate(
|
||||
EndorsementCredential.select(certificateService));
|
||||
Assert.assertEquals(records.size(), 1);
|
||||
|
||||
Certificate cert = records.iterator().next();
|
||||
@ -100,8 +100,8 @@ public class EndorsementKeyCredentialsPageControllerTest extends PageControllerT
|
||||
.param("id", cert.getId().toString()))
|
||||
.andExpect(status().is3xxRedirection())
|
||||
.andReturn();
|
||||
records = certificateManager.getCertificate(EndorsementCredential
|
||||
.select(certificateManager).includeArchived());
|
||||
records = certificateService.getCertificate(EndorsementCredential
|
||||
.select(certificateService).includeArchived());
|
||||
Assert.assertEquals(records.size(), 1);
|
||||
|
||||
cert = records.iterator().next();
|
||||
@ -131,8 +131,8 @@ public class EndorsementKeyCredentialsPageControllerTest extends PageControllerT
|
||||
|
||||
// verify the cert was not actually stored
|
||||
Set<Certificate> records =
|
||||
certificateManager.getCertificate(
|
||||
EndorsementCredential.select(certificateManager));
|
||||
certificateService.getCertificate(
|
||||
EndorsementCredential.select(certificateService));
|
||||
Assert.assertEquals(records.size(), 0);
|
||||
}
|
||||
}
|
||||
|
@ -47,14 +47,11 @@ public class IssuedCertificatesPageControllerTest extends PageControllerTest {
|
||||
private Set<PlatformCredential> platformCredentials;
|
||||
private IssuedAttestationCertificate issued;
|
||||
|
||||
private DeviceGroup group;
|
||||
private Device device;
|
||||
|
||||
@Autowired
|
||||
private DeviceManager deviceManager;
|
||||
|
||||
@Autowired
|
||||
private DeviceGroupManager deviceGroupManager;
|
||||
|
||||
@Autowired
|
||||
private CertificateManager certificateManager;
|
||||
@ -65,13 +62,8 @@ public class IssuedCertificatesPageControllerTest extends PageControllerTest {
|
||||
*/
|
||||
@BeforeClass
|
||||
public void beforeMethod() throws IOException {
|
||||
//Create new device grup
|
||||
group = new DeviceGroup("default");
|
||||
group = deviceGroupManager.saveDeviceGroup(group);
|
||||
|
||||
//Create new device and save it
|
||||
device = new Device("Test");
|
||||
device.setDeviceGroup(group);
|
||||
device = deviceManager.saveDevice(device);
|
||||
|
||||
//Upload and save EK Cert
|
||||
|
@ -1,10 +1,10 @@
|
||||
package hirs.attestationca.portal.page.controllers;
|
||||
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
import hirs.data.persist.certificate.PlatformCredential;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.attestationca.portal.page.PageControllerTest;
|
||||
import hirs.attestationca.portal.page.PageMessages;
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
import hirs.data.persist.certificate.PlatformCredential;
|
||||
import hirs.persist.service.CertificateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
@ -29,7 +29,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class PlatformCredentialsPageControllerTest extends PageControllerTest {
|
||||
@Autowired
|
||||
private CertificateManager certificateManager;
|
||||
private CertificateService certificateService;
|
||||
|
||||
// A cert that is an actual PC cert file and should be parsable.
|
||||
private MockMultipartFile realPcCertFile;
|
||||
@ -95,7 +95,7 @@ public class PlatformCredentialsPageControllerTest extends PageControllerTest {
|
||||
|
||||
// verify the cert was actually stored
|
||||
Set<Certificate> records =
|
||||
certificateManager.getCertificate(PlatformCredential.select(certificateManager));
|
||||
certificateService.getCertificate(PlatformCredential.select(certificateService));
|
||||
Assert.assertEquals(records.size(), 1);
|
||||
|
||||
Certificate cert = records.iterator().next();
|
||||
@ -113,8 +113,8 @@ public class PlatformCredentialsPageControllerTest extends PageControllerTest {
|
||||
.andReturn();
|
||||
|
||||
Set<Certificate> records =
|
||||
certificateManager.getCertificate(PlatformCredential
|
||||
.select(certificateManager).includeArchived());
|
||||
certificateService.getCertificate(PlatformCredential
|
||||
.select(certificateService).includeArchived());
|
||||
Assert.assertEquals(records.size(), 1);
|
||||
|
||||
Assert.assertTrue(records.iterator().next().isArchived());
|
||||
@ -147,8 +147,8 @@ public class PlatformCredentialsPageControllerTest extends PageControllerTest {
|
||||
"Pre-existing certificate found and unarchived (" + REALPCCERT + "): ");
|
||||
|
||||
// verify the cert was actually stored
|
||||
Set<Certificate> records = certificateManager.getCertificate(PlatformCredential.select(
|
||||
certificateManager));
|
||||
Set<Certificate> records = certificateService.getCertificate(PlatformCredential.select(
|
||||
certificateService));
|
||||
Assert.assertEquals(records.size(), 1);
|
||||
|
||||
Certificate newCert = records.iterator().next();
|
||||
@ -168,7 +168,7 @@ public class PlatformCredentialsPageControllerTest extends PageControllerTest {
|
||||
public void uploadNonPlatformCert() throws Exception {
|
||||
// verify the cert was not actually stored
|
||||
Set<Certificate> originalRecords =
|
||||
certificateManager.getCertificate(PlatformCredential.select(certificateManager));
|
||||
certificateService.getCertificate(PlatformCredential.select(certificateService));
|
||||
Assert.assertEquals(originalRecords.size(), 0);
|
||||
|
||||
// perform upload. Attach csv file and add HTTP parameters for the baseline name and type.
|
||||
@ -186,7 +186,7 @@ public class PlatformCredentialsPageControllerTest extends PageControllerTest {
|
||||
|
||||
// verify the cert was not actually stored
|
||||
Set<Certificate> records =
|
||||
certificateManager.getCertificate(PlatformCredential.select(certificateManager));
|
||||
certificateService.getCertificate(PlatformCredential.select(certificateService));
|
||||
Assert.assertEquals(records.size(), 0);
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ public class PlatformCredentialsPageControllerTest extends PageControllerTest {
|
||||
|
||||
// verify the cert was not actually stored
|
||||
Set<Certificate> records =
|
||||
certificateManager.getCertificate(PlatformCredential.select(certificateManager));
|
||||
certificateService.getCertificate(PlatformCredential.select(certificateService));
|
||||
Assert.assertEquals(records.size(), 0);
|
||||
}
|
||||
}
|
||||
|
@ -2,26 +2,25 @@ package hirs.attestationca.portal.page.controllers;
|
||||
|
||||
import hirs.appraiser.Appraiser;
|
||||
import hirs.appraiser.SupplyChainAppraiser;
|
||||
import hirs.attestationca.portal.page.PageController;
|
||||
import hirs.attestationca.portal.page.PageControllerTest;
|
||||
import hirs.data.persist.policy.SupplyChainPolicy;
|
||||
import hirs.persist.AppraiserManager;
|
||||
import hirs.persist.PolicyManager;
|
||||
import org.testng.Assert;
|
||||
import static hirs.attestationca.portal.page.Page.POLICY;
|
||||
|
||||
import hirs.attestationca.portal.page.PageControllerTest;
|
||||
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasProperty;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static hirs.attestationca.portal.page.Page.POLICY;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasProperty;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.flash;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import hirs.attestationca.portal.page.PageController;
|
||||
|
||||
/**
|
||||
* Integration tests that test the URL End Points of PolicyPageController.
|
||||
@ -34,9 +33,6 @@ public class PolicyPageControllerTest extends PageControllerTest {
|
||||
@Autowired
|
||||
private AppraiserManager appraiserManager;
|
||||
|
||||
@Autowired
|
||||
private DeviceGroupManager groupManager;
|
||||
|
||||
private SupplyChainPolicy policy;
|
||||
|
||||
/**
|
||||
@ -52,12 +48,6 @@ public class PolicyPageControllerTest extends PageControllerTest {
|
||||
*/
|
||||
@BeforeClass
|
||||
public void setUpPolicy() {
|
||||
|
||||
// create default group so that the policy can be applied as a default.
|
||||
if (groupManager.getDeviceGroup(DeviceGroup.DEFAULT_GROUP) == null) {
|
||||
groupManager.saveDeviceGroup(new DeviceGroup(DeviceGroup.DEFAULT_GROUP));
|
||||
}
|
||||
|
||||
appraiserManager.saveAppraiser(new SupplyChainAppraiser());
|
||||
final Appraiser supplyChainAppraiser = appraiserManager.getAppraiser(
|
||||
SupplyChainAppraiser.NAME);
|
||||
|
@ -4,7 +4,7 @@ import hirs.attestationca.portal.page.PageControllerTest;
|
||||
import hirs.attestationca.portal.page.PageMessages;
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
import hirs.data.persist.certificate.CertificateAuthorityCredential;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.persist.service.CertificateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
@ -21,8 +21,8 @@ import java.io.IOException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
import static hirs.attestationca.portal.page.Page.TRUST_CHAIN;
|
||||
import static org.hamcrest.Matchers.hasEntry;
|
||||
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.model;
|
||||
@ -35,7 +35,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
public class TrustChainManagementPageControllerTest extends PageControllerTest {
|
||||
|
||||
@Autowired
|
||||
private CertificateManager certificateManager;
|
||||
private CertificateService certificateService;
|
||||
|
||||
@Autowired
|
||||
private X509Certificate acaCert;
|
||||
@ -170,8 +170,8 @@ public class TrustChainManagementPageControllerTest extends PageControllerTest {
|
||||
|
||||
// verify the cert was actually stored
|
||||
Set<Certificate> records =
|
||||
certificateManager.getCertificate(
|
||||
CertificateAuthorityCredential.select(certificateManager));
|
||||
certificateService.getCertificate(
|
||||
CertificateAuthorityCredential.select(certificateService));
|
||||
Assert.assertEquals(records.size(), 1);
|
||||
|
||||
//Check the cert is not already in the archive
|
||||
@ -188,8 +188,8 @@ public class TrustChainManagementPageControllerTest extends PageControllerTest {
|
||||
.param("id", cert.getId().toString()))
|
||||
.andExpect(status().is3xxRedirection())
|
||||
.andReturn();
|
||||
Set<Certificate> records = certificateManager.getCertificate(CertificateAuthorityCredential
|
||||
.select(certificateManager).includeArchived());
|
||||
Set<Certificate> records = certificateService.getCertificate(CertificateAuthorityCredential
|
||||
.select(certificateService).includeArchived());
|
||||
Assert.assertEquals(records.size(), 1);
|
||||
|
||||
Assert.assertTrue(records.iterator().next().isArchived());
|
||||
@ -222,8 +222,8 @@ public class TrustChainManagementPageControllerTest extends PageControllerTest {
|
||||
"Pre-existing certificate found and unarchived (" + NONCACERT + "): ");
|
||||
|
||||
// verify the cert can be retrieved without looking at archived certs
|
||||
Set<Certificate> records = certificateManager.getCertificate(CertificateAuthorityCredential
|
||||
.select(certificateManager).includeArchived());
|
||||
Set<Certificate> records = certificateService.getCertificate(CertificateAuthorityCredential
|
||||
.select(certificateService).includeArchived());
|
||||
Assert.assertEquals(records.size(), 1);
|
||||
Certificate newCert = records.iterator().next();
|
||||
|
||||
@ -256,8 +256,8 @@ public class TrustChainManagementPageControllerTest extends PageControllerTest {
|
||||
|
||||
// verify the cert was not actually stored
|
||||
Set<Certificate> records =
|
||||
certificateManager.getCertificate(
|
||||
CertificateAuthorityCredential.select(certificateManager));
|
||||
certificateService.getCertificate(
|
||||
CertificateAuthorityCredential.select(certificateService));
|
||||
Assert.assertEquals(records.size(), 0);
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
package hirs.attestationca.portal.page.datatables;
|
||||
|
||||
import hirs.FilteredRecordsList;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.persist.CriteriaModifier;
|
||||
import hirs.persist.OrderedListQuerier;
|
||||
import hirs.attestationca.portal.datatables.Column;
|
||||
import hirs.attestationca.portal.datatables.DataTableInput;
|
||||
import hirs.attestationca.portal.datatables.Order;
|
||||
import hirs.attestationca.portal.datatables.OrderedListQueryDataTableAdapter;
|
||||
import hirs.attestationca.portal.datatables.Search;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.persist.CriteriaModifier;
|
||||
import hirs.persist.OrderedQuery;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Matchers;
|
||||
@ -36,7 +36,7 @@ import static org.mockito.Mockito.when;
|
||||
*/
|
||||
public class OrderedListQueryDataTableAdapterTest {
|
||||
|
||||
private OrderedListQuerier<Device> querier;
|
||||
private OrderedQuery<Device> querier;
|
||||
|
||||
private FilteredRecordsList filteredList;
|
||||
|
||||
@ -54,8 +54,8 @@ public class OrderedListQueryDataTableAdapterTest {
|
||||
// sets up the @Captor
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
querier = (OrderedListQuerier<Device>)
|
||||
mock(OrderedListQuerier.class);
|
||||
querier = (OrderedQuery<Device>)
|
||||
mock(OrderedQuery .class);
|
||||
|
||||
filteredList = new FilteredRecordsList();
|
||||
|
||||
|
@ -2,7 +2,6 @@ package hirs.data.persist;
|
||||
|
||||
import hirs.data.persist.enums.HealthStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import hirs.foss.XMLCleaner;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -13,8 +12,6 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
|
@ -15,12 +15,56 @@ import java.util.Date;
|
||||
* Whenever the server issues a {@link hirs.ReportRequest} for a {@link Device}, the server
|
||||
* will create a <code>ReportRequestState</code>. This state will be used track if the given
|
||||
* <code>Device</code> has fulfilled reporting requirements in a timely manner. A client is late in
|
||||
* reporting if a report has not been received within the {@link DeviceGroup} threshold. This state
|
||||
* reporting if a report has not been received within the threshold. This state
|
||||
* includes the necessary information for the server to generate alerts when a client fails to
|
||||
* report.
|
||||
*/
|
||||
@Entity
|
||||
public class ReportRequestState extends State {
|
||||
/**
|
||||
* A second period in milliseconds.
|
||||
*/
|
||||
public static final long SECOND_MS_INTERVAL = 1000;
|
||||
|
||||
/**
|
||||
* A minute period in milliseconds.
|
||||
*/
|
||||
public static final long MINUTE_MS_INTERVAL = 60 * SECOND_MS_INTERVAL;
|
||||
|
||||
/**
|
||||
* five minutes period in milliseconds.
|
||||
*/
|
||||
public static final long FIVE_MINUTES_MS_INTERVAL = 5 * MINUTE_MS_INTERVAL;
|
||||
|
||||
/**
|
||||
* An hour period in milliseconds.
|
||||
*/
|
||||
public static final long HOUR_MS_INTERVAL = 60 * MINUTE_MS_INTERVAL;
|
||||
|
||||
/**
|
||||
* A day period in milliseconds.
|
||||
*/
|
||||
public static final long DAY_MS_INTERVAL = 24 * HOUR_MS_INTERVAL;
|
||||
|
||||
/**
|
||||
* The default for on demand and periodic report thresholds.
|
||||
*/
|
||||
public static final long DEFAULT_REPORT_DELAY_THRESHOLD = 12 * HOUR_MS_INTERVAL;
|
||||
|
||||
/**
|
||||
* Minimum Periodic report period is once every 500 millisecond.
|
||||
*/
|
||||
public static final long MINIMUM_PERIODIC_REPORT_INTERVAL = FIVE_MINUTES_MS_INTERVAL;
|
||||
|
||||
/**
|
||||
* Minimum allowed value for any report Threshold.
|
||||
*/
|
||||
public static final long MINIMUM_THRESHOLD_INTERVAL_MS = MINUTE_MS_INTERVAL;
|
||||
|
||||
/**
|
||||
* The default job frequency of 1 day in milliseconds.
|
||||
*/
|
||||
public static final long DEFAULT_JOB_FREQUENCY_MS = DAY_MS_INTERVAL;
|
||||
|
||||
@OneToOne(optional = false, fetch = FetchType.EAGER)
|
||||
private Device device;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package hirs.data.persist.certificate;
|
||||
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.persist.CertificateSelector;
|
||||
import hirs.persist.service.CertificateService;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import java.io.IOException;
|
||||
@ -18,24 +18,26 @@ public class ConformanceCredential extends Certificate {
|
||||
*/
|
||||
public static class Selector extends CertificateSelector<ConformanceCredential> {
|
||||
/**
|
||||
* Construct a new CertificateSelector that will use the given {@link CertificateManager} to
|
||||
* Construct a new CertificateSelector that will use the
|
||||
* given {@link CertificateService} to
|
||||
* retrieve one or many ConformanceCredentials.
|
||||
*
|
||||
* @param certificateManager the certificate manager to be used to retrieve certificates
|
||||
* @param certificateService the certificate service to be used to retrieve certificates
|
||||
*/
|
||||
public Selector(final CertificateManager certificateManager) {
|
||||
super(certificateManager, ConformanceCredential.class);
|
||||
public Selector(final CertificateService certificateService) {
|
||||
super(certificateService, ConformanceCredential.class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Selector for use in retrieving ConformanceCredentials.
|
||||
*
|
||||
* @param certMan the CertificateManager to be used to retrieve persisted certificates
|
||||
* @param certificateService the CertificateService to be used to retrieve
|
||||
* persisted certificates
|
||||
* @return a ConformanceCredential.Selector instance to use for retrieving certificates
|
||||
*/
|
||||
public static Selector select(final CertificateManager certMan) {
|
||||
return new Selector(certMan);
|
||||
public static Selector select(final CertificateService certificateService) {
|
||||
return new Selector(certificateService);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +64,8 @@ public class IssuedAttestationCertificate extends DeviceAssociatedCertificate {
|
||||
/**
|
||||
* Get a Selector for use in retrieving IssuedAttestationCertificate.
|
||||
*
|
||||
* @param certificateService the CertificateService to be used to retrieve persisted certificates
|
||||
* @param certificateService the CertificateService to be used to
|
||||
* retrieve persisted certificates
|
||||
* @return a IssuedAttestationCertificate.Selector instance to use for retrieving certificates
|
||||
*/
|
||||
public static IssuedAttestationCertificate.Selector select(
|
||||
|
@ -23,6 +23,15 @@ public interface CertificateService extends OrderedQuery<Certificate> {
|
||||
*/
|
||||
Certificate saveCertificate(Certificate certificate);
|
||||
|
||||
/**
|
||||
* Updates a <code>Certificate</code>. This updates the database entries to
|
||||
* reflect the new values that should be set.
|
||||
*
|
||||
* @param certificate Certificate object to save
|
||||
* @return a Certificate object
|
||||
*/
|
||||
Certificate updateCertificate(Certificate certificate);
|
||||
|
||||
/**
|
||||
* Updates a <code>Certificate</code>. This updates the database entries to
|
||||
* reflect the new values that should be set.
|
||||
|
@ -24,6 +24,15 @@ public interface ReferenceManifestService extends OrderedQuery<ReferenceManifest
|
||||
*/
|
||||
ReferenceManifest saveRIM(ReferenceManifest rim);
|
||||
|
||||
/**
|
||||
* Updates a <code>ReferenceManifest</code>. This updates the database entries to
|
||||
* reflect the new values that should be set.
|
||||
*
|
||||
* @param rim ReferenceManifest object to save
|
||||
* @return a ReferenceManifest object
|
||||
*/
|
||||
ReferenceManifest updateReferenceManifest(ReferenceManifest rim);
|
||||
|
||||
/**
|
||||
* Updates a <code>ReferenceManifest</code>. This updates the database entries to
|
||||
* reflect the new values that should be set.
|
||||
@ -39,7 +48,6 @@ public interface ReferenceManifestService extends OrderedQuery<ReferenceManifest
|
||||
* database session and saves the device.
|
||||
*
|
||||
* @param rim ReferenceManifest to delete
|
||||
* @return reference to deleted rim
|
||||
*/
|
||||
void deleteRIM(ReferenceManifest rim);
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class ReportRequestStateTest {
|
||||
public final void setDueDate() {
|
||||
ReportRequestState state = new ReportRequestState();
|
||||
Date currentTime = new Date();
|
||||
state.setDueDate(DeviceGroup.MINUTE_MS_INTERVAL);
|
||||
state.setDueDate(ReportRequestState.MINUTE_MS_INTERVAL);
|
||||
Date setDate = state.getDueDate();
|
||||
Assert.assertTrue(currentTime.before(setDate));
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package hirs.data.persist.certificate;
|
||||
|
||||
import hirs.persist.service.CertificateService;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.mockito.Mockito;
|
||||
import org.testng.Assert;
|
||||
@ -10,13 +11,12 @@ import java.net.URISyntaxException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.cert.CertificateException;
|
||||
import hirs.persist.CertificateManager;
|
||||
|
||||
/**
|
||||
* Tests that CertificateAuthorityCredential properly parses its fields.
|
||||
*/
|
||||
public class CertificateAuthorityCredentialTest {
|
||||
private static final CertificateManager CERT_MAN = Mockito.mock(CertificateManager.class);
|
||||
private static final CertificateService CERT_MAN = Mockito.mock(CertificateService.class);
|
||||
|
||||
/**
|
||||
* Tests that a CertificateAuthorityCredential can be created from an X.509 certificate and
|
||||
|
@ -1,14 +1,7 @@
|
||||
package hirs.data.service;
|
||||
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceInfoReport;
|
||||
import hirs.data.persist.info.FirmwareInfo;
|
||||
import hirs.data.persist.info.HardwareInfo;
|
||||
import hirs.data.persist.info.NetworkInfo;
|
||||
import hirs.data.persist.info.OSInfo;
|
||||
import hirs.data.persist.info.TPMInfo;
|
||||
import hirs.persist.DeviceManager;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@ -33,11 +26,6 @@ public class DeviceRegisterImplTest {
|
||||
@Test
|
||||
public void registerNonStoredDeviceByReport() {
|
||||
final DeviceManager deviceManager = mock(DeviceManager.class);
|
||||
final InetAddress ipAddress = getTestIpAddress();
|
||||
final NetworkInfo networkInfo = new NetworkInfo(HOSTNAME, ipAddress, MAC_ADDRESS);
|
||||
|
||||
final DeviceInfoReport report = new DeviceInfoReport(networkInfo, new OSInfo(),
|
||||
new FirmwareInfo(), new HardwareInfo(), new TPMInfo());
|
||||
|
||||
verify(deviceManager).saveDevice(any(Device.class));
|
||||
}
|
||||
@ -58,10 +46,6 @@ public class DeviceRegisterImplTest {
|
||||
@Test
|
||||
public void registerExistingDeviceByReport() {
|
||||
final DeviceManager deviceManager = mock(DeviceManager.class);
|
||||
final InetAddress ipAddress = getTestIpAddress();
|
||||
final NetworkInfo networkInfo = new NetworkInfo(HOSTNAME, ipAddress, MAC_ADDRESS);
|
||||
final DeviceInfoReport report = new DeviceInfoReport(networkInfo, new OSInfo(),
|
||||
new FirmwareInfo(), new HardwareInfo(), new TPMInfo());
|
||||
final Device device = new Device(HOSTNAME);
|
||||
|
||||
when(deviceManager.getDevice(HOSTNAME)).thenReturn(device);
|
||||
|
Loading…
Reference in New Issue
Block a user