当前位置: 首页>>代码示例>>Python>>正文


Python Shell._get_cached_token_path_for_user方法代码示例

本文整理汇总了Python中st2client.shell.Shell._get_cached_token_path_for_user方法的典型用法代码示例。如果您正苦于以下问题:Python Shell._get_cached_token_path_for_user方法的具体用法?Python Shell._get_cached_token_path_for_user怎么用?Python Shell._get_cached_token_path_for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2client.shell.Shell的用法示例。


在下文中一共展示了Shell._get_cached_token_path_for_user方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_cached_auth_token_invalid_permissions

# 需要导入模块: from st2client.shell import Shell [as 别名]
# 或者: from st2client.shell.Shell import _get_cached_token_path_for_user [as 别名]
    def test_get_cached_auth_token_invalid_permissions(self):
        shell = Shell()
        client = Client()
        username = 'testu'
        password = 'testp'

        cached_token_path = shell._get_cached_token_path_for_user(username=username)
        data = {
            'token': 'yayvalid',
            'expire_timestamp': (int(time.time()) + 20)
        }
        with open(cached_token_path, 'w') as fp:
            fp.write(json.dumps(data))

        # 1. Current user doesn't have read access to the config directory
        os.chmod(self._mock_config_directory_path, 0000)

        shell.LOG = mock.Mock()
        result = shell._get_cached_auth_token(client=client, username=username,
                                              password=password)

        self.assertEqual(result, None)
        self.assertEqual(shell.LOG.warn.call_count, 1)
        log_message = shell.LOG.warn.call_args[0][0]

        expected_msg = ('Unable to retrieve cached token from .*? read access to the parent '
                        'directory')
        self.assertRegexpMatches(log_message, expected_msg)

        # 2. Read access on the directory, but not on the cached token file
        os.chmod(self._mock_config_directory_path, 0777)  # nosec
        os.chmod(cached_token_path, 0000)

        shell.LOG = mock.Mock()
        result = shell._get_cached_auth_token(client=client, username=username,
                                              password=password)
        self.assertEqual(result, None)

        self.assertEqual(shell.LOG.warn.call_count, 1)
        log_message = shell.LOG.warn.call_args[0][0]

        expected_msg = ('Unable to retrieve cached token from .*? read access to this file')
        self.assertRegexpMatches(log_message, expected_msg)

        # 3. Other users also have read access to the file
        os.chmod(self._mock_config_directory_path, 0777)  # nosec
        os.chmod(cached_token_path, 0444)

        shell.LOG = mock.Mock()
        result = shell._get_cached_auth_token(client=client, username=username,
                                              password=password)
        self.assertEqual(result, 'yayvalid')

        self.assertEqual(shell.LOG.warn.call_count, 1)
        log_message = shell.LOG.warn.call_args[0][0]

        expected_msg = ('Permissions .*? for cached token file .*? are to permissive')
        self.assertRegexpMatches(log_message, expected_msg)
开发者ID:LindsayHill,项目名称:st2,代码行数:60,代码来源:test_shell.py

示例2: test_cache_auth_token_invalid_permissions

# 需要导入模块: from st2client.shell import Shell [as 别名]
# 或者: from st2client.shell.Shell import _get_cached_token_path_for_user [as 别名]
    def test_cache_auth_token_invalid_permissions(self):
        shell = Shell()
        username = 'testu'

        cached_token_path = shell._get_cached_token_path_for_user(username=username)
        expiry = datetime.datetime.utcnow() + datetime.timedelta(seconds=30)

        token_db = TokenDB(user=username, token='fyeah', expiry=expiry)

        cached_token_path = shell._get_cached_token_path_for_user(username=username)
        data = {
            'token': 'yayvalid',
            'expire_timestamp': (int(time.time()) + 20)
        }
        with open(cached_token_path, 'w') as fp:
            fp.write(json.dumps(data))

        # 1. Current user has no write access to the parent directory
        os.chmod(self._mock_config_directory_path, 0000)

        shell.LOG = mock.Mock()
        shell._cache_auth_token(token_obj=token_db)

        self.assertEqual(shell.LOG.warn.call_count, 1)
        log_message = shell.LOG.warn.call_args[0][0]

        expected_msg = ('Unable to write token to .*? doesn\'t have write access to the parent '
                        'directory')
        self.assertRegexpMatches(log_message, expected_msg)

        # 2. Current user has no write access to the cached token file
        os.chmod(self._mock_config_directory_path, 0777)  # nosec
        os.chmod(cached_token_path, 0000)

        shell.LOG = mock.Mock()
        shell._cache_auth_token(token_obj=token_db)

        self.assertEqual(shell.LOG.warn.call_count, 1)
        log_message = shell.LOG.warn.call_args[0][0]

        expected_msg = ('Unable to write token to .*? doesn\'t have write access to this file')
        self.assertRegexpMatches(log_message, expected_msg)
开发者ID:LindsayHill,项目名称:st2,代码行数:44,代码来源:test_shell.py

示例3: test_get_cached_auth_token_corrupted_token_cache_file

# 需要导入模块: from st2client.shell import Shell [as 别名]
# 或者: from st2client.shell.Shell import _get_cached_token_path_for_user [as 别名]
    def test_get_cached_auth_token_corrupted_token_cache_file(self):
        client = Client()
        shell = Shell()
        username = 'testu'
        password = 'testp'

        cached_token_path = shell._get_cached_token_path_for_user(username=username)
        with open(cached_token_path, 'w') as fp:
            fp.write('CORRRRRUPTED!')

        expected_msg = 'File (.+) with cached token is corrupted or invalid'
        self.assertRaisesRegexp(ValueError, expected_msg, shell._get_cached_auth_token,
                                client=client, username=username, password=password)
开发者ID:azamsheriff,项目名称:st2,代码行数:15,代码来源:test_shell.py

示例4: test_get_cached_auth_token_valid_token_in_cache_file

# 需要导入模块: from st2client.shell import Shell [as 别名]
# 或者: from st2client.shell.Shell import _get_cached_token_path_for_user [as 别名]
    def test_get_cached_auth_token_valid_token_in_cache_file(self):
        client = Client()
        shell = Shell()
        username = 'testu'
        password = 'testp'

        cached_token_path = shell._get_cached_token_path_for_user(username=username)
        data = {
            'token': 'yayvalid',
            'expire_timestamp': (int(time.time()) + 20)
        }
        with open(cached_token_path, 'w') as fp:
            fp.write(json.dumps(data))

        result = shell._get_cached_auth_token(client=client, username=username,
                                              password=password)
        self.assertEqual(result, 'yayvalid')
开发者ID:azamsheriff,项目名称:st2,代码行数:19,代码来源:test_shell.py


注:本文中的st2client.shell.Shell._get_cached_token_path_for_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。