Exemple #1
0
    def test_proxies_param_with_ntlm(self):
        """Test proxies with NTLM credentials."""
        urls = {'http': 'localhost:8080', 'https': 'localhost:8080'}
        proxies_with_ntlm_dict = {
            'urls': urls,
            'username_ntlm': 'domain\\username',
            'password_ntlm': 'password'
        }
        ntlm_expected_result = {
            'verify': True,
            'proxies': urls,
            'auth': HttpNtlmAuth('domain\\username', 'password')
        }
        proxies_with_ntlm_credentials = Credentials(
            'dummy_token', 'https://dummy_url', proxies=proxies_with_ntlm_dict)
        result = proxies_with_ntlm_credentials.connection_parameters()

        # Verify the NTLM credentials.
        self.assertEqual(
            ntlm_expected_result['auth'].username, result['auth'].username)
        self.assertEqual(
            ntlm_expected_result['auth'].password, result['auth'].password)

        # Remove the HttpNtlmAuth objects for direct comparison of the dicts.
        ntlm_expected_result.pop('auth')
        result.pop('auth')
        self.assertDictEqual(ntlm_expected_result, result)
Exemple #2
0
 def test_verify_param(self):
     """Test 'verify' arg is acknowledged."""
     false_verify_expected_result = {'verify': False}
     false_verify_credentials = Credentials(
         'dummy_token', 'https://dummy_url', verify=False)
     result = false_verify_credentials.connection_parameters()
     self.assertDictEqual(false_verify_expected_result, result)
Exemple #3
0
 def test_proxy_param(self):
     """Test using only proxy urls (no NTLM credentials)."""
     urls = {'http': 'localhost:8080', 'https': 'localhost:8080'}
     proxies_only_expected_result = {'verify': True, 'proxies': urls}
     proxies_only_credentials = Credentials(
         'dummy_token', 'https://dummy_url', proxies={'urls': urls})
     result = proxies_only_credentials.connection_parameters()
     self.assertDictEqual(proxies_only_expected_result, result)
Exemple #4
0
    def __init__(self, access_token: str, credentials: Credentials) -> None:
        """ExperimentClient constructor.

        Args:
            access_token: IBM Quantum Experience access token.
            credentials: Account credentials.
        """
        self._session = RetrySession(credentials.experiment_url, access_token,
                                     **credentials.connection_parameters())
        self.base_api = Api(self._session)
Exemple #5
0
    def test_malformed_proxy_param(self):
        """Test input with malformed nesting of the proxies dictionary."""
        urls = {'http': 'localhost:8080', 'https': 'localhost:8080'}
        malformed_nested_proxies_dict = {'proxies': urls}
        malformed_nested_credentials = Credentials(
            'dummy_token', 'https://dummy_url',
            proxies=malformed_nested_proxies_dict)

        # Malformed proxy entries should be ignored.
        expected_result = {'verify': True}
        result = malformed_nested_credentials.connection_parameters()
        self.assertDictEqual(expected_result, result)
Exemple #6
0
    def __init__(
        self,
        access_token: str,
        credentials: Credentials,
    ) -> None:
        """RandomClient constructor.

        Args:
            access_token: IBM Quantum Experience access token.
            credentials: Account credentials.
        """
        self._session = RetrySession(credentials.extractor_url, access_token,
                                     **credentials.connection_parameters())
        self.random_api = Random(self._session)
Exemple #7
0
 def test_malformed_ntlm_params(self):
     """Test input with malformed NTLM credentials."""
     urls = {'http': 'localhost:8080', 'https': 'localhost:8080'}
     malformed_ntlm_credentials_dict = {
         'urls': urls,
         'username_ntlm': 1234,
         'password_ntlm': 5678
     }
     malformed_ntlm_credentials = Credentials(
         'dummy_token', 'https://dummy_url',
         proxies=malformed_ntlm_credentials_dict)
     # Should raise when trying to do username.split('\\', <int>)
     # in NTLM credentials due to int not facilitating 'split'.
     with self.assertRaises(AttributeError):
         _ = malformed_ntlm_credentials.connection_parameters()
Exemple #8
0
 def test_proxy_urls(self, qe_token, qe_url):
     """Test different forms of the proxy urls."""
     test_urls = [
         'http://{}:{}'.format(ADDRESS,
                               PORT), '//{}:{}'.format(ADDRESS, PORT),
         'http:{}:{}'.format(ADDRESS, PORT),
         'http://*****:*****@{}:{}'.format(ADDRESS, PORT)
     ]
     for proxy_url in test_urls:
         with self.subTest(proxy_url=proxy_url):
             credentials = Credentials(
                 qe_token, qe_url, proxies={'urls': {
                     'https': proxy_url
                 }})
             version_finder = VersionClient(
                 credentials.base_url,
                 **credentials.connection_parameters())
             version_finder.version()
Exemple #9
0
 def test_no_proxy_params(self):
     """Test when no proxy parameters are passed."""
     no_params_expected_result = {'verify': True}
     no_params_credentials = Credentials('dummy_token', 'https://dummy_url')
     result = no_params_credentials.connection_parameters()
     self.assertDictEqual(no_params_expected_result, result)