Esempio n. 1
0
 def _auth_client(self, auth_url):
     return json_v3id.V3TokenClient(
         auth_url,
         disable_ssl_certificate_validation=self.dscv,
         ca_certs=self.ca_certs,
         trace_requests=self.trace_requests,
         http_timeout=self.http_timeout)
Esempio n. 2
0
 def test_auth(self):
     token_client_v3 = token_client.V3TokenClient('fake_url')
     post_mock = self.useFixture(
         mockpatch.PatchObject(token_client_v3,
                               'post',
                               return_value=self.fake_201_http.request(
                                   'fake_url',
                                   body={'access': {
                                       'token': 'fake_token'
                                   }})))
     resp = token_client_v3.auth(username='******', password='******')
     self.assertIsInstance(resp, rest_client.ResponseBody)
     req_dict = json.dumps(
         {
             'auth': {
                 'identity': {
                     'methods': ['password'],
                     'password': {
                         'user': {
                             'name': 'fake_user',
                             'password': '******',
                         }
                     }
                 },
             }
         },
         sort_keys=True)
     post_mock.mock.assert_called_once_with('fake_url/auth/tokens',
                                            body=req_dict)
Esempio n. 3
0
    def test_auth(self):
        token_client_v3 = token_client.V3TokenClient('fake_url')
        response, body_text = fake_identity._fake_v3_response(None, None)
        body = json.loads(body_text)

        with mock.patch.object(token_client_v3, 'post') as post_mock:
            post_mock.return_value = response, body
            resp = token_client_v3.auth(username='******',
                                        password='******')

        self.assertIsInstance(resp, rest_client.ResponseBody)
        req_dict = json.dumps(
            {
                'auth': {
                    'identity': {
                        'methods': ['password'],
                        'password': {
                            'user': {
                                'name': 'fake_user',
                                'password': '******',
                            }
                        }
                    },
                }
            },
            sort_keys=True)
        post_mock.assert_called_once_with('fake_url/auth/tokens',
                                          body=req_dict)
    def test_auth_with_tenant(self):
        token_client_v3 = token_client.V3TokenClient('fake_url')
        response = fake_http.fake_http_response(
            None, status=201,
        )
        body = {'access': {'token': 'fake_token'}}

        with mock.patch.object(token_client_v3, 'post') as post_mock:
            post_mock.return_value = response, body
            resp = token_client_v3.auth(username='******',
                                        password='******',
                                        project_name='fake_tenant')

        self.assertIsInstance(resp, rest_client.ResponseBody)
        req_dict = json.dumps({
            'auth': {
                'identity': {
                    'methods': ['password'],
                    'password': {
                        'user': {
                            'name': 'fake_user',
                            'password': '******',
                        }
                    }},
                'scope': {
                    'project': {
                        'name': 'fake_tenant'
                    }
                },
            }
        }, sort_keys=True)

        post_mock.assert_called_once_with('fake_url/auth/tokens',
                                          body=req_dict)
Esempio n. 5
0
    def test_request_with_str_body(self):
        token_client_v3 = token_client.V3TokenClient('fake_url')

        with mock.patch.object(token_client_v3, 'raw_request') as mock_raw_r:
            mock_raw_r.return_value = (fake_identity._fake_v3_response(
                None, None))
            resp, body = token_client_v3.request('GET', 'fake_uri')

        self.assertIsInstance(body, dict)
Esempio n. 6
0
    def test_request_with_bytes_body(self):
        token_client_v3 = token_client.V3TokenClient('fake_url')

        response, body_text = fake_identity._fake_v3_response(None, None)
        body = body_text.encode('utf-8')

        with mock.patch.object(token_client_v3, 'raw_request') as mock_raw_r:
            mock_raw_r.return_value = response, body
            resp, body = token_client_v3.request('GET', 'fake_uri')

        self.assertIsInstance(body, dict)
Esempio n. 7
0
 def test_request_with_bytes_body(self):
     token_client_v3 = token_client.V3TokenClient('fake_url')
     self.useFixture(
         mockpatch.PatchObject(
             token_client_v3,
             'raw_request',
             return_value=(httplib2.Response({"status": "200"}),
                           bytes(b'{"access": {"token": "fake_token"}}'))))
     resp, body = token_client_v3.request('GET', 'fake_uri')
     self.assertIsInstance(resp, httplib2.Response)
     self.assertIsInstance(body, dict)
    def test_request_with_str_body(self):
        token_client_v3 = token_client.V3TokenClient('fake_url')

        with mock.patch.object(token_client_v3, 'raw_request') as mock_raw_r:
            mock_raw_r.return_value = (
                fake_identity._fake_v3_response(None, None))
            resp, body = token_client_v3.request('GET', 'fake_uri')
        mock_raw_r.assert_called_once_with('fake_uri', 'GET',
                                           headers=mock.ANY, body=None,
                                           log_req_body='<omitted>')

        self.assertIsInstance(body, dict)
    def test_request_with_str_body(self):
        token_client_v3 = token_client.V3TokenClient('fake_url')
        response = fake_http.fake_http_response(
            None, status=200,
        )
        body = str('{"access": {"token": "fake_token"}}')

        with mock.patch.object(token_client_v3, 'raw_request') as mock_raw_r:
            mock_raw_r.return_value = response, body
            resp, body = token_client_v3.request('GET', 'fake_uri')

        self.assertIsInstance(body, dict)
Esempio n. 10
0
    def test_auth_with_project_id_and_domain_id(self):
        token_client_v3 = token_client.V3TokenClient('fake_url')
        response = fake_http.fake_http_response(
            None,
            status=201,
        )
        body = {'access': {'token': 'fake_token'}}

        with mock.patch.object(token_client_v3, 'post') as post_mock:
            post_mock.return_value = response, body
            resp = token_client_v3.auth(
                username='******',
                password='******',
                project_id='fcac2a055a294e4c82d0a9c21c620eb4',
                user_domain_id='14f4a9a99973404d8c20ba1d2af163ff',
                project_domain_id='291f63ae9ac54ee292ca09e5f72d9676')

        self.assertIsInstance(resp, rest_client.ResponseBody)
        req_dict = json.dumps(
            {
                'auth': {
                    'identity': {
                        'methods': ['password'],
                        'password': {
                            'user': {
                                'name': 'fake_user',
                                'password': '******',
                                'domain': {
                                    'id': '14f4a9a99973404d8c20ba1d2af163ff'
                                }
                            }
                        }
                    },
                    'scope': {
                        'project': {
                            'id': 'fcac2a055a294e4c82d0a9c21c620eb4',
                            'domain': {
                                'id': '291f63ae9ac54ee292ca09e5f72d9676'
                            }
                        }
                    }
                }
            },
            sort_keys=True)
        post_mock.assert_called_once_with('fake_url/auth/tokens',
                                          body=req_dict)