urn_perun_user_attribute_def_def_userCertDNs extends UserAttributesModuleAbstract implements UserAttributesModuleImplApi { @Override public void checkAttributeSyntax(PerunSessionImpl sess, User user, Attribute attribute) throws WrongAttributeValueException { if(attribute.getValue() == null) return; Map<String, String> value = attribute.valueAsMap(); Set<String> valueKeys = value.keySet(); for(String k: valueKeys) { Matcher certKeyMatcher = certPattern.matcher(k); if(!certKeyMatcher.find()) throw new WrongAttributeValueException(attribute, "There is wrong value for key " + k + " in hashMap of userCertDNs."); String valueOfKey = value.get(k); Matcher certValueOfKeyMatcher = certPattern.matcher(valueOfKey); if(!certValueOfKeyMatcher.find()) throw new WrongAttributeValueException(attribute, "There is wrong value for key's value " + valueOfKey + " in hashMap of UserCertDns for key " + k); } }  @Override void checkAttributeSyntax(PerunSessionImpl sess, User user, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl sess, User user, Attribute attribute); @Override Attribute fillAttribute(PerunSessionImpl sess, User user, AttributeDefinition attribute); @Override void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongAttributeValueException.class) public void testCheckAttributeSyntaxWithIncorrectKeyValue() throws Exception { System.out.println("testCheckAttributeSyntaxWithIncorrectKeyValue()"); Map<String, String> value = new LinkedHashMap<>(); value.put("bad_example", "/example"); attributeToCheck.setValue(value); classInstance.checkAttributeSyntax(session, user, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckAttributeSyntaxWithIncorrectValueValue() throws Exception { System.out.println("testCheckAttributeSyntaxWithIncorrectValueValue()"); Map<String, String> value = new LinkedHashMap<>(); value.put("/example", ""); attributeToCheck.setValue(value); classInstance.checkAttributeSyntax(session, user, attributeToCheck); }
@Test public void testCheckAttributeSyntaxCorrect() throws Exception { System.out.println("testCheckAttributeSyntaxCorrect()"); Map<String, String> value = new LinkedHashMap<>(); value.put("/example", "/example"); attributeToCheck.setValue(value); classInstance.checkAttributeSyntax(session, user, attributeToCheck); }