~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/netrc_credential_store/tests/test_netrc.py

  • Committer: Vincent Ladeuil
  • Date: 2017-01-17 13:48:10 UTC
  • mfrom: (6615.3.6 merges)
  • mto: This revision was merged to the branch mainline in revision 6620.
  • Revision ID: v.ladeuil+lp@free.fr-20170117134810-j9p3lidfy6pfyfsc
Merge 2.7, resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2013, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
43
43
machine host login joe password secret
44
44
default login anonymous password joe@home
45
45
"""
46
 
        f = open(osutils.pathjoin(self.test_home_dir, '.netrc'), 'wb')
47
 
        try:
 
46
        netrc_path = osutils.pathjoin(self.test_home_dir, '.netrc')
 
47
        with open(netrc_path, 'wb') as f:
48
48
            f.write(netrc_content)
49
 
        finally:
50
 
            f.close()
 
49
        # python's netrc will complain about access permissions starting with
 
50
        # 2.7.5-8 so we restrict the access unconditionally
 
51
        osutils.chmod_if_possible(netrc_path, 0600)
51
52
 
52
53
    def _get_netrc_cs(self):
53
54
        return  config.credential_store_registry.get_credential_store('netrc')
60
61
    def test_matching_user(self):
61
62
        cs = self._get_netrc_cs()
62
63
        password = cs.decode_password(dict(host='host', user='joe'))
63
 
        self.assertEquals('secret', password)
 
64
        self.assertEqual('secret', password)
64
65
 
65
66
    def test_default_password(self):
66
67
        cs = self._get_netrc_cs()
67
68
        password = cs.decode_password(dict(host='other', user='anonymous'))
68
 
        self.assertEquals('joe@home', password)
 
69
        self.assertEqual('joe@home', password)
69
70
 
70
71
    def test_default_password_without_user(self):
71
72
        cs = self._get_netrc_cs()
83
84
        conf = config.AuthenticationConfig(_file=StringIO(ac_content))
84
85
        credentials = conf.get_credentials('scheme', 'host', user='joe')
85
86
        self.assertIsNot(None, credentials)
86
 
        self.assertEquals('secret', credentials.get('password', None))
 
87
        self.assertEqual('secret', credentials.get('password', None))