Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 13.58.199.13
Web Server : Apache/2.4.18 (Ubuntu)
System :
User : www-data ( )
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python2.7/dist-packages/keyring/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /usr/lib/python2.7/dist-packages/keyring/tests/test_core.py
from __future__ import with_statement

import os

import mock
import pytest

import keyring.backend
import keyring.core
import keyring.util.platform_
from keyring import errors

PASSWORD_TEXT = "This is password"
PASSWORD_TEXT_2 = "This is password2"


@pytest.yield_fixture()
def config_filename(tmpdir):
    filename = tmpdir / 'keyringrc.cfg'
    with mock.patch('keyring.util.platform_.config_root', lambda: str(tmpdir)):
        yield str(filename)


class ATestKeyring(keyring.backend.KeyringBackend):
    """A faked keyring for test.
    """
    def __init__(self):
        self.passwords = {}

    def supported(self):
        return 0

    def get_password(self, service, username):
        return PASSWORD_TEXT

    def set_password(self, service, username, password):
        self.passwords[(service, username)] = password
        return 0

    def delete_password(self, service, username):
        try:
            del self.passwords[(service, username)]
        except KeyError:
            raise errors.PasswordDeleteError("not set")


class AnotherTestKeyring(ATestKeyring):
    """Another faked keyring for test.
    """
    def get_password(self, service, username):
        return PASSWORD_TEXT_2


class TestCore:
    mock_global_backend = mock.patch('keyring.core._keyring_backend')

    @mock_global_backend
    def test_set_password(self, backend):
        """
        set_password on the default keyring is called.
        """
        keyring.core.set_password("test", "user", "passtest")
        backend.set_password.assert_called_once_with('test', 'user',
            'passtest')

    @mock_global_backend
    def test_get_password(self, backend):
        """
        set_password on the default keyring is called.
        """
        result = keyring.core.get_password("test", "user")
        backend.get_password.assert_called_once_with('test', 'user')
        assert result is not None

    @mock_global_backend
    def test_delete_password(self, backend):
        keyring.core.delete_password("test", "user")
        backend.delete_password.assert_called_once_with('test', 'user')

    def test_set_keyring_in_runtime(self):
        """Test the function of set keyring in runtime.
        """
        keyring.core.set_keyring(ATestKeyring())

        keyring.core.set_password("test", "user", "password")
        assert keyring.core.get_password("test", "user") == PASSWORD_TEXT

    def test_set_keyring_in_config(self, config_filename):
        """Test setting the keyring by config file.
        """
        # create the config file
        with open(config_filename, 'w') as config_file:
            config_file.writelines([
                "[backend]\n",
                # the path for the user created keyring
                "keyring-path= %s\n" % os.path.dirname(os.path.abspath(__file__)),
                # the name of the keyring class
                "default-keyring=test_core.AnotherTestKeyring\n",
                ])

        # init the keyring lib, the lib will automaticlly load the
        # config file and load the user defined module
        keyring.core.init_backend()

        keyring.core.set_password("test", "user", "password")
        assert keyring.core.get_password("test", "user") == PASSWORD_TEXT_2

    def test_load_config_empty(self, config_filename):
        "A non-existent or empty config should load"
        assert keyring.core.load_config() is None

    def test_load_config_degenerate(self, config_filename):
        "load_config should succeed in the absence of a backend section"
        with open(config_filename, 'w') as config_file:
            config_file.write('[keyring]')
        assert keyring.core.load_config() is None

    def test_load_config_blank_backend(self, config_filename):
        "load_config should succeed with an empty [backend] section"
        with open(config_filename, 'w') as config_file:
            config_file.write('[backend]')
        assert keyring.core.load_config() is None

Anon7 - 2022
AnonSec Team