Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
5d4b61c7
Commit
5d4b61c7
authored
Feb 19, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better configuration for codejail.
parent
30748a06
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
15 deletions
+54
-15
common/lib/codejail/codejail/django_integration.py
+16
-0
common/lib/codejail/codejail/jailpy.py
+21
-14
common/lib/codejail/codejail/tests/test_jailpy.py
+6
-1
lms/envs/common.py
+11
-0
No files found.
common/lib/codejail/codejail/django_integration.py
0 → 100644
View file @
5d4b61c7
"""Django integration for codejail"""
from
django.core.exceptions
import
MiddlewareNotUsed
from
django.conf
import
settings
import
codejail.jailpy
class
ConfigureCodeJailMiddleware
(
object
):
"""Middleware to configure codejail on startup."""
def
__init__
(
self
):
python_bin
=
settings
.
CODE_JAIL
.
get
(
'python_bin'
)
if
python_bin
:
user
=
settings
.
CODE_JAIL
[
'user'
]
codejail
.
jailpy
.
configure
(
python_bin
,
user
=
user
)
raise
MiddlewareNotUsed
common/lib/codejail/codejail/jailpy.py
View file @
5d4b61c7
...
...
@@ -7,6 +7,7 @@ import os, os.path
import
resource
import
shutil
import
subprocess
import
sys
import
threading
import
time
...
...
@@ -16,21 +17,24 @@ from .util import temp_directory
# Configure the Python command
SANDBOX_POSSIBILITIES
=
[
"~/mitx_all/python-sandbox/bin/python"
,
"/usr/bin/python-sandbox"
,
]
PYTHON_CMD
=
None
for
sandbox_python
in
SANDBOX_POSSIBILITIES
:
sandbox_python
=
os
.
path
.
expanduser
(
sandbox_python
)
if
os
.
path
.
exists
(
sandbox_python
):
PYTHON_CMD
=
[
'sudo'
,
'-u'
,
'sandbox'
,
sandbox_python
,
'-E'
,
]
break
else
:
raise
Exception
(
"Couldn't find Python sandbox"
)
def
configure
(
python_bin
,
user
=
None
):
"""Configure the jailpy module."""
global
PYTHON_CMD
PYTHON_CMD
=
[]
if
user
:
PYTHON_CMD
.
extend
([
'sudo'
,
'-u'
,
'sandbox'
])
PYTHON_CMD
.
extend
([
python_bin
,
'-E'
])
def
is_configured
():
return
bool
(
PYTHON_CMD
)
# By default, look where our current Python is, and maybe there's a
# python-sandbox alongside. Only do this if running in a virtualenv.
if
hasattr
(
sys
,
'real_prefix'
):
if
os
.
path
.
isdir
(
sys
.
prefix
+
"-sandbox"
):
configure
(
sys
.
prefix
+
"-sandbox/bin/python"
,
"sandbox"
)
class
JailResult
(
object
):
...
...
@@ -52,6 +56,9 @@ def jailpy(code, files=None, argv=None, stdin=None):
.status: return status of the process: an int, 0 for successful
"""
if
not
PYTHON_CMD
:
raise
Exception
(
"jailpy needs to be configured"
)
with
temp_directory
(
delete_when_done
=
True
)
as
tmpdir
:
# All the supporting files are copied into our directory.
...
...
common/lib/codejail/codejail/tests/test_jailpy.py
View file @
5d4b61c7
...
...
@@ -4,12 +4,17 @@ import textwrap
import
unittest
from
nose.plugins.skip
import
SkipTest
from
codejail.jailpy
import
jailpy
from
codejail.jailpy
import
jailpy
,
is_configured
dedent
=
textwrap
.
dedent
class
JailPyHelpers
(
object
):
"""Assert helpers for jailpy tests."""
def
setUp
(
self
):
super
(
JailPyHelpers
,
self
)
.
setUp
()
if
not
is_configured
():
raise
SkipTest
def
assertResultOk
(
self
,
res
):
self
.
assertEqual
(
res
.
stderr
,
""
)
self
.
assertEqual
(
res
.
status
,
0
)
...
...
lms/envs/common.py
View file @
5d4b61c7
...
...
@@ -242,6 +242,16 @@ MODULESTORE = {
}
CONTENTSTORE
=
None
#################### Python sandbox ############################################
CODE_JAIL
=
{
# Path to a sandboxed Python executable. None means don't bother.
'python_bin'
:
None
,
# User to run as in the sandbox.
'user'
:
'sandbox'
,
}
############################ SIGNAL HANDLERS ################################
# This is imported to register the exception signal handling that logs exceptions
import
monitoring.exceptions
# noqa
...
...
@@ -385,6 +395,7 @@ MIDDLEWARE_CLASSES = (
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
'django_comment_client.utils.ViewNameMiddleware'
,
'codejail.django_integration.ConfigureCodeJailMiddleware'
,
)
############################### Pipeline #######################################
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment