def test_get_signature_value(self):
     """
     Ensures that we're able to get the string representation of the
     signature.
     """
     dom = ET.fromstring(VALID_SAML)
     signature = validation.get_signature(dom)
     result = validation.get_signature_value(signature)
     self.assertIsInstance(result, str)
 def test_get_signed_info(self):
     """
     Ensures the fragment of the DOM that is the information that is
     signed can be obtained FROM the DOM.
     """
     dom = ET.fromstring(VALID_SAML)
     signature = validation.get_signature(dom)
     result = validation.get_signed_info(signature)
     self.assertIsInstance(result, str)
 def test_get_cert(self):
     """
     Ensures that we're able to extract the certificate from the signature
     fragment.
     """
     dom = ET.fromstring(VALID_SAML)
     signature = validation.get_signature(dom)
     result = validation.get_cert(signature)
     self.assertIsInstance(result, str)
 def test_get_signature_value(self):
     """
     Ensures that we're able to get the string representation of the
     signature.
     """
     dom = ET.fromstring(VALID_SAML)
     signature = validation.get_signature(dom)
     result = validation.get_signature_value(signature)
     self.assertIsInstance(result, str)
 def test_get_cert(self):
     """
     Ensures that we're able to extract the certificate from the signature
     fragment.
     """
     dom = ET.fromstring(VALID_SAML)
     signature = validation.get_signature(dom)
     result = validation.get_cert(signature)
     self.assertIsInstance(result, str)
 def test_get_signed_info(self):
     """
     Ensures the fragment of the DOM that is the information that is
     signed can be obtained FROM the DOM.
     """
     dom = ET.fromstring(VALID_SAML)
     signature = validation.get_signature(dom)
     result = validation.get_signed_info(signature)
     self.assertIsInstance(result, str)
 def test_get_signature(self):
     """
     Ensures that given a valid DOM will return the element representing
     the Signature tag.
     """
     dom = ET.fromstring(VALID_SAML)
     result = validation.get_signature(dom)
     self.assertIsInstance(result, ET._Element)
     self.assertEqual('{http://www.w3.org/2000/09/xmldsig#}Signature',
                      result.tag)
 def test_get_signature(self):
     """
     Ensures that given a valid DOM will return the element representing
     the Signature tag.
     """
     dom = ET.fromstring(VALID_SAML)
     result = validation.get_signature(dom)
     self.assertIsInstance(result, ET._Element)
     self.assertEqual('{http://www.w3.org/2000/09/xmldsig#}Signature',
                      result.tag)
 def test_verify_signature(self):
     """
     Given various valid inputs, ensures the signature is verfied as
     correct.
     """
     dom = ET.fromstring(VALID_SAML)
     signature = validation.get_signature(dom)
     signed_info = validation.get_signed_info(signature)
     cert = validation.get_cert(signature)
     signature_value = validation.get_signature_value(signature)
     is_valid = validation.verify_signature(signed_info, cert,
                                            signature_value)
     self.assertEqual(1, is_valid)
Example #10
0
 def test_verify_signature(self):
     """
     Given various valid inputs, ensures the signature is verfied as
     correct.
     """
     dom = ET.fromstring(VALID_SAML)
     signature = validation.get_signature(dom)
     signed_info = validation.get_signed_info(signature)
     cert = validation.get_cert(signature)
     signature_value = validation.get_signature_value(signature)
     is_valid = validation.verify_signature(signed_info, cert,
                                            signature_value)
     self.assertEqual(1, is_valid)
 def test_verify_signature_with_bad_data(self):
     """
     Give some invalid inputs, ensures the signature is shown to be
     incorrect.
     """
     dom = ET.fromstring(VALID_SAML)
     signature = validation.get_signature(dom)
     signed_info = validation.get_signed_info(signature)
     cert = validation.get_cert(signature)
     signature_value = validation.get_signature_value(signature)
     signature_value = 'WRONG' + signature_value[5:]
     is_valid = validation.verify_signature(signed_info, cert,
                                            signature_value)
     self.assertEqual(0, is_valid)
Example #12
0
 def test_verify_signature_with_bad_data(self):
     """
     Give some invalid inputs, ensures the signature is shown to be
     incorrect.
     """
     dom = ET.fromstring(VALID_SAML)
     signature = validation.get_signature(dom)
     signed_info = validation.get_signed_info(signature)
     cert = validation.get_cert(signature)
     signature_value = validation.get_signature_value(signature)
     signature_value = 'WRONG' + signature_value[5:]
     is_valid = validation.verify_signature(signed_info, cert,
                                            signature_value)
     self.assertEqual(0, is_valid)
Example #13
0
 def test_get_signed_info_c14n_exclusive(self):
     """
     Ensures that the method for generating the string is generated with
     the correct function for canonicalization with the exclusive flag set
     to True.
     """
     with mock.patch.object(validation.ET, 'tostring') as mock_call:
         dom = ET.fromstring(VALID_SAML)
         signature = validation.get_signature(dom)
         validation.get_signed_info(signature)
         signed_info = signature.find(
                     '{http://www.w3.org/2000/09/xmldsig#}SignedInfo')
         mock_call.assert_called_once_with(signed_info, method='c14n',
                                           exclusive=True)