1
# Copyright (C) 2008 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
from bzrlib.plugins import netrc_credential_store
27
class TestNetrcCSNoNetrc(tests.TestCaseInTempDir):
29
def test_home_netrc_does_not_exist(self):
30
self.assertRaises(errors.NoSuchFile,
31
config.credential_store_registry.get_credential_store,
35
class TestNetrcCS(tests.TestCaseInTempDir):
38
super(TestNetrcCS, self).setUp()
39
# Create a .netrc file
41
machine host login joe password secret
42
default login anonymous password joe@home
44
f = open(osutils.pathjoin(self.test_home_dir, '.netrc'), 'wb')
46
f.write(netrc_content)
50
def _get_netrc_cs(self):
51
return config.credential_store_registry.get_credential_store('netrc')
53
def test_not_matching_user(self):
54
cs = self._get_netrc_cs()
55
password = cs.decode_password(dict(host='host', user='jim'))
56
self.assertIs(None, password)
58
def test_matching_user(self):
59
cs = self._get_netrc_cs()
60
password = cs.decode_password(dict(host='host', user='joe'))
61
self.assertEquals('secret', password)
63
def test_default_password(self):
64
cs = self._get_netrc_cs()
65
password = cs.decode_password(dict(host='other', user='anonymous'))
66
self.assertEquals('joe@home', password)
68
def test_default_password_without_user(self):
69
cs = self._get_netrc_cs()
70
password = cs.decode_password(dict(host='other'))
71
self.assertIs(None, password)