コード例 #1
0
 def test_load_xml_attributes_unexpected_element(self):
     data = parse_xml(b'<lightRequest><requestedAttributes><myField>data</myField>'
                      b'</requestedAttributes></lightRequest>')
     with self.assertRaisesMessage(ValidationError,
                                   '\'<lightRequest><requestedAttributes><myField>\': '
                                   '"Unexpected element \'myField\'"'):
         LightRequest.load_xml(data)
コード例 #2
0
 def test_load_xml_attribute_values_unexpected_element(self):
     data = parse_xml(b'<lightRequest><requestedAttributes><attribute><definition>data</definition><foo/>'
                      b'</attribute></requestedAttributes></lightRequest>')
     with self.assertRaisesMessage(ValidationError,
                                   '\'<lightRequest><requestedAttributes><attribute><foo>\': '
                                   '"Unexpected element \'foo\'"'):
         LightRequest.load_xml(data)
コード例 #3
0
 def test_load_xml_attributes_definition_element(self):
     data = parse_xml(b'<lightRequest><requestedAttributes><attribute>data</attribute>'
                      b'</requestedAttributes></lightRequest>')
     with self.assertRaisesMessage(ValidationError,
                                   "'<lightRequest><requestedAttributes><attribute>': "
                                   "'Missing attribute.definition element.'"):
         LightRequest.load_xml(data)
     data = parse_xml(b'<lightRequest><requestedAttributes><attribute><foo>data</foo>'
                      b'</attribute></requestedAttributes></lightRequest>')
     with self.assertRaisesMessage(ValidationError,
                                   '\'<lightRequest><requestedAttributes><attribute><foo>\': '
                                   '"Unexpected element \'foo\'"'):
         LightRequest.load_xml(data)
コード例 #4
0
    def test_export_xml_full_sample(self):
        self.maxDiff = None

        with cast(BinaryIO, (DATA_DIR / 'light_request.xml').open('rb')) as f:
            data = f.read()
            request = LightRequest.load_xml(parse_xml(data))
        self.assertEqual(dump_xml(request.export_xml()), data)
コード例 #5
0
    def test_put_light_request(self):
        with cast(TextIO, (DATA_DIR / 'light_request.xml').open('r')) as f:
            data = f.read()

        request = LightRequest.load_xml(parse_xml(data))
        self.storage.put_light_request('abc', request)
        self.assertEqual(self.client_class_mock.mock_calls, [call(timeout=33)])
        self.assertEqual(self.client_mock.mock_calls, [
            call.connect(self.HOST, self.PORT),
            call.get_cache(self.REQUEST_CACHE_NAME),
            call.get_cache().put('abc', data)
        ])
コード例 #6
0
    def test_from_light_request_invalid_id(self):
        self.maxDiff = None

        with cast(BinaryIO,
                  (DATA_DIR / 'light_request_minimal.xml').open('rb')) as f:
            request = LightRequest.load_xml(parse_xml(f))
        request.id = '0day'

        with self.assert_validation_error(
                'id', "Light request id is not a valid XML id: '0day'"):
            SAMLRequest.from_light_request(
                request, 'test/destination',
                datetime(2017, 12, 11, 14, 12, 5, 148000))
コード例 #7
0
    def test_pop_light_request_found(self):
        with cast(BinaryIO, (DATA_DIR / 'light_request.xml').open('rb')) as f:
            data = f.read()

        self.cache_mock.get_and_remove.return_value = data.decode('utf-8')
        self.assertEqual(LightRequest.load_xml(parse_xml(data)),
                         self.storage.pop_light_request('abc'))
        self.assertEqual(self.client_class_mock.mock_calls, [call(timeout=33)])
        self.assertEqual(self.client_mock.mock_calls, [
            call.connect(self.HOST, self.PORT),
            call.get_cache(self.REQUEST_CACHE_NAME),
            call.get_cache().get_and_remove('abc')
        ])
コード例 #8
0
    def test_load_xml_minimal_sample(self):
        self.maxDiff = None

        with cast(BinaryIO, (DATA_DIR / 'light_request_minimal.xml').open('rb')) as f:
            request = LightRequest.load_xml(parse_xml(f))

        self.assertEqual(request.citizen_country_code, 'CA')
        self.assertEqual(request.id, 'test-light-request-id')
        self.assertIsNone(request.issuer)
        self.assertEqual(request.level_of_assurance, LevelOfAssurance.LOW)
        self.assertIsNone(request.name_id_format)
        self.assertIsNone(request.provider_name)
        self.assertIsNone(request.sp_type)
        self.assertIsNone(request.relay_state)
        self.assertEqual(request.requested_attributes, {})
コード例 #9
0
    def test_from_light_request_minimal(self):
        self.maxDiff = None

        with cast(BinaryIO,
                  (DATA_DIR / 'light_request_minimal.xml').open('rb')) as f:
            request = LightRequest.load_xml(parse_xml(f))
        request.id = 'test-saml-request-id'

        saml_request = SAMLRequest.from_light_request(
            request, 'test/destination',
            datetime(2017, 12, 11, 14, 12, 5, 148000))

        with cast(TextIO,
                  (DATA_DIR / 'saml_request_minimal.xml').open('r')) as f2:
            data = f2.read()
        self.assertXMLEqual(
            dump_xml(saml_request.document).decode('utf-8'), data)
        self.assertEqual(saml_request.relay_state, None)
        self.assertEqual(saml_request.citizen_country_code, 'CA')
コード例 #10
0
 def test_load_xml_unknown_element(self):
     data = parse_xml(b'<lightRequest><myField>data</myField></lightRequest>')
     with self.assertRaisesMessage(ValidationError, '\'<lightRequest><myField>\': "Unknown element \'myField\'."'):
         LightRequest.load_xml(data)
コード例 #11
0
 def test_load_xml_wrong_root_element(self):
     data = parse_xml(b'<lightResponse></lightResponse>')
     with self.assertRaisesMessage(ValidationError,
                                   '\'<lightResponse>\': "Invalid root element \'lightResponse\'."'):
         LightRequest.load_xml(data)
コード例 #12
0
 def test_load_xml_full_sample(self):
     with cast(BinaryIO, (DATA_DIR / 'light_request.xml').open('rb')) as f:
         request = LightRequest.load_xml(parse_xml(f))
     self.assertEqual(request, LightRequest(**LIGHT_REQUEST_DICT))