Beispiel #1
0
    def test_password_change_auth_state(self):
        self.stub_auth(json=self.TEST_RESPONSE_DICT)

        expired = ksa_utils.before_utcnow(days=2)
        token = fixture.V2Token(expires=expired)

        auth_ref = access.create(body=token)

        a = v2.Password(self.TEST_URL,
                        username=self.TEST_USER,
                        password=self.TEST_PASS,
                        tenant_id=uuid.uuid4().hex)

        initial_cache_id = a.get_cache_id()

        state = a.get_auth_state()
        self.assertIsNone(state)

        state = json.dumps({
            'auth_token': auth_ref.auth_token,
            'body': auth_ref._data
        })
        a.set_auth_state(state)

        self.assertEqual(token.token_id, a.auth_ref.auth_token)

        s = session.Session()
        self.assertEqual(self.TEST_TOKEN, a.get_token(s))  # updates expired
        self.assertEqual(initial_cache_id, a.get_cache_id())
    def __init__(self, expires=None, issued=None, user_id=None, user_name=None,
                 user_domain_id=None, user_domain_name=None, methods=None,
                 project_id=None, project_name=None, project_domain_id=None,
                 project_domain_name=None, domain_id=None, domain_name=None,
                 trust_id=None, trust_impersonation=None, trustee_user_id=None,
                 trustor_user_id=None, oauth_access_token_id=None,
                 oauth_consumer_id=None, audit_id=None, audit_chain_id=None):
        super(Token, self).__init__()

        self.user_id = user_id or uuid.uuid4().hex
        self.user_name = user_name or uuid.uuid4().hex
        self.user_domain_id = user_domain_id or uuid.uuid4().hex
        self.user_domain_name = user_domain_name or uuid.uuid4().hex
        self.audit_id = audit_id or uuid.uuid4().hex

        if not methods:
            methods = ['password']
        self.methods.extend(methods)

        if not issued:
            issued = _utils.before_utcnow(minutes=2)

        try:
            self.issued = issued
        except (TypeError, AttributeError):
            # issued should be able to be passed as a string so ignore
            self.issued_str = issued

        if not expires:
            expires = self.issued + datetime.timedelta(hours=1)

        try:
            self.expires = expires
        except (TypeError, AttributeError):
            # expires should be able to be passed as a string so ignore
            self.expires_str = expires

        if (project_id or project_name or
                project_domain_id or project_domain_name):
            self.set_project_scope(id=project_id,
                                   name=project_name,
                                   domain_id=project_domain_id,
                                   domain_name=project_domain_name)

        if domain_id or domain_name:
            self.set_domain_scope(id=domain_id, name=domain_name)

        if (trust_id or (trust_impersonation is not None) or
                trustee_user_id or trustor_user_id):
            self.set_trust_scope(id=trust_id,
                                 impersonation=trust_impersonation,
                                 trustee_user_id=trustee_user_id,
                                 trustor_user_id=trustor_user_id)

        if oauth_access_token_id or oauth_consumer_id:
            self.set_oauth(access_token_id=oauth_access_token_id,
                           consumer_id=oauth_consumer_id)

        if audit_chain_id:
            self.audit_chain_id = audit_chain_id
Beispiel #3
0
    def test_password_change_auth_state(self):
        self.stub_auth(json=self.TEST_RESPONSE_DICT)

        expired = ksa_utils.before_utcnow(days=2)
        token = fixture.V3Token(expires=expired)
        token_id = uuid.uuid4().hex

        state = json.dumps({'auth_token': token_id, 'body': token})

        a = v3.Password(self.TEST_URL,
                        username=self.TEST_USER,
                        password=self.TEST_PASS,
                        user_domain_id=self.TEST_DOMAIN_ID,
                        project_id=uuid.uuid4().hex)

        initial_cache_id = a.get_cache_id()

        self.assertIsNone(a.get_auth_state())
        a.set_auth_state(state)

        self.assertEqual(token_id, a.auth_ref.auth_token)

        s = session.Session()
        self.assertEqual(self.TEST_TOKEN, a.get_token(s))  # updates expired
        self.assertEqual(initial_cache_id, a.get_cache_id())
Beispiel #4
0
    def test_password_change_auth_state(self):
        self.stub_auth(json=self.TEST_RESPONSE_DICT)

        expired = ksa_utils.before_utcnow(days=2)
        token = fixture.V3Token(expires=expired)
        token_id = uuid.uuid4().hex

        state = json.dumps({'auth_token': token_id, 'body': token})

        a = v3.Password(self.TEST_URL,
                        username=self.TEST_USER,
                        password=self.TEST_PASS,
                        user_domain_id=self.TEST_DOMAIN_ID,
                        project_id=uuid.uuid4().hex)

        initial_cache_id = a.get_cache_id()

        self.assertIsNone(a.get_auth_state())
        a.set_auth_state(state)

        self.assertEqual(token_id, a.auth_ref.auth_token)

        s = session.Session()
        self.assertEqual(self.TEST_TOKEN, a.get_token(s))  # updates expired
        self.assertEqual(initial_cache_id, a.get_cache_id())
Beispiel #5
0
    def test_password_change_auth_state(self):
        self.stub_auth(json=self.TEST_RESPONSE_DICT)

        expired = ksa_utils.before_utcnow(days=2)
        token = fixture.V2Token(expires=expired)

        auth_ref = access.create(body=token)

        a = v2.Password(self.TEST_URL,
                        username=self.TEST_USER,
                        password=self.TEST_PASS,
                        tenant_id=uuid.uuid4().hex)

        initial_cache_id = a.get_cache_id()

        state = a.get_auth_state()
        self.assertIsNone(state)

        state = json.dumps({'auth_token': auth_ref.auth_token,
                            'body': auth_ref._data})
        a.set_auth_state(state)

        self.assertEqual(token.token_id, a.auth_ref.auth_token)

        s = session.Session()
        self.assertEqual(self.TEST_TOKEN, a.get_token(s))  # updates expired
        self.assertEqual(initial_cache_id, a.get_cache_id())
    def _create_expired_auth_plugin(self, **kwargs):
        expires = _utils.before_utcnow(minutes=20)
        expired_token = self.get_auth_data(expires=expires)
        expired_auth_ref = access.create(body=expired_token)

        body = 'SUCCESS'
        self.stub_url('GET', ['path'],
                      base_url=self.TEST_COMPUTE_ADMIN, text=body)

        a = self.create_auth_plugin(**kwargs)
        a.auth_ref = expired_auth_ref
        return a
    def _create_expired_auth_plugin(self, **kwargs):
        expires = _utils.before_utcnow(minutes=20)
        expired_token = self.get_auth_data(expires=expires)
        expired_auth_ref = access.create(body=expired_token)

        body = 'SUCCESS'
        self.stub_url('GET', ['path'],
                      base_url=self.TEST_COMPUTE_ADMIN,
                      text=body)

        a = self.create_auth_plugin(**kwargs)
        a.auth_ref = expired_auth_ref
        return a
Beispiel #8
0
    def __init__(self,
                 token_id=None,
                 expires=None,
                 issued=None,
                 tenant_id=None,
                 tenant_name=None,
                 user_id=None,
                 user_name=None,
                 trust_id=None,
                 trustee_user_id=None,
                 audit_id=None,
                 audit_chain_id=None):
        super(Token, self).__init__()

        self.token_id = token_id or uuid.uuid4().hex
        self.user_id = user_id or uuid.uuid4().hex
        self.user_name = user_name or uuid.uuid4().hex
        self.audit_id = audit_id or uuid.uuid4().hex

        if not issued:
            issued = _utils.before_utcnow(minutes=2)
        if not expires:
            expires = issued + datetime.timedelta(hours=1)

        try:
            self.issued = issued
        except (TypeError, AttributeError):
            # issued should be able to be passed as a string so ignore
            self.issued_str = issued

        try:
            self.expires = expires
        except (TypeError, AttributeError):
            # expires should be able to be passed as a string so ignore
            self.expires_str = expires

        if tenant_id or tenant_name:
            self.set_scope(tenant_id, tenant_name)

        if trust_id or trustee_user_id:
            # the trustee_user_id will generally be the same as the user_id as
            # the token is being issued to the trustee
            self.set_trust(id=trust_id,
                           trustee_user_id=trustee_user_id or user_id)

        if audit_chain_id:
            self.audit_chain_id = audit_chain_id
Beispiel #9
0
    def __init__(self, token_id=None, expires=None, issued=None,
                 tenant_id=None, tenant_name=None, user_id=None,
                 user_name=None, trust_id=None, trustee_user_id=None,
                 audit_id=None, audit_chain_id=None):
        super(Token, self).__init__()

        self.token_id = token_id or uuid.uuid4().hex
        self.user_id = user_id or uuid.uuid4().hex
        self.user_name = user_name or uuid.uuid4().hex
        self.audit_id = audit_id or uuid.uuid4().hex

        if not issued:
            issued = _utils.before_utcnow(minutes=2)
        if not expires:
            expires = issued + datetime.timedelta(hours=1)

        try:
            self.issued = issued
        except (TypeError, AttributeError):
            # issued should be able to be passed as a string so ignore
            self.issued_str = issued

        try:
            self.expires = expires
        except (TypeError, AttributeError):
            # expires should be able to be passed as a string so ignore
            self.expires_str = expires

        if tenant_id or tenant_name:
            self.set_scope(tenant_id, tenant_name)

        if trust_id or trustee_user_id:
            # the trustee_user_id will generally be the same as the user_id as
            # the token is being issued to the trustee
            self.set_trust(id=trust_id,
                           trustee_user_id=trustee_user_id or user_id)

        if audit_chain_id:
            self.audit_chain_id = audit_chain_id
Beispiel #10
0
    def __init__(self, id, status=None, updated=None):
        super(DiscoveryBase, self).__init__()

        self.id = id
        self.status = status or 'stable'
        self.updated = updated or utils.before_utcnow(days=_DEFAULT_DAYS_AGO)
Beispiel #11
0
    def __init__(self,
                 expires=None,
                 issued=None,
                 user_id=None,
                 user_name=None,
                 user_domain_id=None,
                 user_domain_name=None,
                 methods=None,
                 project_id=None,
                 project_name=None,
                 project_domain_id=None,
                 project_domain_name=None,
                 domain_id=None,
                 domain_name=None,
                 trust_id=None,
                 trust_impersonation=None,
                 trustee_user_id=None,
                 trustor_user_id=None,
                 application_credential_id=None,
                 application_credential_access_rules=None,
                 oauth_access_token_id=None,
                 oauth_consumer_id=None,
                 audit_id=None,
                 audit_chain_id=None,
                 is_admin_project=None,
                 project_is_domain=None):
        super(Token, self).__init__()

        self.user_id = user_id or uuid.uuid4().hex
        self.user_name = user_name or uuid.uuid4().hex
        self.user_domain_id = user_domain_id or uuid.uuid4().hex
        self.user_domain_name = user_domain_name or uuid.uuid4().hex
        self.audit_id = audit_id or uuid.uuid4().hex

        if not methods:
            methods = ['password']
        self.methods.extend(methods)

        if not issued:
            issued = _utils.before_utcnow(minutes=2)

        try:
            self.issued = issued
        except (TypeError, AttributeError):
            # issued should be able to be passed as a string so ignore
            self.issued_str = issued

        if not expires:
            expires = self.issued + datetime.timedelta(hours=1)

        try:
            self.expires = expires
        except (TypeError, AttributeError):
            # expires should be able to be passed as a string so ignore
            self.expires_str = expires

        if (project_id or project_name or project_domain_id
                or project_domain_name):
            self.set_project_scope(id=project_id,
                                   name=project_name,
                                   domain_id=project_domain_id,
                                   domain_name=project_domain_name,
                                   is_domain=project_is_domain)

        if domain_id or domain_name:
            self.set_domain_scope(id=domain_id, name=domain_name)

        if (trust_id or (trust_impersonation is not None) or trustee_user_id
                or trustor_user_id):
            self.set_trust_scope(id=trust_id,
                                 impersonation=trust_impersonation,
                                 trustee_user_id=trustee_user_id,
                                 trustor_user_id=trustor_user_id)

        if application_credential_id:
            self.set_application_credential(
                application_credential_id,
                access_rules=application_credential_access_rules)

        if oauth_access_token_id or oauth_consumer_id:
            self.set_oauth(access_token_id=oauth_access_token_id,
                           consumer_id=oauth_consumer_id)

        if audit_chain_id:
            self.audit_chain_id = audit_chain_id

        if is_admin_project is not None:
            self.is_admin_project = is_admin_project
Beispiel #12
0
    def __init__(self, id, status=None, updated=None):
        super(DiscoveryBase, self).__init__()

        self.id = id
        self.status = status or 'stable'
        self.updated = updated or utils.before_utcnow(days=_DEFAULT_DAYS_AGO)