Skip to content

Commit

Permalink
Merge pull request #495 from edx/dcs/config-perm
Browse files Browse the repository at this point in the history
Check for file permissions
  • Loading branch information
davestgermain authored Dec 26, 2018
2 parents be2e2d9 + 5c98198 commit bf05a9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 9 additions & 4 deletions edx_proctoring/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ def make_worker_config(backends, out='/tmp/workers.json'):
except KeyError:
warnings.warn('%r does not contain a `main` entry' % package_file)
if config:
with open(out, 'wb') as outfp:
json.dump(config, outfp)
os.chmod(out, 0o664)
return True
try:
with open(out, 'wb+') as outfp:
json.dump(config, outfp)
except IOError:
warnings.warn("Could not write worker config to %s" % out)
else:
# make sure that this file is group writable, because it may be written by different users
os.chmod(out, 0o664)
return True
return False


Expand Down
7 changes: 7 additions & 0 deletions edx_proctoring/tests/test_workerconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ def test_no_module(self):
self.assertFalse(make_worker_config([backend], self.outfile))
self._check_outfile(None)

def test_no_permission(self):
self.outfile = '/etc/workers-test.json'
backend = TestBackendProvider()
backend.npm_module = self._make_npm_module('test-1234', 'foo/bar/baz.js')
self.assertFalse(make_worker_config([backend], self.outfile))
self._check_outfile(None)

@patch('django.conf.settings.NODE_MODULES_ROOT', None)
def test_no_setting(self):
backend = TestBackendProvider()
Expand Down

0 comments on commit bf05a9e

Please sign in to comment.