urn_perun_user_facility_attribute_def_def_homeMountPoint extends UserFacilityAttributesModuleAbstract implements UserFacilityAttributesModuleImplApi { @Override public void checkAttributeSyntax(PerunSessionImpl session, User user, Facility facility, Attribute attribute) throws WrongAttributeValueException { if (attribute.getValue() == null) return; Matcher match = pattern.matcher(attribute.valueAsString()); if (!match.matches()) { throw new WrongAttributeValueException(attribute, "Attribute has wrong format"); } }  @Override void checkAttributeSemantics(PerunSessionImpl session, User user, Facility facility, Attribute attribute); @Override void checkAttributeSyntax(PerunSessionImpl session, User user, Facility facility, Attribute attribute); @Override Attribute fillAttribute(PerunSessionImpl session, User user, Facility facility, AttributeDefinition attribute); @Override List<String> getDependencies(); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongAttributeValueException.class) public void testCheckAttributeSyntaxWrongHomeMountPointFormat() throws Exception { System.out.println("testCheckAttributeSyntaxWrongHomeMountPointFormat()"); Attribute attributeToCheck = new Attribute(); attributeToCheck.setValue("/bin/\n/bash"); when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSession.class), any(Facility.class), any(User.class))).thenReturn(new ArrayList<Resource>() { { add(resource); } }); when(session.getPerunBl().getFacilitiesManagerBl().getAssignedResources(any(PerunSession.class), any(Facility.class))).thenReturn(new ArrayList<Resource>() { { add(resource); } }); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenReturn(listOfMntPts); classInstance.checkAttributeSyntax(session, user, facility, attributeToCheck); fail("Wrong homeMountPoint format should have thrown an exception"); }
@Test(expected = WrongAttributeValueException.class) public void testCheckAttributeSyntaxWrongHomeMountPointFormatInvalidCharacter() throws Exception { System.out.println("testCheckAttributeSyntaxWrongHomeMountPointFormatInvalidCharacter()"); Attribute attributeToCheck = new Attribute(); attributeToCheck.setValue("/ok/(&^%"); when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSession.class), any(Facility.class), any(User.class))).thenReturn(new ArrayList<Resource>() { { add(resource); } }); when(session.getPerunBl().getFacilitiesManagerBl().getAssignedResources(any(PerunSession.class), any(Facility.class))).thenReturn(new ArrayList<Resource>() { { add(resource); } }); when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenReturn(listOfMntPts); classInstance.checkAttributeSyntax(session, user, facility, attributeToCheck) ; fail("Wrong homeMountPoint format should have thrown an exception"); }