Exemplo n.º 1
0
    def test_authorize_multi_method(self):
        methods = [
            v3.PasswordMethod(username=common.TEST_USER,
                              password=common.TEST_PASS),
            v3.TokenMethod(token=common.TEST_TOKEN)
        ]
        sot = v3.Auth(TEST_URL, methods)
        xport = self.create_mock_transport(common.TEST_RESPONSE_DICT_V3)

        resp = sot.authorize(xport)

        eurl = TEST_URL + '/auth/tokens'
        eheaders = {
            'Accept': 'application/json',
            'X-Auth-Token': common.TEST_TOKEN
        }
        up = {'password': common.TEST_PASS, 'name': common.TEST_USER}
        ejson = {
            'auth': {
                'identity': {
                    'token': {
                        'id': common.TEST_TOKEN
                    },
                    'password': {
                        'user': up
                    },
                    'methods': ['password', 'token']
                }
            }
        }
        xport.post.assert_called_with(eurl, headers=eheaders, json=ejson)
        ecatalog = common.TEST_RESPONSE_DICT_V3['token'].copy()
        ecatalog['auth_token'] = common.TEST_SUBJECT
        ecatalog['version'] = 'v3'
        self.assertEqual(ecatalog, resp._info)
Exemplo n.º 2
0
    def test_password_domain(self):
        kargs = {'domain_id': common.TEST_DOMAIN_ID,
                 'domain_name': common.TEST_DOMAIN_NAME,
                 'trust_id': common.TEST_TRUST_ID,
                 'project_id': common.TEST_PROJECT_ID,
                 'project_name': common.TEST_PROJECT_NAME}

        methods = [v3.PasswordMethod(username=common.TEST_USER,
                                     user_id=common.TEST_USER_ID,
                                     password=common.TEST_PASS)]
        sot = v3.Auth(TEST_URL, methods, **kargs)

        self.assertEqual(1, len(sot.auth_methods))
        auther = sot.auth_methods[0]
        self.assertEqual(common.TEST_USER_ID, auther.user_id)
        self.assertEqual(common.TEST_USER, auther.username)
        self.assertEqual(None, auther.user_domain_id)
        self.assertEqual(None, auther.user_domain_name)
        self.assertEqual(common.TEST_PASS, auther.password)
        expected = ('password', {'user': {'id': common.TEST_USER_ID,
                                          'password': common.TEST_PASS}})
        self.assertEqual(expected, auther.get_auth_data(None, None, {}))
        self.assertEqual(common.TEST_TRUST_ID, sot.trust_id)
        self.assertEqual(common.TEST_DOMAIN_ID, sot.domain_id)
        self.assertEqual(common.TEST_DOMAIN_NAME, sot.domain_name)
        self.assertEqual(common.TEST_PROJECT_ID, sot.project_id)
        self.assertEqual(common.TEST_PROJECT_NAME, sot.project_name)
        self.assertEqual(None, sot.project_domain_id)
        self.assertEqual(None, sot.project_domain_name)
        self.assertEqual(TEST_URL + '/auth/tokens', sot.token_url)