def test_sign_assertion_response_signed(self):
     root = Element(Q_NAMES['saml2p:Response'])
     SubElement(root, Q_NAMES['saml2:Assertion'])
     response_signature = SubElement(root, Q_NAMES['ds:Signature'])
     response = SAMLResponse(ElementTree(root))
     with self.assertRaisesMessage(SecurityError,
                                   'response signature is already present'):
         response.sign_assertion(**SIGNATURE_OPTIONS)
     self.assertIs(response.response_signature,
                   response_signature)  # Preserved
     self.assertIsNone(response.assertion_signature)
 def test_sign_assertion_without_issuer(self):
     root = Element(Q_NAMES['saml2p:Response'])
     assertion = SubElement(root, Q_NAMES['saml2:Assertion'])
     SubElement(assertion, Q_NAMES['saml2:Subject'])
     response = SAMLResponse(ElementTree(root))
     self.assertTrue(response.sign_assertion(**SIGNATURE_OPTIONS))
     self.assertIsNone(response.response_signature)
     self.assertIsNotNone(response.assertion_signature)
     self.assertEqual(assertion.index(response.assertion_signature), 0)
 def test_sign_assertion_decrypted(self):
     root = Element(Q_NAMES['saml2p:Response'])
     assertion = SubElement(
         SubElement(root, Q_NAMES['saml2:EncryptedAssertion']),
         Q_NAMES['saml2:Assertion'])
     response_signature = SubElement(root, Q_NAMES['ds:Signature'])
     assertion_signature = SubElement(assertion, Q_NAMES['ds:Signature'])
     response = SAMLResponse(ElementTree(root))
     self.assertFalse(response.sign_assertion(**SIGNATURE_OPTIONS))
     self.assertIs(response.response_signature,
                   response_signature)  # Preserved
     self.assertIs(response.assertion_signature,
                   assertion_signature)  # Preserved
 def test_sign_assertion_no_assertion(self):
     root = Element(Q_NAMES['saml2p:Response'])
     response = SAMLResponse(ElementTree(root))
     self.assertFalse(response.sign_assertion(**SIGNATURE_OPTIONS))
     self.assertIsNone(response.response_signature)
     self.assertIsNone(response.assertion_signature)