Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_save_load_jobs():
jobs = [
UrlJob(name='news', url='http://news.orf.at/'),
ShellJob(name='list homedir', command='ls ~'),
ShellJob(name='list proc', command='ls /proc'),
]
# tempfile.NamedTemporaryFile() doesn't work on Windows
# because the returned file object cannot be opened again
fd, name = tempfile.mkstemp()
UrlsYaml(name).save(jobs)
jobs2 = UrlsYaml(name).load()
os.chmod(name, 0o777)
jobs3 = UrlsYaml(name).load_secure()
os.close(fd)
os.remove(name)
assert len(jobs2) == len(jobs)
# Assert that the shell jobs have been removed due to secure loading
if sys.platform != 'win32':
def test_save_load_jobs():
jobs = [
UrlJob(name='news', url='http://news.orf.at/'),
ShellJob(name='list homedir', command='ls ~'),
ShellJob(name='list proc', command='ls /proc'),
]
# tempfile.NamedTemporaryFile() doesn't work on Windows
# because the returned file object cannot be opened again
fd, name = tempfile.mkstemp()
UrlsYaml(name).save(jobs)
jobs2 = UrlsYaml(name).load()
os.chmod(name, 0o777)
jobs3 = UrlsYaml(name).load_secure()
os.close(fd)
os.remove(name)
assert len(jobs2) == len(jobs)
# Assert that the shell jobs have been removed due to secure loading
if sys.platform != 'win32':
assert len(jobs3) == 1