Exemple #1
0
    def test_requests_auth_plugin(self):
        sess = client_session.Session()

        requests_auth = object()

        FAKE_RESP = utils.test_response(text='resp')
        RESP = mock.Mock(return_value=FAKE_RESP)

        with mock.patch.object(sess.session, 'request', RESP) as mocked:
            sess.get(self.TEST_URL, requests_auth=requests_auth)

            mocked.assert_called_once_with('GET', self.TEST_URL,
                                           headers=mock.ANY,
                                           allow_redirects=mock.ANY,
                                           auth=requests_auth,
                                           verify=mock.ANY)
    def test_requests_auth_plugin(self):
        sess = client_session.Session()

        requests_auth = object()

        FAKE_RESP = utils.test_response(text='resp')
        RESP = mock.Mock(return_value=FAKE_RESP)

        with mock.patch.object(sess.session, 'request', RESP) as mocked:
            sess.get(self.TEST_URL, requests_auth=requests_auth)

            mocked.assert_called_once_with('GET', self.TEST_URL,
                                           headers=mock.ANY,
                                           allow_redirects=mock.ANY,
                                           auth=requests_auth,
                                           verify=mock.ANY)
Exemple #3
0
    def setUp(self):
        super(ServiceCatalogTest, self).setUp()
        self.AUTH_RESPONSE_BODY = client_fixtures.auth_response_body()
        self.RESPONSE = test_utils.test_response(
            headers=client_fixtures.AUTH_RESPONSE_HEADERS)

        self.north_endpoints = {
            'public': 'http://glance.north.host/glanceapi/public',
            'internal': 'http://glance.north.host/glanceapi/internal',
            'admin': 'http://glance.north.host/glanceapi/admin'
        }

        self.south_endpoints = {
            'public': 'http://glance.south.host/glanceapi/public',
            'internal': 'http://glance.south.host/glanceapi/internal',
            'admin': 'http://glance.south.host/glanceapi/admin'
        }
Exemple #4
0
    def test_http_session_opts(self):
        session = client_session.Session(cert='cert.pem', timeout=5,
                                         verify='certs')

        FAKE_RESP = utils.test_response(text='resp')
        RESP = mock.Mock(return_value=FAKE_RESP)

        with mock.patch.object(session.session, 'request', RESP) as mocked:
            session.post(self.TEST_URL, data='value')

            mock_args, mock_kwargs = mocked.call_args

            self.assertEqual(mock_args[0], 'POST')
            self.assertEqual(mock_args[1], self.TEST_URL)
            self.assertEqual(mock_kwargs['data'], 'value')
            self.assertEqual(mock_kwargs['cert'], 'cert.pem')
            self.assertEqual(mock_kwargs['verify'], 'certs')
            self.assertEqual(mock_kwargs['timeout'], 5)
    def test_http_session_opts(self):
        session = client_session.Session(cert='cert.pem', timeout=5,
                                         verify='certs')

        FAKE_RESP = utils.test_response(text='resp')
        RESP = mock.Mock(return_value=FAKE_RESP)

        with mock.patch.object(session.session, 'request', RESP) as mocked:
            session.post(self.TEST_URL, data='value')

            mock_args, mock_kwargs = mocked.call_args

            self.assertEqual(mock_args[0], 'POST')
            self.assertEqual(mock_args[1], self.TEST_URL)
            self.assertEqual(mock_kwargs['data'], 'value')
            self.assertEqual(mock_kwargs['cert'], 'cert.pem')
            self.assertEqual(mock_kwargs['verify'], 'certs')
            self.assertEqual(mock_kwargs['timeout'], 5)
    def test_setting_connection_params(self):
        text = uuid.uuid4().hex

        with mock.patch.object(self.session.session, 'request') as mocked:
            mocked.return_value = utils.test_response(text=text)
            resp = self.session.get('prefix',
                                    endpoint_filter=self.ENDPOINT_FILTER)

            self.assertEqual(text, resp.text)

            # the cert and verify values passed to request are those that were
            # returned from the auth plugin as connection params.

            mocked.assert_called_once_with('GET',
                                           self.auth.url('prefix'),
                                           headers=mock.ANY,
                                           allow_redirects=False,
                                           cert=self.auth.cert,
                                           verify=False)
    def test_setting_connection_params(self):
        text = uuid.uuid4().hex

        with mock.patch.object(self.session.session, 'request') as mocked:
            mocked.return_value = utils.test_response(text=text)
            resp = self.session.get('prefix',
                                    endpoint_filter=self.ENDPOINT_FILTER)

            self.assertEqual(text, resp.text)

            # the cert and verify values passed to request are those that were
            # returned from the auth plugin as connection params.

            mocked.assert_called_once_with('GET',
                                           self.auth.url('prefix'),
                                           headers=mock.ANY,
                                           allow_redirects=False,
                                           cert=self.auth.cert,
                                           verify=False)
    def setUp(self):
        super(ServiceCatalogTest, self).setUp()
        self.AUTH_RESPONSE_BODY = client_fixtures.auth_response_body()
        self.RESPONSE = test_utils.test_response(
            headers=client_fixtures.AUTH_RESPONSE_HEADERS
        )

        self.north_endpoints = {'public':
                                'http://glance.north.host/glanceapi/public',
                                'internal':
                                'http://glance.north.host/glanceapi/internal',
                                'admin':
                                'http://glance.north.host/glanceapi/admin'}

        self.south_endpoints = {'public':
                                'http://glance.south.host/glanceapi/public',
                                'internal':
                                'http://glance.south.host/glanceapi/internal',
                                'admin':
                                'http://glance.south.host/glanceapi/admin'}
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import datetime
import uuid

from oslo_utils import timeutils

from keystoneclient import access
from keystoneclient import fixture
from keystoneclient.tests.unit import utils as test_utils
from keystoneclient.tests.unit.v3 import client_fixtures
from keystoneclient.tests.unit.v3 import utils

TOKEN_RESPONSE = test_utils.test_response(
    headers=client_fixtures.AUTH_RESPONSE_HEADERS)
UNSCOPED_TOKEN = client_fixtures.unscoped_token()
DOMAIN_SCOPED_TOKEN = client_fixtures.domain_scoped_token()
PROJECT_SCOPED_TOKEN = client_fixtures.project_scoped_token()


class AccessInfoTest(utils.TestCase):
    def test_building_unscoped_accessinfo(self):
        auth_ref = access.AccessInfo.factory(resp=TOKEN_RESPONSE,
                                             body=UNSCOPED_TOKEN)

        self.assertTrue(auth_ref)
        self.assertIn('methods', auth_ref)
        self.assertNotIn('catalog', auth_ref)

        self.assertEqual(client_fixtures.AUTH_SUBJECT_TOKEN,
Exemple #10
0
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import mock
import requests

from keystoneclient import httpclient
from keystoneclient.tests.unit import utils

FAKE_RESPONSE = utils.test_response(json={'hi': 'there'})

REQUEST_URL = 'https://127.0.0.1:5000/hi'
RESPONSE_BODY = '{"hi": "there"}'


def get_client():
    cl = httpclient.HTTPClient(username="******",
                               password="******",
                               project_id="tenant",
                               auth_url="auth_test",
                               cacert="ca.pem",
                               cert=('cert.pem', "key.pem"))
    return cl

#    License for the specific language governing permissions and limitations
#    under the License.

import datetime
import uuid

from keystoneauth1 import fixture
from oslo_utils import timeutils

from keystoneclient import access
from keystoneclient.tests.unit import utils as test_utils
from keystoneclient.tests.unit.v3 import client_fixtures
from keystoneclient.tests.unit.v3 import utils


TOKEN_RESPONSE = test_utils.test_response(headers=client_fixtures.AUTH_RESPONSE_HEADERS)
UNSCOPED_TOKEN = client_fixtures.unscoped_token()
DOMAIN_SCOPED_TOKEN = client_fixtures.domain_scoped_token()
PROJECT_SCOPED_TOKEN = client_fixtures.project_scoped_token()


class AccessInfoTest(utils.TestCase):
    def test_building_unscoped_accessinfo(self):
        auth_ref = access.AccessInfo.factory(resp=TOKEN_RESPONSE, body=UNSCOPED_TOKEN)

        self.assertTrue(auth_ref)
        self.assertIn("methods", auth_ref)
        self.assertNotIn("catalog", auth_ref)

        self.assertEqual(client_fixtures.AUTH_SUBJECT_TOKEN, auth_ref.auth_token)
        self.assertEqual(UNSCOPED_TOKEN.user_name, auth_ref.username)
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import mock
import requests

from keystoneclient import httpclient
from keystoneclient.tests.unit import utils


FAKE_RESPONSE = utils.test_response(json={'hi': 'there'})

REQUEST_URL = 'https://127.0.0.1:5000/hi'
RESPONSE_BODY = '{"hi": "there"}'


def get_client():
    cl = httpclient.HTTPClient(username="******", password="******",
                               project_id="tenant", auth_url="auth_test",
                               cacert="ca.pem", cert=('cert.pem', "key.pem"))
    return cl


def get_authed_client():
    cl = get_client()
    cl.management_url = "https://127.0.0.1:5000"