def test_missing_mandatory_attribute(self): validator = AuthnRequestXMLSchemaValidator(translator=FakeTranslator()) request = FakeRequest(sample_requests.missing_issue_instant_attr) with pytest.raises(XMLSchemaValidationError) as excinfo: validator.validate(request) exc = excinfo.value self.assertEqual(len(exc.details), 1) self.assertIn("The attribute 'IssueInstant' is required but missing.", exc.details[0].message)
def test_invalid_attribute_format(self): # See: https://github.com/italia/spid-testenv2/issues/63 validator = AuthnRequestXMLSchemaValidator(translator=FakeTranslator()) request = FakeRequest(sample_requests.invalid_id_attr) with pytest.raises(XMLSchemaValidationError) as excinfo: validator.validate(request) exc = excinfo.value self.assertEqual(len(exc.details), 1) self.assertIn("is not a valid value of the atomic type 'xs:ID'", exc.details[0].message)
def test_multiple_errors(self): validator = AuthnRequestXMLSchemaValidator(translator=FakeTranslator()) request = FakeRequest(sample_requests.multiple_errors) with pytest.raises(XMLSchemaValidationError) as excinfo: validator.validate(request) exc = excinfo.value self.assertEqual(len(exc.details), 2) self.assertIn("is not a valid value of the atomic type 'xs:ID'", exc.details[0].message) self.assertIn("The attribute 'Version' is required but missing.", exc.details[1].message)
def test_invalid_comparison_attribute(self): # https://github.com/italia/spid-testenv2/issues/97 validator = AuthnRequestXMLSchemaValidator(translator=FakeTranslator()) request = FakeRequest(sample_requests.invalid_comparison_attr) with pytest.raises(XMLSchemaValidationError) as excinfo: validator.validate(request) exc = excinfo.value self.assertEqual(exc.details[0].type_name, 'SCHEMAV_CVC_ENUMERATION_VALID') self.assertIn( "The value 'invalid' is not an element of the set " "{'exact', 'minimum', 'maximum', 'better'}", exc.details[0].message )
def test_unexpected_element(self): # See: https://github.com/italia/spid-testenv2/issues/79 validator = AuthnRequestXMLSchemaValidator(translator=FakeTranslator()) request = FakeRequest(sample_requests.unexpected_element) with pytest.raises(XMLSchemaValidationError) as excinfo: validator.validate(request) exc = excinfo.value self.assertEqual(len(exc.details), 1) self.assertIn( "Element 'AuthnContextClassRef': " "This element is not expected. Expected is one of ( " "Conditions, RequestedAuthnContext, Scoping ).", exc.details[0].message)
def test_valid_requests(self): validator = AuthnRequestXMLSchemaValidator(translator=FakeTranslator()) for request in sample_requests.valid: request = FakeRequest(request) self.assertIsNone(validator.validate(request))