def fake_app(ctx): ctx.obj = {} x = utils.get_password(user, resource) click.echo('Password is {}'.format(x)) monkeypatch.setattr(doubleclick.click, 'prompt', blow_up) assert (user, 'example.com') in ctx.obj['passwords'] x = utils.get_password(user, resource) click.echo('Password is {}'.format(x))
def test_get_password_from_system_keyring(monkeypatch): username = '******' password = '******' resource = 'http://example.com/path/to/whatever/' hostname = 'example.com' class KeyringMock(object): def get_password(self, resource, _username): assert _username == username assert resource == utils.password_key_prefix + hostname return password monkeypatch.setattr(utils, 'keyring', KeyringMock()) monkeypatch.setattr('getpass.getpass', blow_up) _password = utils.get_password(username, resource) assert _password == password
def test_get_password_from_netrc(monkeypatch): username = '******' password = '******' resource = 'http://example.com/path/to/whatever/' hostname = 'example.com' calls = [] class Netrc(object): def authenticators(self, hostname): calls.append(hostname) return username, 'bogus', password monkeypatch.setattr('netrc.netrc', Netrc) monkeypatch.setattr('getpass.getpass', blow_up) _password = utils.get_password(username, resource) assert _password == password assert calls == [hostname]
def test_get_password_from_system_keyring(monkeypatch, resources_to_test): username = '******' password = '******' resource = 'http://example.com/path/to/whatever/' hostname = 'example.com' class KeyringMock(object): def __init__(self): p = utils.password_key_prefix self.resources = [ p + 'http://example.com/path/to/whatever/', p + 'http://example.com/path/to/whatever', p + 'http://example.com/path/to/', p + 'http://example.com/path/to', p + 'http://example.com/path/', p + 'http://example.com/path', p + 'http://example.com/', ][:resources_to_test] def get_password(self, resource, _username): assert _username == username assert resource == self.resources.pop(0) if not self.resources: return password monkeypatch.setattr(utils, 'keyring', KeyringMock()) netrc_calls = [] class Netrc(object): def authenticators(self, hostname): netrc_calls.append(hostname) return None monkeypatch.setattr('netrc.netrc', Netrc) monkeypatch.setattr('getpass.getpass', blow_up) _password = utils.get_password(username, resource) assert _password == password assert netrc_calls == [hostname]
def test_get_password_from_system_keyring(monkeypatch, resources_to_test): username = '******' password = '******' resource = 'http://example.com/path/to/whatever/' hostname = 'example.com' class KeyringMock(object): def __init__(self): p = utils.password_key_prefix self.resources = [ p + 'http://example.com/path/to/whatever/', p + 'http://example.com/path/to/whatever', p + 'http://example.com/path/to/', p + 'http://example.com/path/to', p + 'http://example.com/path/', p + 'http://example.com/path', p + 'http://example.com/', ][:resources_to_test] def get_password(self, resource, _username): assert _username == username assert resource == self.resources.pop(0) if not self.resources: return password monkeypatch.setattr(utils, 'keyring', KeyringMock()) netrc_calls = [] class Netrc(object): def authenticators(self, hostname): netrc_calls.append(hostname) return None monkeypatch.setattr('netrc.netrc', Netrc) monkeypatch.setattr('getpass.getpass', None) _password = utils.get_password(username, resource) assert _password == password assert netrc_calls == [hostname]
def __init__(self, url, username='', password='', collection=None, verify=True, auth=None, useragent=USERAGENT, **kwargs): ''' :param url: Base URL or an URL to a collection. Autodiscovery should be done via :py:meth:`DavStorage.discover`. :param username: Username for authentication. :param password: Password for authentication. :param verify: Verify SSL certificate, default True. :param auth: Authentication method, from {'basic', 'digest'}, default 'basic'. :param useragent: Default 'vdirsyncer'. ''' super(HttpStorage, self).__init__(**kwargs) if username and not password: password = get_password(username, url) self._settings = { 'verify': prepare_verify(verify), 'auth': prepare_auth(auth, username, password) } self.username, self.password = username, password self.useragent = useragent if collection is not None: url = urlparse.urljoin(url, collection) self.url = url self.parsed_url = urlparse.urlparse(self.url) self.collection = collection self._items = {}
def fake_app(ctx): ctx.obj = {'config': ({'password_command': filepath}, {}, {})} _password = utils.get_password(username, resource) assert _password == password
def fake_app(ctx): ctx.obj = {} x = utils.get_password('foouser', 'http://example.com/a/b') click.echo('password is ' + x)
def fake_app(): x = utils.get_password(user, resource) click.echo('Password is {}'.format(x))