/** * Create an instance of {@link MultiValuesConstraint } * */ public MultiValuesConstraint createMultiValuesConstraint() { return new MultiValuesConstraint(); }
@Test public void emptyListCommitmentTypeIndicationsCheck() throws Exception { XmlSignature sig = new XmlSignature(); MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("1"); constraint.getId().add("2"); constraint.getId().add("3"); XmlSAV result = new XmlSAV(); CommitmentTypeIndicationsCheck ctic = new CommitmentTypeIndicationsCheck(result, new SignatureWrapper(sig), constraint); ctic.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.NOT_OK, constraints.get(0).getStatus()); } }
@Test public void commitmentTypeIndicationsCheck() throws Exception { List<String> commitmentTypeIndication = new ArrayList<String>(); commitmentTypeIndication.add("1"); commitmentTypeIndication.add("2"); XmlSignature sig = new XmlSignature(); sig.setCommitmentTypeIndication(commitmentTypeIndication); MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("1"); constraint.getId().add("2"); constraint.getId().add("3"); XmlSAV result = new XmlSAV(); CommitmentTypeIndicationsCheck ctic = new CommitmentTypeIndicationsCheck(result, new SignatureWrapper(sig), constraint); ctic.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.OK, constraints.get(0).getStatus()); }
@Test public void failedCommitmentTypeIndicationsCheck() throws Exception { List<String> commitmentTypeIndication = new ArrayList<String>(); commitmentTypeIndication.add("1"); commitmentTypeIndication.add("4"); XmlSignature sig = new XmlSignature(); sig.setCommitmentTypeIndication(commitmentTypeIndication); MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("1"); constraint.getId().add("2"); constraint.getId().add("3"); XmlSAV result = new XmlSAV(); CommitmentTypeIndicationsCheck ctic = new CommitmentTypeIndicationsCheck(result, new SignatureWrapper(sig), constraint); ctic.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.NOT_OK, constraints.get(0).getStatus()); }
protected boolean processValueCheck(String value) { List<String> expecteds = constraint.getId(); if (Utils.isStringNotEmpty(value) && Utils.isCollectionNotEmpty(expecteds)) { if (expecteds.contains(ALL_VALUE)) { return true; } else if (expecteds.contains(value)) { return true; } } return false; }
@Test public void failedKeyUsageCheck() throws Exception { List<String> keyUsageBits = new ArrayList<String>(); keyUsageBits.add("Valid_Key"); MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("Invalid_Key"); XmlCertificate xc = new XmlCertificate(); xc.setKeyUsageBits(keyUsageBits); XmlSubXCV result = new XmlSubXCV(); KeyUsageCheck kuc = new KeyUsageCheck(result, new CertificateWrapper(xc), constraint); kuc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.NOT_OK, constraints.get(0).getStatus()); }
@Override protected boolean process() { String policyId = signature.getPolicyId(); if (multiValues.getId().contains(SignaturePolicy.NO_POLICY) && Utils.isStringEmpty(policyId)) { return true; } else if (multiValues.getId().contains(SignaturePolicy.ANY_POLICY) && Utils.isStringNotEmpty(policyId)) { return true; } else if (multiValues.getId().contains(SignaturePolicy.IMPLICIT_POLICY) && Utils.areStringsEqual(SignaturePolicy.IMPLICIT_POLICY, policyId)) { return true; } // oids return processValueCheck(policyId); }
@Test public void claimedRolesCheck() throws Exception { List<String> claimedRoles = new ArrayList<String>(); claimedRoles.add("Claimed_Role"); XmlSignature sig = new XmlSignature(); sig.setClaimedRoles(claimedRoles); MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("Claimed_Role"); XmlSAV result = new XmlSAV(); ClaimedRolesCheck crc = new ClaimedRolesCheck(result, new SignatureWrapper(sig), constraint); crc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.OK, constraints.get(0).getStatus()); }
@Override protected boolean process() { List<String> commitmentTypeIdentifiers = signature.getCommitmentTypeIdentifiers(); List<String> expectedValues = constraint.getId(); if (Utils.isCollectionEmpty(commitmentTypeIdentifiers)) { return false; } if (Utils.isCollectionNotEmpty(expectedValues)) { return expectedValues.containsAll(commitmentTypeIdentifiers); } return true; }
@Test public void pseudonymCheck() throws Exception { MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("Valid_Pseudonym"); XmlCertificate xc = new XmlCertificate(); xc.setPseudonym("Valid_Pseudonym"); XmlSubXCV result = new XmlSubXCV(); PseudonymCheck pc = new PseudonymCheck(result, new CertificateWrapper(xc), constraint); pc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.OK, constraints.get(0).getStatus()); }
@Test public void failedCommonNameCheck() throws Exception { MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("Invalid_Name"); XmlCertificate xc = new XmlCertificate(); xc.setCommonName("Valid_Name"); XmlSubXCV result = new XmlSubXCV(); CommonNameCheck cnc = new CommonNameCheck(result, new CertificateWrapper(xc), constraint); cnc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.NOT_OK, constraints.get(0).getStatus()); }
@Test public void keyUsageCheck() throws Exception { List<String> keyUsageBits = new ArrayList<String>(); keyUsageBits.add("Valid_Key"); MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add(keyUsageBits.get(0)); XmlCertificate xc = new XmlCertificate(); xc.setKeyUsageBits(keyUsageBits); XmlSubXCV result = new XmlSubXCV(); KeyUsageCheck kuc = new KeyUsageCheck(result, new CertificateWrapper(xc), constraint); kuc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.OK, constraints.get(0).getStatus()); }
@Test public void failedOrganizationUnitCheck() throws Exception { MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("Invalid_Org"); XmlCertificate xc = new XmlCertificate(); xc.setOrganizationalUnit("Valid_Org"); XmlSubXCV result = new XmlSubXCV(); OrganizationUnitCheck ouc = new OrganizationUnitCheck(result, new CertificateWrapper(xc), constraint); ouc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.NOT_OK, constraints.get(0).getStatus()); }
@Test public void validFormat() throws Exception { XmlSignature sig = new XmlSignature(); sig.setSignatureFormat("CAdES_BASELINE_B"); MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("CAdES_BASELINE_B"); XmlFC result = new XmlFC(); FormatCheck fc = new FormatCheck(result, new SignatureWrapper(sig), constraint); fc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.OK, constraints.get(0).getStatus()); }
@Test public void failedSurnameCheck() throws Exception { MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("Invalid_Surname"); XmlCertificate xc = new XmlCertificate(); xc.setSurname("Valid_Surname"); XmlSubXCV result = new XmlSubXCV(); SurnameCheck sc = new SurnameCheck(result, new CertificateWrapper(xc), constraint); sc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.NOT_OK, constraints.get(0).getStatus()); }
@Test public void failedOrganizationNameCheck() throws Exception { MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("Invalid_Org"); XmlCertificate xc = new XmlCertificate(); xc.setOrganizationName("Valid_Org"); XmlSubXCV result = new XmlSubXCV(); OrganizationNameCheck onc = new OrganizationNameCheck(result, new CertificateWrapper(xc), constraint); onc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.NOT_OK, constraints.get(0).getStatus()); }
@Test public void failedGivenNameCheck() throws Exception { MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("Invalid_Name"); XmlCertificate xc = new XmlCertificate(); xc.setGivenName("Valid_Name"); XmlSubXCV result = new XmlSubXCV(); GivenNameCheck gnc = new GivenNameCheck(result, new CertificateWrapper(xc), constraint); gnc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.NOT_OK, constraints.get(0).getStatus()); }
@Test public void invalidFormat() throws Exception { XmlSignature sig = new XmlSignature(); sig.setSignatureFormat("Invalid_format"); MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("CAdES_BASELINE_B"); XmlFC result = new XmlFC(); FormatCheck fc = new FormatCheck(result, new SignatureWrapper(sig), constraint); fc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.NOT_OK, constraints.get(0).getStatus()); }
@Test public void countryCheck() throws Exception { MultiValuesConstraint constraint = new MultiValuesConstraint(); constraint.setLevel(Level.FAIL); constraint.getId().add("BE"); XmlCertificate xc = new XmlCertificate(); xc.setCountryName("BE"); XmlSubXCV result = new XmlSubXCV(); CountryCheck cc = new CountryCheck(result, new CertificateWrapper(xc), constraint); cc.execute(); List<XmlConstraint> constraints = result.getConstraint(); assertEquals(1, constraints.size()); assertEquals(XmlStatus.OK, constraints.get(0).getStatus()); }