urn_perun_resource_attribute_def_def_sshkeysTargetUser extends ResourceAttributesModuleAbstract implements ResourceAttributesModuleImplApi { @Override public void checkAttributeSyntax(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws WrongAttributeValueException { String key = attribute.valueAsString(); if (key == null) return; Matcher match = pattern.matcher(key); if (!match.matches()) { throw new WrongAttributeValueException(attribute, resource, "Bad format of attribute sshkeysTargetUser (only letters, numbers and '.' '_' '-' are allowed. Cannot begin with '-')."); } }  @Override void checkAttributeSyntax(PerunSessionImpl perunSession, Resource resource, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl perunSession, Resource resource, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test public void testCheckAttributeSyntax() throws Exception { System.out.println("testCheckAttributeSyntax()"); Attribute attributeToCheck = new Attribute(); attributeToCheck.setValue("Jan_Nepomucky"); classInstance.checkAttributeSemantics(session, resource, attributeToCheck); attributeToCheck.setValue(".John_Dale."); classInstance.checkAttributeSemantics(session, resource, attributeToCheck); attributeToCheck.setValue("_Adele-Frank"); classInstance.checkAttributeSemantics(session, resource, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckAttributeSyntaxWithWrongValueHyphen() throws Exception { System.out.println("testCheckAttributeSyntaxWithWrongValueHyphen()"); Attribute attributeToCheck = new Attribute(); attributeToCheck.setValue("-Adam"); classInstance.checkAttributeSyntax(session, resource, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckAttributeSyntaxWithWrongValueWhitespace() throws Exception { System.out.println("testCheckAttributeSyntaxWithWrongValueWhitespace()"); Attribute attributeToCheck = new Attribute(); attributeToCheck.setValue("Elena Fuente"); classInstance.checkAttributeSyntax(session, resource, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckAttributeSyntaxWithWrongValueDiacritic() throws Exception { System.out.println("testCheckAttributeSyntaxWithWrongValueDiacritic()"); Attribute attributeToCheck = new Attribute(); attributeToCheck.setValue("Jan_Veselý"); classInstance.checkAttributeSyntax(session, resource, attributeToCheck); }