Esempio n. 1
0
    def __get_auth_data(self, dtoken):
        """return AuthData object for a token"""
        tenant = None
        endpoints = None

        if dtoken.tenant_id:
            dtenant = api.TENANT.get(dtoken.tenant_id)
            tenant = auth.Tenant(id=dtenant.id, name=dtenant.name)

            endpoints = api.TENANT.get_all_endpoints(dtoken.tenant_id)

        token = auth.Token(dtoken.expires, dtoken.id, tenant)

        duser = api.USER.get(dtoken.user_id)

        ts = []
        if dtoken.tenant_id:
            drole_refs = api.ROLE.ref_get_all_tenant_roles(
                duser.id, dtoken.tenant_id)
            for drole_ref in drole_refs:
                drole = api.ROLE.get(drole_ref.role_id)
                ts.append(
                    UserRole(drole_ref.role_id, drole.name,
                             drole_ref.tenant_id))
        drole_refs = api.ROLE.ref_get_all_global_roles(duser.id)
        for drole_ref in drole_refs:
            drole = api.ROLE.get(drole_ref.role_id)
            ts.append(
                UserRole(drole_ref.role_id, drole.name, drole_ref.tenant_id))

        user = auth.User(duser.id, duser.name, None, None, UserRoles(ts, []))

        return auth.AuthData(token, user, endpoints)
Esempio n. 2
0
 def test_AuthData_json_serialization(self):
     auth = logic_auth.AuthData(self.token, self.user)
     data = json.loads(auth.to_json())
     expected = {
         'access': {
             'token': {
                 'expires': '2000-01-31',
                 'tenants': [{
                     'id': 'ten8',
                     'name': 'The Tenant'
                 }],
                 'id': 'abc123T',
                 'tenant': {
                     'id': 'ten8',
                     'name': 'The Tenant'
                 }
             },
             'user': {
                 'id': 'u1',
                 'roles': [{
                     'name': 'Admin',
                     'id': '1'
                 }],
                 'name': 'john'
             }
         }
     }
     self.assertDictEqual(data, expected)
Esempio n. 3
0
 def test_AuthData_xml_catalog(self):
     auth = logic_auth.AuthData(self.token, self.user, self.base_urls)
     xml_str = auth.to_xml()
     dom = etree.fromstring(xml_str)
     xmlns = "http://docs.openstack.org/identity/api/v2.0"
     catalog = dom.find("{%s}serviceCatalog" % xmlns)
     service = catalog.find("{%s}service" % xmlns)
     endpoint = service.find("{%s}endpoint" % xmlns)
     self.assertIsNotNone("publicURL", endpoint.attrib)
     self.assertIn("versionId", endpoint.attrib)
     self.assertIn("tenantId", endpoint.attrib)
Esempio n. 4
0
 def test_AuthData_xml_serialization(self):
     auth = logic_auth.AuthData(self.token, self.user)
     xml_str = auth.to_xml()
     expected = (
         '<access xmlns='
         '"http://docs.openstack.org/identity/api/v2.0"><token expires='
         '"2000-01-31" id="abc123T"><tenant name="The Tenant" '
         'id="ten8"/></token><user name="john" id="u1"><roles '
         'xmlns="http://docs.openstack.org/identity/api/v2.0"><role '
         'xmlns="http://docs.openstack.org/identity/api/v2.0" id="1" '
         'name="Admin"/></roles></user></access>')
     self.assertTrue(test_utils.XMLTools.xmlEqual(xml_str, expected))
Esempio n. 5
0
    def get_endpoints_for_token(self, admin_token, token_id):
        self.__validate_admin_token(admin_token)

        dtoken = api.TOKEN.get(token_id)
        if not dtoken:
            raise fault.ItemNotFoundFault("Token not found")

        endpoints = api.TENANT.get_all_endpoints(dtoken.tenant_id)

        # For now it's easier to resend the token data as well.
        # Who knows, might be useful and the client can reuse their
        # auth parsing code.
        token = auth.Token(dtoken.expires, dtoken.id, dtoken.tenant_id)
        return auth.AuthData(token, endpoints)
Esempio n. 6
0
    def test_AuthData_json_catalog(self):
        auth = logic_auth.AuthData(self.token, self.user, self.base_urls)
        data = json.loads(auth.to_json())
        self.assertIn("access", data)
        self.assertIn("serviceCatalog", data['access'])
        catalog = data['access']['serviceCatalog']
        self.assertTrue(len(catalog) > 0)
        endpoints = catalog[0]['endpoints']
        self.assertTrue(len(endpoints) > 1)
        endpoint = endpoints[0]
        self.assertIn("publicURL", endpoint)
        self.assertIn("versionId", endpoint)
        self.assertIn("tenantId", endpoint)

        endpoint = endpoints[1]
        self.assertNotIn("versionId", endpoint)