def federated_authenticate(self, request, external_auth_service, region):
     federated_keystone_url = get_federated_keystone_url()
     realm = get_realm(external_auth_service)
     print "=======realm=======", realm
     tenant_name = get_tenant_name(realm)
     print "=======tenant_name=======", tenant_name
     scoped_token_dict = federatedAuthentication(federated_keystone_url, realm, tenant_name)
     print "========scoped_token_dict======", scoped_token_dict
     user = create_user_from_token(
         request,
         Token(AccessInfo.factory(resp=None, body=scoped_token_dict)),
         federated_keystone_url, region)
     user.backend = "%s.%s" % (self.__module__, self.__class__.__name__)
     return user
Ejemplo n.º 2
0
def generate_test_data():
    ''' Builds a set of test_data data as returned by Keystone V2. '''
    test_data = TestDataContainer()

    keystone_service = {
        'type':
        'identity',
        'name':
        'keystone',
        'endpoints_links': [],
        'endpoints': [{
            'region': 'RegionOne',
            'adminURL': 'http://admin.localhost:35357/v2.0',
            'internalURL': 'http://internal.localhost:5000/v2.0',
            'publicURL': 'http://public.localhost:5000/v2.0'
        }]
    }

    # Users
    user_dict = {
        'id': uuid.uuid4().hex,
        'name': 'gabriel',
        'email': '*****@*****.**',
        'password': '******',
        'token': '',
        'enabled': True
    }
    test_data.user = User(UserManager(None), user_dict, loaded=True)

    # Tenants
    tenant_dict_1 = {
        'id': uuid.uuid4().hex,
        'name': 'tenant_one',
        'description': '',
        'enabled': True
    }
    tenant_dict_2 = {
        'id': uuid.uuid4().hex,
        'name': '',
        'description': '',
        'enabled': False
    }
    test_data.tenant_one = Tenant(TenantManager(None),
                                  tenant_dict_1,
                                  loaded=True)
    test_data.tenant_two = Tenant(TenantManager(None),
                                  tenant_dict_2,
                                  loaded=True)

    nova_service = {
        'type': 'compute',
        'name': 'nova',
        'endpoint_links': [],
        'endpoints': [
            {
                'region': 'RegionOne',
                'adminURL': 'http://nova-admin.localhost:8774/v2.0/%s' \
                            % (tenant_dict_1['id']),
                'internalURL': 'http://nova-internal.localhost:8774/v2.0/%s' \
                               % (tenant_dict_1['id']),
                'publicURL': 'http://nova-public.localhost:8774/v2.0/%s' \
                             % (tenant_dict_1['id'])
            },
            {
                'region': 'RegionTwo',
                'adminURL': 'http://nova2-admin.localhost:8774/v2.0/%s' \
                            % (tenant_dict_1['id']),
                'internalURL': 'http://nova2-internal.localhost:8774/v2.0/%s' \
                               % (tenant_dict_1['id']),
                'publicURL': 'http://nova2-public.localhost:8774/v2.0/%s' \
                             % (tenant_dict_1['id'])
            }
        ]
    }

    # Roles
    role_dict = {'id': uuid.uuid4().hex, 'name': 'Member'}
    test_data.role = Role(RoleManager, role_dict)

    # Tokens
    tomorrow = datetime_safe.datetime.now() + timedelta(days=1)
    expiration = datetime_safe.datetime.isoformat(tomorrow)

    scoped_token_dict = {
        'access': {
            'token': {
                'id': uuid.uuid4().hex,
                'expires': expiration,
                'tenant': tenant_dict_1,
                'tenants': [tenant_dict_1, tenant_dict_2]
            },
            'user': {
                'id': user_dict['id'],
                'name': user_dict['name'],
                'roles': [role_dict]
            },
            'serviceCatalog': [keystone_service, nova_service]
        }
    }

    test_data.scoped_access_info = AccessInfo.factory(resp=None,
                                                      body=scoped_token_dict)

    unscoped_token_dict = {
        'access': {
            'token': {
                'id': uuid.uuid4().hex,
                'expires': expiration
            },
            'user': {
                'id': user_dict['id'],
                'name': user_dict['name'],
                'roles': [role_dict]
            },
            'serviceCatalog': [keystone_service]
        }
    }
    test_data.unscoped_access_info = AccessInfo.factory(
        resp=None, body=unscoped_token_dict)

    # Service Catalog
    test_data.service_catalog = ServiceCatalog.factory({
        'serviceCatalog': [keystone_service, nova_service],
        'token': {
            'id': scoped_token_dict['access']['token']['id'],
            'expires': scoped_token_dict['access']['token']['expires'],
            'user_id': user_dict['id'],
            'tenant_id': tenant_dict_1['id']
        }
    })

    return test_data
Ejemplo n.º 3
0
def data(TEST):
    TEST.service_catalog = SERVICE_CATALOG
    TEST.tokens = TestDataContainer()
    TEST.domains = TestDataContainer()
    TEST.users = TestDataContainer()
    TEST.groups = TestDataContainer()
    TEST.tenants = TestDataContainer()
    TEST.roles = TestDataContainer()
    TEST.ec2 = TestDataContainer()

    admin_role_dict = {'id': '1', 'name': 'admin'}
    admin_role = roles.Role(roles.RoleManager, admin_role_dict)
    member_role_dict = {
        'id': "2",
        'name': settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE
    }
    member_role = roles.Role(roles.RoleManager, member_role_dict)
    TEST.roles.add(admin_role, member_role)
    TEST.roles.admin = admin_role
    TEST.roles.member = member_role

    domain_dict = {
        'id': "1",
        'name': 'test_domain',
        'description': "a test domain.",
        'enabled': True
    }
    domain_dict_2 = {
        'id': "2",
        'name': 'disabled_domain',
        'description': "a disabled test domain.",
        'enabled': False
    }
    domain = domains.Domain(domains.DomainManager, domain_dict)
    disabled_domain = domains.Domain(domains.DomainManager, domain_dict_2)
    TEST.domains.add(domain, disabled_domain)
    TEST.domain = domain  # Your "current" domain

    user_dict = {
        'id': "1",
        'name': 'test_user',
        'email': '*****@*****.**',
        'password': '******',
        'token': 'test_token',
        'project_id': '1',
        'enabled': True,
        'domain_id': "1"
    }
    user = users.User(users.UserManager(None), user_dict)
    user_dict = {
        'id': "2",
        'name': 'user_two',
        'email': '*****@*****.**',
        'password': '******',
        'token': 'test_token',
        'project_id': '1',
        'enabled': True,
        'domain_id': "1"
    }
    user2 = users.User(users.UserManager(None), user_dict)
    user_dict = {
        'id': "3",
        'name': 'user_three',
        'email': '*****@*****.**',
        'password': '******',
        'token': 'test_token',
        'project_id': '1',
        'enabled': True,
        'domain_id': "1"
    }
    user3 = users.User(users.UserManager(None), user_dict)
    user_dict = {
        'id': "4",
        'name': 'user_four',
        'email': '*****@*****.**',
        'password': '******',
        'token': 'test_token',
        'project_id': '2',
        'enabled': True,
        'domain_id': "2"
    }
    user4 = users.User(users.UserManager(None), user_dict)
    TEST.users.add(user, user2, user3, user4)
    TEST.user = user  # Your "current" user
    TEST.user.service_catalog = SERVICE_CATALOG

    group_dict = {
        'id': "1",
        'name': 'group_one',
        'description': 'group one description',
        'domain_id': '1'
    }
    group = groups.Group(groups.GroupManager(None), group_dict)
    group_dict = {
        'id': "2",
        'name': 'group_two',
        'description': 'group two description',
        'domain_id': '1'
    }
    group2 = groups.Group(groups.GroupManager(None), group_dict)
    group_dict = {
        'id': "3",
        'name': 'group_three',
        'description': 'group three description',
        'domain_id': '2'
    }
    group3 = groups.Group(groups.GroupManager(None), group_dict)
    TEST.groups.add(group, group2, group3)

    tenant_dict = {
        'id': "1",
        'name': 'test_tenant',
        'description': "a test tenant.",
        'enabled': True,
        'domain_id': '1'
    }
    tenant_dict_2 = {
        'id': "2",
        'name': 'disabled_tenant',
        'description': "a disabled test tenant.",
        'enabled': False,
        'domain_id': '2'
    }
    tenant_dict_3 = {
        'id': "3",
        'name': u'\u4e91\u89c4\u5219',
        'description': "an unicode-named tenant.",
        'enabled': True,
        'domain_id': '2'
    }
    tenant = tenants.Tenant(tenants.TenantManager, tenant_dict)
    disabled_tenant = tenants.Tenant(tenants.TenantManager, tenant_dict_2)
    tenant_unicode = tenants.Tenant(tenants.TenantManager, tenant_dict_3)

    TEST.tenants.add(tenant, disabled_tenant, tenant_unicode)
    TEST.tenant = tenant  # Your "current" tenant

    tomorrow = datetime_safe.datetime.now() + timedelta(days=1)
    expiration = datetime_safe.datetime.isoformat(tomorrow)

    scoped_token_dict = {
        'access': {
            'token': {
                'id': "test_token_id",
                'expires': expiration,
                'tenant': tenant_dict,
                'tenants': [tenant_dict]
            },
            'user': {
                'id': "test_user_id",
                'name': "test_user",
                'roles': [member_role_dict]
            },
            'serviceCatalog': TEST.service_catalog
        }
    }

    scoped_access_info = AccessInfo.factory(resp=None, body=scoped_token_dict)

    unscoped_token_dict = {
        'access': {
            'token': {
                'id': "test_token_id",
                'expires': expiration
            },
            'user': {
                'id': "test_user_id",
                'name': "test_user",
                'roles': [member_role_dict]
            },
            'serviceCatalog': TEST.service_catalog
        }
    }
    unscoped_access_info = AccessInfo.factory(resp=None,
                                              body=unscoped_token_dict)

    scoped_token = Token(scoped_access_info)
    unscoped_token = Token(unscoped_access_info)
    TEST.tokens.add(scoped_token, unscoped_token)
    TEST.token = scoped_token  # your "current" token.
    TEST.tokens.scoped_token = scoped_token
    TEST.tokens.unscoped_token = unscoped_token

    access_secret = ec2.EC2(ec2.CredentialsManager, {
        "access": "access",
        "secret": "secret"
    })
    TEST.ec2.add(access_secret)
Ejemplo n.º 4
0
def generate_test_data():
    ''' Builds a set of test_data data as returned by Keystone V2. '''
    test_data = TestDataContainer()

    keystone_service = {
        'type': 'identity',
        'id': uuid.uuid4().hex,
        'endpoints': [
            {
                'url': 'http://admin.localhost:35357/v3',
                'region': 'RegionOne',
                'interface': 'admin',
                'id': uuid.uuid4().hex,
            },
            {
                'url': 'http://internal.localhost:5000/v3',
                'region': 'RegionOne',
                'interface': 'internal',
                'id': uuid.uuid4().hex
            },
            {
                'url':'http://public.localhost:5000/v3',
                'region':'RegionOne',
                'interface': 'public',
                 'id': uuid.uuid4().hex
            }
        ]
    }

    # Domains
    domain_dict = {'id': uuid.uuid4().hex,
                   'name': 'domain',
                   'description': '',
                   'enabled': True}
    test_data.domain = Domain(DomainManager(None), domain_dict, loaded=True)

    # Users
    user_dict = {'id': uuid.uuid4().hex,
                 'name': 'gabriel',
                 'email': '*****@*****.**',
                 'password': '******',
                 'domain_id': domain_dict['id'],
                 'token': '',
                 'enabled': True}
    test_data.user = User(UserManager(None), user_dict, loaded=True)

    # Projects
    project_dict_1 = {'id': uuid.uuid4().hex,
                     'name': 'tenant_one',
                     'description': '',
                     'domain_id': domain_dict['id'],
                     'enabled': True}
    project_dict_2 = {'id': uuid.uuid4().hex,
                     'name': '',
                     'description': '',
                     'domain_id': domain_dict['id'],
                     'enabled': False}
    test_data.project_one = Project(ProjectManager(None),
                                  project_dict_1,
                                  loaded=True)
    test_data.project_two = Project(ProjectManager(None),
                                  project_dict_2,
                                  loaded=True)

    # Roles
    role_dict = {'id': uuid.uuid4().hex,
                 'name': 'Member'}
    test_data.role = Role(RoleManager, role_dict)

    nova_service = {
        'type': 'compute',
        'id': uuid.uuid4().hex,
        'endpoints': [
            {
                'url': 'http://nova-admin.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region': 'RegionOne',
                'interface': 'admin',
                'id': uuid.uuid4().hex,
            },
            {
                'url': 'http://nova-internal.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region': 'RegionOne',
                'interface': 'internal',
                'id': uuid.uuid4().hex
            },
            {
                'url':'http://nova-public.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region':'RegionOne',
                'interface': 'public',
                 'id': uuid.uuid4().hex
            },
            {
                'url': 'http://nova2-admin.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region': 'RegionTwo',
                'interface': 'admin',
                'id': uuid.uuid4().hex,
            },
            {
                'url': 'http://nova2-internal.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region': 'RegionTwo',
                'interface': 'internal',
                'id': uuid.uuid4().hex
            },
            {
                'url':'http://nova2-public.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region':'RegionTwo',
                'interface': 'public',
                 'id': uuid.uuid4().hex
            }
        ]
    }

    # Tokens
    tomorrow = datetime_safe.datetime.now() + timedelta(days=1)
    expiration = datetime_safe.datetime.isoformat(tomorrow)
    auth_token = uuid.uuid4().hex
    auth_response_headers = {
        'X-Subject-Token': auth_token
    }

    auth_response = TestResponse({
        "headers": auth_response_headers
    })

    scoped_token_dict = {
        'token': {
            'methods': ['password'],
            'expires_at': expiration,
            'project': {
                'id': project_dict_1['id'],
                'name': project_dict_1['name'],
                'domain': {
                    'id': domain_dict['id'],
                    'name': domain_dict['name']
                }
            },
            'user': {
                'id': user_dict['id'],
                'name': user_dict['name'],
                'domain': {
                    'id': domain_dict['id'],
                    'name': domain_dict['name']
                }
            },
            'roles': [role_dict],
            'catalog': [keystone_service, nova_service]
        }
    }

    test_data.scoped_access_info = AccessInfo.factory(
        resp=auth_response,
        body=scoped_token_dict
    )

    unscoped_token_dict = {
        'token': {
            'methods': ['password'],
            'expires_at': expiration,
            'user': {
                'id': user_dict['id'],
                'name': user_dict['name'],
                'domain': {
                    'id': domain_dict['id'],
                    'name': domain_dict['name']
                }
            },
            'roles': [role_dict],
            'catalog': [keystone_service]
        }
    }

    test_data.unscoped_access_info = AccessInfo.factory(
        resp=auth_response,
        body=unscoped_token_dict
    )

    # Service Catalog
    test_data.service_catalog = ServiceCatalog.factory({
        'methods': ['password'],
        'user': {},
        'catalog': [keystone_service, nova_service],
    }, token=auth_token)

    return test_data
Ejemplo n.º 5
0
def generate_test_data():
    ''' Builds a set of test_data data as returned by Keystone V2. '''
    test_data = TestDataContainer()

    keystone_service = {
        'type': 'identity',
        'name': 'keystone',
        'endpoints_links': [],
        'endpoints': [
            {
                'region': 'RegionOne',
                'adminURL': 'http://admin.localhost:35357/v2.0',
                'internalURL': 'http://internal.localhost:5000/v2.0',
                'publicURL': 'http://public.localhost:5000/v2.0'
            }
        ]
    }

    # Users
    user_dict = {'id': uuid.uuid4().hex,
                 'name': 'gabriel',
                 'email': '*****@*****.**',
                 'password': '******',
                 'token': '',
                 'enabled': True}
    test_data.user = User(UserManager(None), user_dict, loaded=True)

    # Tenants
    tenant_dict_1 = {'id': uuid.uuid4().hex,
                     'name': 'tenant_one',
                     'description': '',
                     'enabled': True}
    tenant_dict_2 = {'id': uuid.uuid4().hex,
                     'name': '',
                     'description': '',
                     'enabled': False}
    test_data.tenant_one = Tenant(TenantManager(None),
                                  tenant_dict_1,
                                  loaded=True)
    test_data.tenant_two = Tenant(TenantManager(None),
                                  tenant_dict_2,
                                  loaded=True)

    nova_service = {
        'type': 'compute',
        'name': 'nova',
        'endpoint_links': [],
        'endpoints': [
            {
                'region': 'RegionOne',
                'adminURL': 'http://nova-admin.localhost:8774/v2.0/%s' \
                            % (tenant_dict_1['id']),
                'internalURL': 'http://nova-internal.localhost:8774/v2.0/%s' \
                               % (tenant_dict_1['id']),
                'publicURL': 'http://nova-public.localhost:8774/v2.0/%s' \
                             % (tenant_dict_1['id'])
            },
            {
                'region': 'RegionTwo',
                'adminURL': 'http://nova2-admin.localhost:8774/v2.0/%s' \
                            % (tenant_dict_1['id']),
                'internalURL': 'http://nova2-internal.localhost:8774/v2.0/%s' \
                               % (tenant_dict_1['id']),
                'publicURL': 'http://nova2-public.localhost:8774/v2.0/%s' \
                             % (tenant_dict_1['id'])
            }
        ]
    }

    # Roles
    role_dict = {'id': uuid.uuid4().hex,
                 'name': 'Member'}
    test_data.role = Role(RoleManager, role_dict)

    # Tokens
    tomorrow = datetime_safe.datetime.now() + timedelta(days=1)
    expiration = datetime_safe.datetime.isoformat(tomorrow)

    scoped_token_dict = {
        'access': {
            'token': {
                'id': uuid.uuid4().hex,
                'expires': expiration,
                'tenant': tenant_dict_1,
                'tenants': [tenant_dict_1, tenant_dict_2]},
            'user': {
                'id': user_dict['id'],
                'name': user_dict['name'],
                'roles': [role_dict]},
            'serviceCatalog': [keystone_service, nova_service]
        }
    }

    test_data.scoped_access_info = AccessInfo.factory(
        resp=None,
        body=scoped_token_dict)

    unscoped_token_dict = {
        'access': {
            'token': {
                'id': uuid.uuid4().hex,
                'expires': expiration},
            'user': {
                     'id': user_dict['id'],
                     'name': user_dict['name'],
                     'roles': [role_dict]},
            'serviceCatalog': [keystone_service]
        }
    }
    test_data.unscoped_access_info = AccessInfo.factory(
        resp=None,
        body=unscoped_token_dict)

    # Service Catalog
    test_data.service_catalog = ServiceCatalog.factory({
        'serviceCatalog': [keystone_service, nova_service],
        'token': {
            'id': scoped_token_dict['access']['token']['id'],
            'expires': scoped_token_dict['access']['token']['expires'],
            'user_id': user_dict['id'],
            'tenant_id': tenant_dict_1['id']
        }
    })

    return test_data
Ejemplo n.º 6
0
def data(TEST):
    TEST.service_catalog = SERVICE_CATALOG
    TEST.tokens = TestDataContainer()
    TEST.domains = TestDataContainer()
    TEST.users = TestDataContainer()
    TEST.groups = TestDataContainer()
    TEST.tenants = TestDataContainer()
    TEST.roles = TestDataContainer()
    TEST.ec2 = TestDataContainer()

    admin_role_dict = {"id": "1", "name": "admin"}
    admin_role = roles.Role(roles.RoleManager, admin_role_dict)
    member_role_dict = {"id": "2", "name": settings.OPENSTACK_KEYSTONE_DEFAULT_ROLE}
    member_role = roles.Role(roles.RoleManager, member_role_dict)
    TEST.roles.add(admin_role, member_role)
    TEST.roles.admin = admin_role
    TEST.roles.member = member_role

    domain_dict = {"id": "1", "name": "test_domain", "description": "a test domain.", "enabled": True}
    domain_dict_2 = {"id": "2", "name": "disabled_domain", "description": "a disabled test domain.", "enabled": False}
    domain = domains.Domain(domains.DomainManager, domain_dict)
    disabled_domain = domains.Domain(domains.DomainManager, domain_dict_2)
    TEST.domains.add(domain, disabled_domain)
    TEST.domain = domain  # Your "current" domain

    user_dict = {
        "id": "1",
        "name": "test_user",
        "email": "*****@*****.**",
        "password": "******",
        "token": "test_token",
        "project_id": "1",
        "enabled": True,
        "domain_id": "1",
    }
    user = users.User(users.UserManager(None), user_dict)
    user_dict = {
        "id": "2",
        "name": "user_two",
        "email": "*****@*****.**",
        "password": "******",
        "token": "test_token",
        "project_id": "1",
        "enabled": True,
        "domain_id": "1",
    }
    user2 = users.User(users.UserManager(None), user_dict)
    user_dict = {
        "id": "3",
        "name": "user_three",
        "email": "*****@*****.**",
        "password": "******",
        "token": "test_token",
        "project_id": "1",
        "enabled": True,
        "domain_id": "1",
    }
    user3 = users.User(users.UserManager(None), user_dict)
    user_dict = {
        "id": "4",
        "name": "user_four",
        "email": "*****@*****.**",
        "password": "******",
        "token": "test_token",
        "project_id": "2",
        "enabled": True,
        "domain_id": "2",
    }
    user4 = users.User(users.UserManager(None), user_dict)
    TEST.users.add(user, user2, user3, user4)
    TEST.user = user  # Your "current" user
    TEST.user.service_catalog = SERVICE_CATALOG

    group_dict = {
        "id": "1",
        "name": "group_one",
        "description": "group one description",
        "project_id": "1",
        "domain_id": "1",
    }
    group = groups.Group(groups.GroupManager(None), group_dict)
    group_dict = {
        "id": "2",
        "name": "group_two",
        "description": "group two description",
        "project_id": "1",
        "domain_id": "1",
    }
    group2 = groups.Group(groups.GroupManager(None), group_dict)
    group_dict = {
        "id": "3",
        "name": "group_three",
        "description": "group three description",
        "project_id": "1",
        "domain_id": "1",
    }
    group3 = groups.Group(groups.GroupManager(None), group_dict)
    group_dict = {
        "id": "4",
        "name": "group_four",
        "description": "group four description",
        "project_id": "2",
        "domain_id": "2",
    }
    group4 = groups.Group(groups.GroupManager(None), group_dict)
    TEST.groups.add(group, group2, group3, group4)

    tenant_dict = {"id": "1", "name": "test_tenant", "description": "a test tenant.", "enabled": True, "domain_id": "1"}
    tenant_dict_2 = {
        "id": "2",
        "name": "disabled_tenant",
        "description": "a disabled test tenant.",
        "enabled": False,
        "domain_id": "2",
    }
    tenant_dict_3 = {
        "id": "3",
        "name": u"\u4e91\u89c4\u5219",
        "description": "an unicode-named tenant.",
        "enabled": True,
        "domain_id": "2",
    }
    tenant = tenants.Tenant(tenants.TenantManager, tenant_dict)
    disabled_tenant = tenants.Tenant(tenants.TenantManager, tenant_dict_2)
    tenant_unicode = tenants.Tenant(tenants.TenantManager, tenant_dict_3)

    TEST.tenants.add(tenant, disabled_tenant, tenant_unicode)
    TEST.tenant = tenant  # Your "current" tenant

    tomorrow = datetime_safe.datetime.now() + timedelta(days=1)
    expiration = datetime_safe.datetime.isoformat(tomorrow)

    scoped_token_dict = {
        "access": {
            "token": {"id": "test_token_id", "expires": expiration, "tenant": tenant_dict, "tenants": [tenant_dict]},
            "user": {"id": "test_user_id", "name": "test_user", "roles": [member_role_dict]},
            "serviceCatalog": TEST.service_catalog,
        }
    }

    scoped_access_info = AccessInfo.factory(resp=None, body=scoped_token_dict)

    unscoped_token_dict = {
        "access": {
            "token": {"id": "test_token_id", "expires": expiration},
            "user": {"id": "test_user_id", "name": "test_user", "roles": [member_role_dict]},
            "serviceCatalog": TEST.service_catalog,
        }
    }
    unscoped_access_info = AccessInfo.factory(resp=None, body=unscoped_token_dict)

    scoped_token = Token(scoped_access_info)
    unscoped_token = Token(unscoped_access_info)
    TEST.tokens.add(scoped_token, unscoped_token)
    TEST.token = scoped_token  # your "current" token.
    TEST.tokens.scoped_token = scoped_token
    TEST.tokens.unscoped_token = unscoped_token

    access_secret = ec2.EC2(ec2.CredentialsManager, {"access": "access", "secret": "secret"})
    TEST.ec2.add(access_secret)
Ejemplo n.º 7
0
def generate_test_data():
    ''' Builds a set of test_data data as returned by Keystone V2. '''
    test_data = TestDataContainer()

    keystone_service = {
        'type':
        'identity',
        'id':
        uuid.uuid4().hex,
        'endpoints': [{
            'url': 'http://admin.localhost:35357/v3',
            'region': 'RegionOne',
            'interface': 'admin',
            'id': uuid.uuid4().hex,
        }, {
            'url': 'http://internal.localhost:5000/v3',
            'region': 'RegionOne',
            'interface': 'internal',
            'id': uuid.uuid4().hex
        }, {
            'url': 'http://public.localhost:5000/v3',
            'region': 'RegionOne',
            'interface': 'public',
            'id': uuid.uuid4().hex
        }]
    }

    # Domains
    domain_dict = {
        'id': uuid.uuid4().hex,
        'name': 'domain',
        'description': '',
        'enabled': True
    }
    test_data.domain = Domain(DomainManager(None), domain_dict, loaded=True)

    # Users
    user_dict = {
        'id': uuid.uuid4().hex,
        'name': 'gabriel',
        'email': '*****@*****.**',
        'password': '******',
        'domain_id': domain_dict['id'],
        'token': '',
        'enabled': True
    }
    test_data.user = User(UserManager(None), user_dict, loaded=True)

    # Projects
    project_dict_1 = {
        'id': uuid.uuid4().hex,
        'name': 'tenant_one',
        'description': '',
        'domain_id': domain_dict['id'],
        'enabled': True
    }
    project_dict_2 = {
        'id': uuid.uuid4().hex,
        'name': '',
        'description': '',
        'domain_id': domain_dict['id'],
        'enabled': False
    }
    test_data.project_one = Project(ProjectManager(None),
                                    project_dict_1,
                                    loaded=True)
    test_data.project_two = Project(ProjectManager(None),
                                    project_dict_2,
                                    loaded=True)

    # Roles
    role_dict = {'id': uuid.uuid4().hex, 'name': 'Member'}
    test_data.role = Role(RoleManager, role_dict)

    nova_service = {
        'type': 'compute',
        'id': uuid.uuid4().hex,
        'endpoints': [
            {
                'url': 'http://nova-admin.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region': 'RegionOne',
                'interface': 'admin',
                'id': uuid.uuid4().hex,
            },
            {
                'url': 'http://nova-internal.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region': 'RegionOne',
                'interface': 'internal',
                'id': uuid.uuid4().hex
            },
            {
                'url':'http://nova-public.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region':'RegionOne',
                'interface': 'public',
                 'id': uuid.uuid4().hex
            },
            {
                'url': 'http://nova2-admin.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region': 'RegionTwo',
                'interface': 'admin',
                'id': uuid.uuid4().hex,
            },
            {
                'url': 'http://nova2-internal.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region': 'RegionTwo',
                'interface': 'internal',
                'id': uuid.uuid4().hex
            },
            {
                'url':'http://nova2-public.localhost:8774/v2.0/%s' \
                       % (project_dict_1['id']),
                'region':'RegionTwo',
                'interface': 'public',
                 'id': uuid.uuid4().hex
            }
        ]
    }

    # Tokens
    tomorrow = datetime_safe.datetime.now() + timedelta(days=1)
    expiration = datetime_safe.datetime.isoformat(tomorrow)
    auth_token = uuid.uuid4().hex
    auth_response_headers = {'X-Subject-Token': auth_token}

    auth_response = TestResponse({"headers": auth_response_headers})

    scoped_token_dict = {
        'token': {
            'methods': ['password'],
            'expires_at': expiration,
            'project': {
                'id': project_dict_1['id'],
                'name': project_dict_1['name'],
                'domain': {
                    'id': domain_dict['id'],
                    'name': domain_dict['name']
                }
            },
            'user': {
                'id': user_dict['id'],
                'name': user_dict['name'],
                'domain': {
                    'id': domain_dict['id'],
                    'name': domain_dict['name']
                }
            },
            'roles': [role_dict],
            'catalog': [keystone_service, nova_service]
        }
    }

    test_data.scoped_access_info = AccessInfo.factory(resp=auth_response,
                                                      body=scoped_token_dict)

    unscoped_token_dict = {
        'token': {
            'methods': ['password'],
            'expires_at': expiration,
            'user': {
                'id': user_dict['id'],
                'name': user_dict['name'],
                'domain': {
                    'id': domain_dict['id'],
                    'name': domain_dict['name']
                }
            },
            'roles': [role_dict],
            'catalog': [keystone_service]
        }
    }

    test_data.unscoped_access_info = AccessInfo.factory(
        resp=auth_response, body=unscoped_token_dict)

    # Service Catalog
    test_data.service_catalog = ServiceCatalog.factory(
        {
            'methods': ['password'],
            'user': {},
            'catalog': [keystone_service, nova_service],
        },
        token=auth_token)

    return test_data