def test_version(self): # version exists assert self.keyring.version is not None if not hasattr(self.keyring, '_check_version'): return # generate keyring self.set_password('system', 'user', 'password') config = self.get_config() # default version valid assert self.keyring._check_version(config) is True krsetting = escape_for_ini('keyring-setting') version = escape_for_ini('version') # invalid, if version is missing config.remove_option(krsetting, version) self.save_config(config) assert self.keyring._check_version(config) is False
def test_file(self): if not hasattr(self.keyring, '_check_file'): return # keyring file doesn't exist yet assert self.keyring._check_file() is False # generate keyring self.set_password('system', 'user', 'password') # valid keyring file exist now assert self.keyring._check_file() is True # lock keyring self.keyring._lock() # fetch password from keyring assert self.keyring.get_password('system', 'user') == 'password' # test missing password reference config = self.get_config() krsetting = escape_for_ini('keyring-setting') pwref = escape_for_ini('password reference') # pwrefval = config.get(krsetting, pwref) config.remove_option(krsetting, pwref) self.save_config(config) assert self.keyring._check_file() is False
def test_scheme(self): # scheme exists assert self.keyring.scheme is not None if not hasattr(self.keyring, '_check_file'): return # keyring file doesn't exist yet assert self.keyring._check_file() is False # generate keyring self.set_password('system', 'user', 'password') config = self.get_config() krsetting = escape_for_ini('keyring-setting') scheme = escape_for_ini('scheme') defscheme = '[PBKDF2] AES256.CFB' # default scheme match assert config.get(krsetting, scheme) == defscheme # invalid AES mode config.set(krsetting, scheme, defscheme.replace('CFB', 'XXX')) with pytest.raises(ValueError): self.keyring._check_scheme(config) # compatibility with former scheme format config.set(krsetting, scheme, 'PyCrypto ' + defscheme) assert self.keyring._check_scheme(config) is None # test with invalid KDF config.set(krsetting, scheme, defscheme.replace('PBKDF2', 'scrypt')) with pytest.raises(ValueError): self.keyring._check_scheme(config) # a missing scheme is valid config.remove_option(krsetting, scheme) self.save_config(config) assert self.keyring._check_file() is True with pytest.raises(AttributeError): self.keyring._check_scheme(config)