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)
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_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)