diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-09-16 17:48:44 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-09-16 17:48:44 (GMT) |
commit | 4189b67a66afc7a5d4ed9ef39c9f8187d98e7909 (patch) | |
tree | 202254f086d26dabc01be2f2abb331cd996f829e /Lib/test | |
parent | 503baf9ecd2cc5fb0bb85cec99c300862c02de85 (diff) | |
download | cpython-4189b67a66afc7a5d4ed9ef39c9f8187d98e7909.zip cpython-4189b67a66afc7a5d4ed9ef39c9f8187d98e7909.tar.gz cpython-4189b67a66afc7a5d4ed9ef39c9f8187d98e7909.tar.bz2 |
#14984: On POSIX, enforce permissions when reading default .netrc.
Initial patch by Bruno Piguet.
This is implemented as if a useful .netrc file could exist without passwords,
which is possible in the general case; but in fact our netrc implementation
does not support it. Fixing that issue will be an enhancement.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_netrc.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/test/test_netrc.py b/Lib/test/test_netrc.py index b536255..24ad786 100644 --- a/Lib/test/test_netrc.py +++ b/Lib/test/test_netrc.py @@ -32,7 +32,7 @@ class NetrcTestCase(unittest.TestCase): def tearDown (self): del self.netrc - os.unlink(temp_filename) + test_support.unlink(temp_filename) def test_case_1(self): self.assert_(self.netrc.macros == {'macro1':['line1\n', 'line2\n'], @@ -41,6 +41,27 @@ class NetrcTestCase(unittest.TestCase): self.assert_(self.netrc.hosts['foo'] == ('log1', 'acct1', 'pass1')) self.assert_(self.netrc.hosts['default'] == ('log2', None, 'pass2')) + if os.name == 'posix': + def test_security(self): + # This test is incomplete since we are normally not run as root and + # therefore can't test the file ownership being wrong. + os.unlink(temp_filename) + d = test_support.TESTFN + try: + os.mkdir(d) + fn = os.path.join(d, '.netrc') + with open(fn, 'wt') as f: + f.write(TEST_NETRC) + with test_support.EnvironmentVarGuard() as environ: + environ.set('HOME', d) + os.chmod(fn, 0600) + self.netrc = netrc.netrc() + self.test_case_1() + os.chmod(fn, 0622) + self.assertRaises(netrc.NetrcParseError, netrc.netrc) + finally: + test_support.rmtree(d) + def test_main(): test_support.run_unittest(NetrcTestCase) |