Пример #1
0
    def submit_results(self, session):
        print("Submitting results to {0} for secure_id {1}".format(
              self.config.c3_url, self.config.secure_id))
        options_string = "secure_id={0}".format(self.config.secure_id)
        # Create the transport object
        try:
            transport = CertificationTransport(
                self.config.c3_url, options_string, self.config)
        except InvalidSecureIDError as exc:
            print(exc)
            return False
        with open(self.submission_file) as stream:
            try:
                # Send the data, reading from the fallback file
                result = transport.send(stream)
                if 'url' in result:
                    print("Successfully sent, submission status at {0}".format(
                          result['url']))
                else:
                    print("Successfully sent, server response: {0}".format(
                          result))

            except InvalidSchema as exc:
                print("Invalid destination URL: {0}".format(exc))
            except ConnectionError as exc:
                print("Unable to connect to destination URL: {0}".format(exc))
            except HTTPError as exc:
                print(("Server returned an error when "
                       "receiving or processing: {0}").format(exc))
            except IOError as exc:
                print("Problem reading a file: {0}".format(exc))
Пример #2
0
    def submit_results(self, session):
        print("Submitting results to {0} for secure_id {1}".format(
            self.config.c3_url, self.config.secure_id))
        options_string = "secure_id={0}".format(self.config.secure_id)
        # Create the transport object
        try:
            transport = CertificationTransport(self.config.c3_url,
                                               options_string, self.config)
        except InvalidSecureIDError as exc:
            print(exc)
            return False
        with open(self.submission_file) as stream:
            try:
                # Send the data, reading from the fallback file
                result = transport.send(stream)
                if 'url' in result:
                    print("Successfully sent, submission status at {0}".format(
                        result['url']))
                else:
                    print("Successfully sent, server response: {0}".format(
                        result))

            except InvalidSchema as exc:
                print("Invalid destination URL: {0}".format(exc))
            except ConnectionError as exc:
                print("Unable to connect to destination URL: {0}".format(exc))
            except HTTPError as exc:
                print(("Server returned an error when "
                       "receiving or processing: {0}").format(exc))
            except IOError as exc:
                print("Problem reading a file: {0}".format(exc))
Пример #3
0
 def test_send_success(self):
     transport = CertificationTransport(
         self.valid_url, self.valid_option_string)
     requests.post.return_value = MagicMock(name='response')
     requests.post.return_value.status_code = 200
     requests.post.return_value.text = '{"id": 768}'
     result = transport.send(self.sample_xml)
     self.assertTrue(result)
Пример #4
0
    def test_send_success(self):
        transport = CertificationTransport(self.valid_url,
                                           self.valid_option_string)

        requests.post.return_value = MagicMock(name='response')
        requests.post.return_value.status_code = 200
        requests.post.return_value.text = '{"id": 768}'
        result = transport.send(self.sample_xml)

        self.assertTrue(result)
Пример #5
0
 def test_send_failure(self):
     transport = CertificationTransport(
         self.valid_url, self.valid_option_string)
     requests.post.return_value = MagicMock(name='response')
     requests.post.return_value.status_code = 412
     requests.post.return_value.text = 'Some error'
     # Oops, raise_for_status doesn't get fooled by my mocking,
     # so I have to mock *that* method as well..
     requests.post.return_value.raise_for_status = MagicMock(
         side_effect=HTTPError)
     with self.assertRaises(TransportError):
         transport.send(self.sample_xml)
Пример #6
0
    def test_invalid_url(self):
        transport = CertificationTransport(
            self.invalid_url, self.valid_option_string)
        dummy_data = BytesIO(b"some data to send")
        requests.post.side_effect = InvalidSchema

        with self.assertRaises(TransportError):
            result = transport.send(dummy_data)
            self.assertIsNotNone(result)
        requests.post.assert_called_with(
            self.invalid_url, files={'data': dummy_data},
            headers={'X_HARDWARE_ID': self.valid_secure_id}, proxies=None)
Пример #7
0
 def test_share_with_hexr_header_sent(self, mock_logger):
     transport = CertificationTransport(
         self.valid_url, self.valid_option_string+",submit_to_hexr=1")
     dummy_data = BytesIO(b"some data to send")
     result = transport.send(dummy_data)
     self.assertIsNotNone(result)
     requests.post.assert_called_with(self.valid_url,
                                      files={'data': dummy_data},
                                      headers={'X_HARDWARE_ID':
                                               self.valid_secure_id,
                                               'X-Share-With-HEXR':
                                               True},
                                      proxies=None)
Пример #8
0
 def test_valid_url_cant_connect(self, mock_logger):
     transport = CertificationTransport(
         self.unreachable_url, self.valid_option_string)
     dummy_data = BytesIO(b"some data to send")
     requests.post.side_effect = ConnectionError
     with self.assertRaises(TransportError):
         result = transport.send(dummy_data)
         self.assertIsNotNone(result)
     requests.post.assert_called_with(self.unreachable_url,
                                      files={'data': dummy_data},
                                      headers={'X_HARDWARE_ID':
                                               self.valid_secure_id},
                                      proxies=None)
Пример #9
0
    def test_valid_url_cant_connect(self):
        transport = CertificationTransport(self.unreachable_url,
                                           self.valid_option_string)
        dummy_data = BytesIO(b"some data to send")
        requests.post.side_effect = ConnectionError

        with self.assertRaises(ConnectionError):
            result = transport.send(dummy_data)
            self.assertIsNotNone(result)
        requests.post.assert_called_with(self.unreachable_url,
                                         files={'data': dummy_data},
                                         headers={'X_HARDWARE_ID':
                                                  self.valid_secure_id},
                                         proxies=None)
Пример #10
0
    def test_invalid_url(self):
        transport = CertificationTransport(self.invalid_url,
                                           self.valid_option_string)
        dummy_data = BytesIO(b"some data to send")
        requests.post.side_effect = InvalidSchema

        with self.assertRaises(InvalidSchema):
            result = transport.send(dummy_data)
            self.assertIsNotNone(result)
        requests.post.assert_called_with(self.invalid_url,
                                         files={'data': dummy_data},
                                         headers={'X_HARDWARE_ID':
                                         self.valid_secure_id},
                                         proxies=None)
Пример #11
0
    def test_send_failure(self):
        transport = CertificationTransport(self.valid_url,
                                           self.valid_option_string)

        requests.post.return_value = MagicMock(name='response')
        requests.post.return_value.status_code = 412
        requests.post.return_value.text = 'Some error'
        #Oops, raise_for_status doesn't get fooled by my mocking,
        #so I have to mock *that* method as well..
        requests.post.return_value.raise_for_status = MagicMock(
            side_effect=HTTPError)

        with self.assertRaises(HTTPError):
            result = transport.send(self.sample_xml)
            self.assertIsNotNone(result)
Пример #12
0
 def test_invalid_characters_in_secure_id_are_rejected(self):
     option_string = "secure_id=aA0#"
     with self.assertRaises(InvalidSecureIDError):
             transport = CertificationTransport(self.valid_url,
                                                option_string)
             self.assertIsInstance(CertificationTransport,
                                   transport)
Пример #13
0
 def test_parameter_parsing(self):
     # Makes sense since I'm overriding the base class's constructor.
     transport = CertificationTransport(
         self.valid_url, self.valid_option_string)
     self.assertEqual(self.valid_url, transport.url)
     self.assertEqual(self.valid_secure_id,
                      transport.options['secure_id'])
Пример #14
0
 def test_invalid_length_secure_id_are_rejected(self):
     for length in (14, 16, 20):
         dummy_id = "a" * length
         option_string = "secure_id={}".format(dummy_id)
         with self.assertRaises(InvalidSecureIDError):
             transport = CertificationTransport(self.valid_url,
                                                option_string)
             self.assertIsInstance(CertificationTransport,
                                   transport)
Пример #15
0
    def run(self):
        options_string = "secure_id={0}".format(self.ns.secure_id)
        transport = CertificationTransport(self.ns.url, options_string)

        try:
            with open(self.ns.submission, "r", encoding='utf-8') as subm_file:
                result = transport.send(subm_file)
        except (TransportError, OSError) as exc:
            raise SystemExit(exc)
        else:
            if 'url' in result:
                # TRANSLATORS: Do not translate the {} format marker.
                print(_("Successfully sent, submission status"
                        " at {0}").format(result['url']))
            else:
                # TRANSLATORS: Do not translate the {} format marker.
                print(_("Successfully sent, server response"
                        ": {0}").format(result))
Пример #16
0
    def proxy_test(self, environment, proxies):
        test_environment = environment
        test_proxies = proxies
        test_config = PlainBoxConfig()
        test_config.environment = test_environment

        transport = CertificationTransport(
            self.valid_url, self.valid_option_string)
        dummy_data = BytesIO(b"some data to send")

        requests.post.return_value = MagicMock(name='response')
        requests.post.return_value.status_code = 200
        requests.post.return_value.text = '{"id": 768}'
        result = transport.send(dummy_data, config=test_config)
        self.assertTrue(result)
        requests.post.assert_called_with(
            self.valid_url, files={'data': dummy_data},
            headers={'X_HARDWARE_ID': self.valid_secure_id},
            proxies=test_proxies)
Пример #17
0
    def _submit_results(self):
        print("Submitting results to {0} for secure_id {1}".format(
            self.config.c3_url, self.config.secure_id))
        options_string = "secure_id={0}".format(self.config.secure_id)
        # Create the transport object
        try:
            transport = CertificationTransport(self.config.c3_url,
                                               options_string, self.config)
        except InvalidSecureIDError as exc:
            print(exc)
            return False
        # Prepare the data for submission
        data = self.exporter.get_session_data_subset(self.session)
        with tempfile.NamedTemporaryFile(mode='w+b') as stream:
            # Dump the data to the temporary file
            self.exporter.dump(data, stream)
            # Flush and rewind
            stream.flush()
            stream.seek(0)
            try:
                # Send the data, reading from the temporary file
                result = transport.send(stream)
                if 'url' in result:
                    print("Successfully sent, submission status at {0}".format(
                        result['url']))
                else:
                    print("Successfully sent, server response: {0}".format(
                        result))

            except InvalidSchema as exc:
                print("Invalid destination URL: {0}".format(exc))
            except ConnectionError as exc:
                print("Unable to connect to destination URL: {0}".format(exc))
            except HTTPError as exc:
                print(("Server returned an error when "
                       "receiving or processing: {0}").format(exc))
            except IOError as exc:
                print("Problem reading a file: {0}".format(exc))
Пример #18
0
    def _submit_results(self):
        print("Submitting results to {0} for secure_id {1}".format(
              self.config.c3_url, self.config.secure_id))
        options_string = "secure_id={0}".format(self.config.secure_id)
        # Create the transport object
        try:
            transport = CertificationTransport(
                self.config.c3_url, options_string, self.config)
        except InvalidSecureIDError as exc:
            print(exc)
            return False
        # Prepare the data for submission
        data = self.exporter.get_session_data_subset(self.session)
        with tempfile.NamedTemporaryFile(mode='w+b') as stream:
            # Dump the data to the temporary file
            self.exporter.dump(data, stream)
            # Flush and rewind
            stream.flush()
            stream.seek(0)
            try:
                # Send the data, reading from the temporary file
                result = transport.send(stream)
                if 'url' in result:
                    print("Successfully sent, submission status at {0}".format(
                          result['url']))
                else:
                    print("Successfully sent, server response: {0}".format(
                          result))

            except InvalidSchema as exc:
                print("Invalid destination URL: {0}".format(exc))
            except ConnectionError as exc:
                print("Unable to connect to destination URL: {0}".format(exc))
            except HTTPError as exc:
                print(("Server returned an error when "
                       "receiving or processing: {0}").format(exc))
            except IOError as exc:
                print("Problem reading a file: {0}".format(exc))
Пример #19
0
    def proxy_test(self, environment, proxies):
        test_environment = environment
        test_proxies = proxies
        test_config = PlainBoxConfig()
        test_config.environment = test_environment

        transport = CertificationTransport(self.valid_url,
                                           self.valid_option_string,
                                           config=test_config)
        dummy_data = BytesIO(b"some data to send")

        requests.post.return_value = MagicMock(name='response')
        requests.post.return_value.status_code = 200
        requests.post.return_value.text = '{"id": 768}'
        result = transport.send(dummy_data)

        self.assertTrue(result)

        requests.post.assert_called_with(self.valid_url,
                                         files={'data': dummy_data},
                                         headers={'X_HARDWARE_ID':
                                         self.valid_secure_id},
                                         proxies=test_proxies)
Пример #20
0
 def test_invalid_length_secure_id_are_rejected(self):
     length = 14
     dummy_id = "a" * length
     option_string = "secure_id={}".format(dummy_id)
     with self.assertRaises(InvalidSecureIDError):
         CertificationTransport(self.valid_url, option_string)
Пример #21
0
 def test_submit_to_hexr_interpretation(self):
     transport = CertificationTransport(
         self.valid_url, "submit_to_hexr=1")
     self.assertTrue(transport._submit_to_hexr is True)