CertificateIdentityParser { public CertificateIdentityParser(Set<String> excludedPrincipalSet, boolean excludeRoleCertificates) { this.excludedPrincipalSet = excludedPrincipalSet; this.excludeRoleCertificates = excludeRoleCertificates; } CertificateIdentityParser(Set<String> excludedPrincipalSet, boolean excludeRoleCertificates); CertificateIdentity parse(HttpServletRequest request); CertificateIdentity parse(X509Certificate[] certs); static final String JAVAX_CERT_ATTR; static final String ZTS_CERT_ROLE_URI; static final String EMPTY_CERT_ERR_MSG; }
@Test public void testCertificateIdentityParser() { BiFunction<Field, CertificateIdentityParser, Object> getFieldValue = (f, object) -> { try { f.setAccessible(true); return f.get(object); } catch (IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException(e); } }; CertificateIdentityParser parser; parser = new CertificateIdentityParser(null, false); assertNotNull(parser); for (Field f : parser.getClass().getDeclaredFields()) { switch (f.getName()) { case "excludedPrincipalSet": assertEquals(getFieldValue.apply(f, parser), null); break; case "excludeRoleCertificates": assertEquals(getFieldValue.apply(f, parser), false); break; } } parser = new CertificateIdentityParser(new HashSet<>(Arrays.asList("principal_1", "principal_2")), true); assertNotNull(parser); for (Field f : parser.getClass().getDeclaredFields()) { switch (f.getName()) { case "excludedPrincipalSet": assertEquals(getFieldValue.apply(f, parser), new HashSet<>(Arrays.asList("principal_1", "principal_2"))); break; case "excludeRoleCertificates": assertEquals(getFieldValue.apply(f, parser), true); break; } } }