def test_missing_data(self): for key in ['SAMLRequest', 'SigAlg', 'Signature']: qs = copy(self.querystring) del qs[key] parser = HTTPRedirectRequestParser(qs) with pytest.raises(RequestParserError) as excinfo: parser.parse() exc = excinfo.value self.assertEqual("Dato mancante nella request: '{}'".format(key), exc.args[0])
def test_decoding_failure(self): for key in ['SAMLRequest', 'Signature']: qs = copy(self.querystring) qs[key] = 'XXX_not_base64_data_XXX' parser = HTTPRedirectRequestParser(qs) with pytest.raises(RequestParserError) as excinfo: parser.parse() exc = excinfo.value self.assertEqual( "Impossibile decodificare l'elemento '{}'".format(key), exc.args[0])
def test_valid_request(self): parser = HTTPRedirectRequestParser(self.querystring) parsed = parser.parse() self.assertEqual(parsed.saml_request, b'saml_request') self.assertEqual(parsed.sig_alg, 'sig_alg') self.assertEqual(parsed.relay_state, 'relay_state') self.assertEqual(parsed.signature, b'signature') signed_data = urlencode([ ('SAMLRequest', self.querystring['SAMLRequest']), ('RelayState', self.querystring['RelayState']), ('SigAlg', self.querystring['SigAlg']), ]).encode('ascii') self.assertEqual(parsed.signed_data, signed_data)
def test_relay_state_is_optional(self): del self.querystring['RelayState'] parser = HTTPRedirectRequestParser(self.querystring) parsed = parser.parse() self.assertIsNone(parsed.relay_state)