MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_security

Method test_security

Lib/test/test_netrc.py:277–310  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

275 @unittest.skipUnless(hasattr(os, 'getuid'), "os.getuid is required")
276 @os_helper.skip_unless_working_chmod
277 def test_security(self):
278 # This test is incomplete since we are normally not run as root and
279 # therefore can't test the file ownership being wrong.
280 d = os_helper.TESTFN
281 os.mkdir(d)
282 self.addCleanup(os_helper.rmtree, d)
283 fn = os.path.join(d, '.netrc')
284 with open(fn, 'wt') as f:
285 f.write("""\
286 machine foo.domain.com login bar password pass
287 default login foo password pass
288 """)
289 with os_helper.EnvironmentVarGuard() as environ:
290 environ.set('HOME', d)
291 os.chmod(fn, 0o600)
292 nrc = netrc.netrc()
293 self.assertEqual(nrc.hosts['foo.domain.com'],
294 ('bar', '', 'pass'))
295 os.chmod(fn, 0o622)
296 self.assertRaises(netrc.NetrcParseError, netrc.netrc)
297 with open(fn, 'wt') as f:
298 f.write("""\
299 machine foo.domain.com login anonymous password pass
300 default login foo password pass
301 """)
302 with os_helper.EnvironmentVarGuard() as environ:
303 environ.set('HOME', d)
304 os.chmod(fn, 0o600)
305 nrc = netrc.netrc()
306 self.assertEqual(nrc.hosts['foo.domain.com'],
307 ('anonymous', '', 'pass'))
308 os.chmod(fn, 0o622)
309 self.assertEqual(nrc.hosts['foo.domain.com'],
310 ('anonymous', '', 'pass'))
311
312
313if __name__ == "__main__":

Callers

nothing calls this directly

Calls 9

addCleanupMethod · 0.80
openFunction · 0.50
mkdirMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45
setMethod · 0.45
chmodMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected