コード例 #1
0
    def test_gen_new_auth_token(self):
        from pillar.api import service

        with self.app.test_request_context():
            tokens_coll = self.app.db('tokens')
            service_account_id = self.flamenco.manager_manager.find_service_account_id(
                self.mngr_id)

            # Create a new more tokens
            service.generate_auth_token(service_account_id)
            service.generate_auth_token(service_account_id)
            service.generate_auth_token(service_account_id)

            all_tokens = tokens_coll.find({'user': service_account_id})
            self.assertEqual(all_tokens.count(), 4)

            token = self.flamenco.manager_manager.gen_new_auth_token(
                self.mngr_id)

            # There can be only one, rest should have been deleted.
            all_tokens = tokens_coll.find({'user': service_account_id})
            self.assertEqual(all_tokens.count(), 1)

        self.assertNotEqual(token.token, self.mngr_token)
        self.assertTrue(token.token.startswith('SRV'))
        self.assertTrue(token.expire_time > datetime.datetime.now(tz=utc))
コード例 #2
0
ファイル: __init__.py プロジェクト: BlenderCN-Org/flamenco
    def gen_new_auth_token(
            self, manager_id: bson.ObjectId) -> typing.Optional[AuthTokenInfo]:
        """Generates a new authentication token for the given Manager.

        Deletes all pre-existing authentication tokens of the Manager.
        """

        from pillar.api import service

        service_account_id = self.revoke_auth_token(manager_id)

        self._log.info(
            'Generating new authentication token for Manager %s on behalf of user %s',
            manager_id, current_user.user_id)
        token_info = service.generate_auth_token(service_account_id)
        return AuthTokenInfo(
            token=token_info['token'],
            expire_time=token_info['expire_time'],
        )
コード例 #3
0
    def test_revoke_auth_token(self):
        from pillar.api import service

        with self.app.test_request_context():
            tokens_coll = self.app.db('tokens')
            service_account_id = self.flamenco.manager_manager.find_service_account_id(self.mngr_id)

            # Create a new more tokens
            service.generate_auth_token(service_account_id)
            service.generate_auth_token(service_account_id)
            service.generate_auth_token(service_account_id)

            all_tokens = tokens_coll.find({'user': service_account_id})
            self.assertEqual(all_tokens.count(), 4)

            self.flamenco.manager_manager.revoke_auth_token(self.mngr_id)

            # All should have been deleted.
            all_tokens = tokens_coll.find({'user': service_account_id})
            self.assertEqual(all_tokens.count(), 0)
コード例 #4
0
    def test_revoke_auth_token(self):
        from pillar.api import service

        with self.app.test_request_context():
            tokens_coll = self.app.db('tokens')
            service_account_id = self.flamenco.manager_manager.find_service_account_id(
                self.mngr_id)

            # Create a new more tokens
            service.generate_auth_token(service_account_id)
            service.generate_auth_token(service_account_id)
            service.generate_auth_token(service_account_id)

            all_tokens = tokens_coll.find({'user': service_account_id})
            self.assertEqual(all_tokens.count(), 4)

            self.flamenco.manager_manager.revoke_auth_token(self.mngr_id)

            # All should have been deleted.
            all_tokens = tokens_coll.find({'user': service_account_id})
            self.assertEqual(all_tokens.count(), 0)
コード例 #5
0
    def test_gen_new_auth_token(self):
        from pillar.api import service

        with self.app.test_request_context():
            tokens_coll = self.app.db('tokens')
            service_account_id = self.flamenco.manager_manager.find_service_account_id(self.mngr_id)

            # Create a new more tokens
            service.generate_auth_token(service_account_id)
            service.generate_auth_token(service_account_id)
            service.generate_auth_token(service_account_id)

            all_tokens = tokens_coll.find({'user': service_account_id})
            self.assertEqual(all_tokens.count(), 4)

            token = self.flamenco.manager_manager.gen_new_auth_token(self.mngr_id)

            # There can be only one, rest should have been deleted.
            all_tokens = tokens_coll.find({'user': service_account_id})
            self.assertEqual(all_tokens.count(), 1)

        self.assertNotEqual(token.token, self.mngr_token)
        self.assertTrue(token.token.startswith('SRV'))
        self.assertTrue(token.expire_time > datetime.datetime.now(tz=utc))