Esempio n. 1
0
    def test_oauth_authenticate_success(self):
        access_token = uuid.uuid4().hex

        # Just use an existing project scoped token and change
        # the methods to oauth2, and add its section.
        oauth_token = client_fixtures.unscoped_token()

        oauth_token['methods'] = ["oauth2"]
        oauth_token['oauth2'] = {
            "access_token_id": access_token
        }
        self.stub_auth(json=oauth_token)

        a = auth.OAuth2(self.TEST_URL, access_token=access_token)
        s = session.Session(auth=a)
        t = s.get_token()
        self.assertEqual(self.TEST_TOKEN, t)

        OAUTH2_REQUEST_BODY = {
            "auth": {
                "identity": {
                    "methods": ["oauth2"],
                    "oauth2": {
                        "access_token_id": access_token
                    }
                }
            }
        }

        self.assertRequestBodyIs(json=OAUTH2_REQUEST_BODY)
Esempio n. 2
0
    def test_oauth_authenticate_success(self):
        access_token = uuid.uuid4().hex

        # Just use an existing project scoped token and change
        # the methods to oauth2, and add its section.
        oauth_token = client_fixtures.unscoped_token()

        oauth_token['methods'] = ["oauth2"]
        oauth_token['oauth2'] = {"access_token_id": access_token}
        self.stub_auth(json=oauth_token)

        a = auth.OAuth2(self.TEST_URL, access_token=access_token)
        s = session.Session(auth=a)
        t = s.get_token()
        self.assertEqual(self.TEST_TOKEN, t)

        OAUTH2_REQUEST_BODY = {
            "auth": {
                "identity": {
                    "methods": ["oauth2"],
                    "oauth2": {
                        "access_token_id": access_token
                    }
                }
            }
        }

        self.assertRequestBodyIs(json=OAUTH2_REQUEST_BODY)
    def test_unscoped_init(self):
        self.stub_auth(json=client_fixtures.unscoped_token())

        c = client.Client(user_domain_name='exampledomain',
                          username='******',
                          password='******',
                          auth_url=self.TEST_URL)
        self.assertIsNotNone(c.auth_ref)
        self.assertFalse(c.auth_ref.domain_scoped)
        self.assertFalse(c.auth_ref.project_scoped)
        self.assertEqual(c.auth_user_id, 'c4da488862bd435c9e6c0275a0d0e49a')
        self.assertFalse(c.has_service_catalog())

        self.assertEqual('c4da488862bd435c9e6c0275a0d0e49a',
                         c.get_user_id(session=None))
        self.assertIsNone(c.get_project_id(session=None))
    def test_unscoped_init(self):
        self.stub_auth(json=client_fixtures.unscoped_token())

        c = client.Client(user_domain_name='exampledomain',
                          username='******',
                          password='******',
                          auth_url=self.TEST_URL)
        self.assertIsNotNone(c.auth_ref)
        self.assertFalse(c.auth_ref.domain_scoped)
        self.assertFalse(c.auth_ref.project_scoped)
        self.assertEqual(c.auth_user_id,
                         'c4da488862bd435c9e6c0275a0d0e49a')
        self.assertFalse(c.has_service_catalog())

        self.assertEqual('c4da488862bd435c9e6c0275a0d0e49a',
                         c.get_user_id(session=None))
        self.assertIsNone(c.get_project_id(session=None))
    def test_two_factor_device_authenticate_success(self):
        password = uuid.uuid4().hex
        user_id = uuid.uuid4().hex

        device_id = uuid.uuid4().hex
        device_token = uuid.uuid4().hex

        # Just use an existing project scoped token and change
        # the methods to password, and add its section.
        token = client_fixtures.unscoped_token()

        token['methods'] = ["password"]
        token['password'] = {
            "device_data": { "device_id": device_id, 
                             "device_token": device_token},
            'password': password
        }
        self.stub_auth(json=token)

        a = auth.TwoFactor(
            self.TEST_URL,
            device_data={ "device_id": device_id, 
                          "device_token": device_token},
            password=password,
            user_id=user_id)
        s = session.Session(auth=a)
        t = s.get_token()
        self.assertEqual(self.TEST_TOKEN, t)

        TWO_FACTOR_REQUEST_BODY = {
            "auth": {
                "identity": {
                    "methods": ["password"],
                    "password": {
                        'user': {
                            "device_data": { "device_id": device_id, 
                                             "device_token": device_token},
                            'password': password,
                            'id': user_id
                        }
                    }
                }
            }
        }

        self.assertRequestBodyIs(json=TWO_FACTOR_REQUEST_BODY)
Esempio n. 6
0
    def test_unscoped_init(self):
        token = client_fixtures.unscoped_token()
        self.stub_auth(json=token)

        # Creating a HTTPClient not using session is deprecated.
        with self.deprecations.expect_deprecations_here():
            c = client.Client(user_domain_name=token.user_domain_name,
                              username=token.user_name,
                              password='******',
                              auth_url=self.TEST_URL)
        self.assertIsNotNone(c.auth_ref)
        self.assertFalse(c.auth_ref.domain_scoped)
        self.assertFalse(c.auth_ref.project_scoped)
        self.assertEqual(token.user_id, c.auth_user_id)
        self.assertFalse(c.has_service_catalog())

        self.assertEqual(token.user_id, c.get_user_id(session=None))
        self.assertIsNone(c.get_project_id(session=None))
    def test_unscoped_init(self):
        token = client_fixtures.unscoped_token()
        self.stub_auth(json=token)

        # Creating a HTTPClient not using session is deprecated.
        with self.deprecations.expect_deprecations_here():
            c = client.Client(user_domain_name=token.user_domain_name,
                              username=token.user_name,
                              password='******',
                              auth_url=self.TEST_URL)
        self.assertIsNotNone(c.auth_ref)
        self.assertFalse(c.auth_ref.domain_scoped)
        self.assertFalse(c.auth_ref.project_scoped)
        self.assertEqual(token.user_id, c.auth_user_id)
        self.assertFalse(c.has_service_catalog())

        self.assertEqual(token.user_id, c.get_user_id(session=None))
        self.assertIsNone(c.get_project_id(session=None))
import datetime
import uuid

from oslo_utils import timeutils

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


TOKEN_RESPONSE = utils.TestResponse({
    "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(auth_ref.auth_token,
                         '3e2813b7ba0b4006840c3825860b86ed')
Esempio n. 9
0
#    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.v3 import client_fixtures
from keystoneclient.tests.unit.v3 import utils

TOKEN_RESPONSE = utils.TestResponse(
    {"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(auth_ref.auth_token,
                         '3e2813b7ba0b4006840c3825860b86ed')