Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added :init key to execute code in the sandbox without sandboxing.

  • Loading branch information...
commit e9e6654af5bc18d0e7115d83920c7a3fda323b12 1 parent 66b343d
@Raynes Raynes authored
Showing with 10 additions and 4 deletions.
  1. +6 −4 src/clojail/core.clj
  2. +4 −0 test/clojail/core_test.clj
View
10 src/clojail/core.clj
@@ -131,9 +131,11 @@
(let [writer (java.io.StringWriter.)]
(sb '(println \"blah\") {#'*out* writer}) (str writer))
The above example returns \"blah\\n\""
- [& {:keys [timeout namespace context jvm? transform]
- :or {timeout 10000 namespace (gensym "sandbox")
- context (-> (empty-perms-list) domain context) jvm? true
+ [& {:keys [timeout namespace context jvm? transform init]
+ :or {timeout 10000
+ namespace (gensym "sandbox")
+ context (-> (empty-perms-list) domain context)
+ jvm? true
transform eagerly-consume}}]
(when jvm? (enable-security-manager))
(fn [tester code & [bindings]]
@@ -147,6 +149,7 @@
(binding [*ns* (create-ns namespace)
*read-eval* false]
(refer 'clojure.core)
+ (when init (eval init))
(let [bindings (or bindings {})
code
`(do
@@ -167,7 +170,6 @@
[~'obj-class#
~'obj#
(.getPackage ~'obj-class#)])]
-
(throw (SecurityException. (str "You tripped the alarm! " ~'bad# " is bad!")))
(. ~object# ~method# ~@args#))))
~(doseq [[var new-var] bindings]
View
4 test/clojail/core_test.clj
@@ -59,3 +59,7 @@
(deftest namespace-forbid-test
(let [sb (sandbox #{'clojure.core})]
(is (thrown? SecurityException (sb '(+ 1 2))))))
+
+(deftest init-test
+ (let [sb (sandbox secure-tester :init '(def foo 1))]
+ (is (= 1 (sb 'foo)))))
Please sign in to comment.
Something went wrong with that request. Please try again.