示例#1
0
    def test_get_auth_client_oauth2_client_credentials_with_local(self):
        cfg.CONF.set_override('auth_type',
                              'OAUTH2_CLIENT_CREDENTIALS',
                              group='authentication')
        cfg.CONF.set_override('token_endpoint',
                              self.url,
                              group='authentication')
        cfg.CONF.set_override('client_id',
                              self.user_name,
                              group='authentication')
        cfg.CONF.set_override('client_password',
                              self.password,
                              group='authentication')

        self.requests_mock.register_uri(
            'GET',
            self.url,
            json={
                'access_token': 'test_token3',
                'token_type': 'bearer'
            },
            headers={'Content-Type': 'application/json'},
            status_code=200)

        auth.auth_manager = auth._AuthManager()
        client = auth.auth_manager.get_auth_client()

        self.assertIsInstance(client, auth._OAuth2Session)
        self.assertEqual(self.user_name, client.grant.client_id)
        self.assertEqual(self.password, client.grant.client_password)
        self.assertEqual(self.url, client.grant.token_endpoint)

        history = self.requests_mock.request_history
        self.assertEqual(1, len(history))
示例#2
0
    def test_grants_with_auth_client_credentials(self):
        cfg.CONF.set_override('auth_type', 'OAUTH2_CLIENT_CREDENTIALS',
                              group='authentication')

        self.requests_mock.register_uri('GET',
            self.token_endpoint,
            json={'access_token': 'test_token', 'token_type': 'bearer'},
            headers={'Content-Type': 'application/json'},
            status_code=200)

        auth.auth_manager = auth._AuthManager()

        response_body = self.fake_response_body()
        self.requests_mock.register_uri(
            'POST',
            self.url,
            json=response_body,
            headers=self.headers,
            status_code=201)

        request_body = self.create_request_body()
        res = nfvo_client.GrantRequest.grants(data=request_body)
        self.assertEqual(response_body, json.loads(res.text))
        self.assertEqual(response_body, res.json())

        history = self.requests_mock.request_history
        req_count = _count_mock_history(history, self.nfvo_url, self.oauth_url)
        self.assertEqual(2, req_count)
        self.assert_auth_basic(history[0])
        self.assert_auth_client_credentials(history[1], "test_token")
示例#3
0
 def setUp(self):
     super(TestAuthManager, self).setUp()
     self.url = 'https://oauth2/tokens'
     self.user_name = 'test_user'
     self.password = '******'
     auth.auth_manager = auth._AuthManager()
     self.requests_mock = self.useFixture(requests_mock_fixture.Fixture())
示例#4
0
    def setUp(self):
        super(TestGrantRequest, self).setUp()
        self.requests_mock = self.useFixture(requests_mock_fixture.Fixture())
        self.url = "http://nfvo.co.jp/grant/v1/grants"
        self.nfvo_url = 'http://nfvo.co.jp'
        self.headers = {'content-type': 'application/json'}

        self.token_endpoint = 'https://oauth2/tokens'
        self.nfvo_url = 'http://nfvo.co.jp'
        self.oauth_url = 'https://oauth2'
        self.auth_user_name = 'test_user'
        self.auth_password = '******'

        cfg.CONF.set_override('auth_type', None,
                              group='authentication')
        cfg.CONF.set_override("base_url", self.url, group='connect_grant')
        cfg.CONF.set_override('user_name', self.auth_user_name,
                              group='authentication')
        cfg.CONF.set_override('password', self.auth_password,
                              group='authentication')
        cfg.CONF.set_override('token_endpoint', self.token_endpoint,
                              group='authentication')
        cfg.CONF.set_override('client_id', self.auth_user_name,
                              group='authentication')
        cfg.CONF.set_override('client_password', self.auth_password,
                              group='authentication')
        auth.auth_manager = auth._AuthManager()
        nfvo_client.GrantRequest._connector = nfvo_client._Connect(2, 1, 20)
示例#5
0
    def test_show_with_auth_client_credentials(self):
        cfg.CONF.set_override('auth_type', 'OAUTH2_CLIENT_CREDENTIALS',
                              group='authentication')

        self.requests_mock.register_uri('GET',
            self.token_endpoint,
            json={'access_token': 'test_token', 'token_type': 'bearer'},
            headers={'Content-Type': 'application/json'},
            status_code=200)

        auth.auth_manager = auth._AuthManager()

        response_body = self.json_serial_date_to_dict(
            fakes.VNFPACKAGE_RESPONSE)
        self.requests_mock.register_uri(
            'GET',
            os.path.join(
                self.url,
                uuidsentinel.vnf_pkg_id),
            headers=self.headers,
            json=response_body)

        res = nfvo_client.VnfPackageRequest.show(uuidsentinel.vnf_pkg_id)
        self.assertEqual(200, res.status_code)
        self.assertIsInstance(res.json(), dict)
        self.assertEqual(response_body, res.json())
        self.assertEqual(response_body, json.loads(res.text))

        history = self.requests_mock.request_history
        req_count = _count_mock_history(history, self.nfvo_url, self.oauth_url)
        self.assertEqual(2, req_count)
        self.assert_auth_basic(history[0])
        self.assert_auth_client_credentials(history[1], "test_token")
示例#6
0
    def test_show_with_auth_basic(self):
        cfg.CONF.set_override('auth_type', 'BASIC',
                              group='authentication')
        auth.auth_manager = auth._AuthManager()

        response_body = self.json_serial_date_to_dict(
            fakes.VNFPACKAGE_RESPONSE)
        self.requests_mock.register_uri(
            'GET',
            os.path.join(
                self.url,
                uuidsentinel.vnf_pkg_id),
            headers=self.headers,
            json=response_body)

        res = nfvo_client.VnfPackageRequest.show(uuidsentinel.vnf_pkg_id)
        self.assertEqual(200, res.status_code)
        self.assertIsInstance(res.json(), dict)
        self.assertEqual(response_body, res.json())
        self.assertEqual(response_body, json.loads(res.text))

        history = self.requests_mock.request_history
        req_count = _count_mock_history(history, self.nfvo_url)
        self.assertEqual(1, req_count)
        self.assert_auth_basic(history[0])
示例#7
0
    def test_download_vnf_packages_with_auth_basic(self):
        cfg.CONF.set_override('auth_type', 'BASIC',
                              group='authentication')
        auth.auth_manager = auth._AuthManager()

        expected_connect_cnt = \
            self._download_vnf_packages_all_pipeline_with_assert()
        history = self.requests_mock.request_history
        req_count = _count_mock_history(history, self.nfvo_url)
        self.assertEqual(expected_connect_cnt, req_count)
        for h in history:
            self.assert_auth_basic(h)
示例#8
0
    def test_get_auth_client_basic_with_local(self):
        cfg.CONF.set_override('auth_type', 'BASIC', group='authentication')
        cfg.CONF.set_override('user_name',
                              self.user_name,
                              group='authentication')
        cfg.CONF.set_override('password',
                              self.password,
                              group='authentication')

        auth.auth_manager = auth._AuthManager()
        client = auth.auth_manager.get_auth_client()

        self.assertIsInstance(client, auth._BasicAuthSession)
        self.assertEqual(self.user_name, client.user_name)
        self.assertEqual(self.password, client.password)

        history = self.requests_mock.request_history
        self.assertEqual(0, len(history))
示例#9
0
    def test_download_vnf_packages_with_auth_client_credentials(self):
        cfg.CONF.set_override('auth_type', 'OAUTH2_CLIENT_CREDENTIALS',
                              group='authentication')

        expected_connect_cnt = 1
        self.requests_mock.register_uri('GET',
            self.token_endpoint,
            json={'access_token': 'test_token', 'token_type': 'bearer'},
            headers={'Content-Type': 'application/json'},
            status_code=200)

        auth.auth_manager = auth._AuthManager()

        expected_connect_cnt += \
            self._download_vnf_packages_all_pipeline_with_assert()
        history = self.requests_mock.request_history
        req_count = _count_mock_history(history, self.nfvo_url, self.oauth_url)
        self.assertEqual(expected_connect_cnt, req_count)
        self.assert_auth_basic(history[0])
        for h in history[1:]:
            self.assert_auth_client_credentials(h, "test_token")
示例#10
0
    def test_grants_with_auth_basic(self):
        cfg.CONF.set_override('auth_type', 'BASIC',
                              group='authentication')
        auth.auth_manager = auth._AuthManager()

        response_body = self.fake_response_body()
        self.requests_mock.register_uri(
            'POST',
            self.url,
            json=response_body,
            headers=self.headers,
            status_code=201)

        request_body = self.create_request_body()
        res = nfvo_client.GrantRequest.grants(data=request_body)
        self.assertEqual(response_body, json.loads(res.text))
        self.assertEqual(response_body, res.json())

        history = self.requests_mock.request_history
        req_count = _count_mock_history(history, self.nfvo_url)
        self.assertEqual(1, req_count)
        self.assert_auth_basic(history[0])
示例#11
0
    def setUp(self):
        super(TestVnfPackageRequest, self).setUp()
        self.requests_mock = self.useFixture(requests_mock_fixture.Fixture())
        self.url = "http://nfvo.co.jp/vnfpkgm/v1/vnf_packages"
        self.nfvo_url = "http://nfvo.co.jp"
        self.test_package_dir = 'tacker/tests/unit/vnfm/'
        self.headers = {'Content-Type': 'application/json'}

        self.token_endpoint = 'https://oauth2/tokens'
        self.oauth_url = 'https://oauth2'
        self.auth_user_name = 'test_user'
        self.auth_password = '******'

        cfg.CONF.set_override('auth_type', None,
                              group='authentication')
        cfg.CONF.set_override(
            "base_url",
            self.url,
            group='connect_vnf_packages')
        cfg.CONF.set_default(
            name='pipeline',
            group='connect_vnf_packages',
            default=[
                "package_content",
                "vnfd"])
        cfg.CONF.set_override('user_name', self.auth_user_name,
                              group='authentication')
        cfg.CONF.set_override('password', self.auth_password,
                              group='authentication')
        cfg.CONF.set_override('token_endpoint', self.token_endpoint,
                              group='authentication')
        cfg.CONF.set_override('client_id', self.auth_user_name,
                              group='authentication')
        cfg.CONF.set_override('client_password', self.auth_password,
                              group='authentication')
        auth.auth_manager = auth._AuthManager()
        nfvo_client.VnfPackageRequest._connector = nfvo_client._Connect(
            2, 1, 20)