def test_uri_invalid(self): self.assertFalse(ValidationTools.validate_uri("/foo/bar")) self.assertFalse(ValidationTools.validate_uri("moo.com/foobar")) self.assertFalse(ValidationTools.validate_uri("foo.de:80/jfisoud")) self.assertFalse(ValidationTools.validate_uri("://foo")) self.assertFalse(ValidationTools.validate_uri("://foo/")) self.assertFalse(ValidationTools.validate_uri("http:../example.com"))
def _validate_uniformResourceIdentifier(self): self._report( "Enc_DER_Struct_GenName_URI_Unexpected", "contains unexpected URI \"%s\"." % (self._subject.str_value)) if not ValidationTools.validate_uri(str(self._subject.str_value)): self._report("Enc_DER_Struct_GenName_URI_Malformed", "contains invalid URI \"%s\"." % (str(self._subject.str_value)), commonness=Commonness.HIGHLY_UNUSUAL, compatibility=Compatibility.STANDARDS_DEVIATION) if self._validator.permissible_uri_schemes is not None: split_url = urllib.parse.urlsplit(self._subject.str_value) if split_url.scheme not in self._validator.permissible_uri_schemes: self._report( "Enc_DER_Struct_GenName_URI_UncommonURIScheme", "contains invalid URI scheme \"%s\" (permitted schemes are only %s)." % (str(self._subject.str_value), ", ".join( sorted(self._validator.permissible_uri_schemes))), commonness=Commonness.UNUSUAL)
def test_uri_valid(self): self.assertTrue(ValidationTools.validate_uri("http://a")) self.assertTrue(ValidationTools.validate_uri("http://a.a/")) self.assertTrue(ValidationTools.validate_uri("http://a/a")) self.assertTrue(ValidationTools.validate_uri("http://a/a/")) self.assertTrue(ValidationTools.validate_uri("http://a/a/?")) self.assertTrue(ValidationTools.validate_uri("http://a/a/?a")) self.assertTrue( ValidationTools.validate_uri( "http://de.wikipedia.org/wiki/Uniform_Resource_Identifier")) self.assertTrue( ValidationTools.validate_uri( "http://de.wikipedia.org/wiki/Uniform_Resource_Identifier/")) self.assertTrue( ValidationTools.validate_uri("ftp://ftp.is.co.za/rfc/rfc1808.txt")) self.assertTrue( ValidationTools.validate_uri( "file:///C:/Users/Benutzer/Desktop/Uniform%20Resource%20Identifier.html" )) self.assertTrue(ValidationTools.validate_uri("file:///etc/fstab")) self.assertTrue( ValidationTools.validate_uri("geo:48.33,14.122;u=22.5")) self.assertTrue( ValidationTools.validate_uri( "ldap://[2001:db8::7]/c=GB?objectClass?one")) self.assertTrue( ValidationTools.validate_uri("gopher://gopher.floodgap.com")) self.assertTrue( ValidationTools.validate_uri("mailto:[email protected]")) self.assertTrue( ValidationTools.validate_uri("sip:[email protected]")) self.assertTrue( ValidationTools.validate_uri( "news:comp.infosystems.www.servers.unix")) self.assertTrue( ValidationTools.validate_uri( "data:text/plain;charset=iso-8859-7,%be%fa%be")) self.assertTrue(ValidationTools.validate_uri("tel:+1-816-555-1212")) self.assertTrue( ValidationTools.validate_uri("telnet://192.0.2.16:80/")) self.assertTrue( ValidationTools.validate_uri( "urn:oasis:names:specification:docbook:dtd:xml:4.1.2")) self.assertTrue( ValidationTools.validate_uri("git://github.com/rails/rails.git")) self.assertTrue( ValidationTools.validate_uri( "crid://broadcaster.com/movies/BestActionMovieEver")) self.assertTrue( ValidationTools.validate_uri("http://aa.bbbb-c.dd/eeeeee"))