Permalink
Browse files

Replace tryclojure with clojail

Fix #711
  • Loading branch information...
devth committed Dec 28, 2017
1 parent 8f5643e commit 63db64018dddc9030e38af85f3d67d3d47e64b86
Showing with 29 additions and 30 deletions.
  1. +3 βˆ’0 .java.policy
  2. +2 βˆ’0 Dockerfile
  3. +13 βˆ’1 project.clj
  4. +5 βˆ’12 src/yetibot/commands/clojure.clj
  5. +6 βˆ’17 test/yetibot/test/commands/clojure.clj
View
@@ -0,0 +1,3 @@
grant {
permission java.security.AllPermission;
};
View
@@ -12,6 +12,8 @@ COPY ./test /usr/src/app/test/
COPY ./project.clj /usr/src/app/project.clj
COPY .java.policy $HOME/
WORKDIR /usr/src/app
RUN lein deps
View
@@ -4,7 +4,7 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:deploy-repositories [["releases" :clojars]]
:jvm-opts []
:jvm-opts ["-Djava.security.policy=.java.policy"]
:profiles {;; optionally override this profile in profiles.clj to be merged
;; into dev profile
:profiles/dev {}
@@ -41,6 +41,18 @@
; emojis
[com.vdurmont/emoji-java "3.3.0"]
; repls
[clojail "1.0.6"
;; clojail hasn't been updated in a long time, so exclude its
;; deps
:exclusions [org.clojure/clojure
org.flatland/useful
;; Note: excluding bultitude disables clojail's
;; `blanket` feature
bultitude
]]
[bultitude "0.2.8"]
;encoding
[org.clojure/data.codec "0.1.0"]]
@@ -1,25 +1,18 @@
(ns yetibot.commands.clojure
(:require
[clojure.string :as s]
[clojail.core :refer [sandbox]]
[clojail.testers :refer [secure-tester]]
[yetibot.core.hooks :refer [cmd-hook]]
[yetibot.core.util.http :refer [get-json map-to-query-string]]))
(def endpoint "http://www.tryclj.com/eval.json")
(defn try-clojure [expr]
(let [uri (str endpoint "?" (map-to-query-string {:expr expr}))]
(get-json uri)))
(def sb (sandbox secure-tester :timeout 5000))
(defn clojure-cmd
"clj <expression> # evaluate a clojure expression"
{:yb/cat #{:broken}}
{:yb/cat #{:util}}
[{:keys [args]}]
"tryclj.com is down :(")
;; (let [json (try-clojure args)]
;; (if (:error json)
;; (:message json)
;; (:result json))))
(pr-str (sb (read-string args))))
(cmd-hook #"clj"
#"\S*" clojure-cmd)
@@ -1,22 +1,11 @@
(ns yetibot.test.commands.clojure
(:require
[midje.sweet :refer [fact => anything]]
[midje.sweet :refer [fact => anything throws]]
[yetibot.commands.clojure :refer :all]
[yetibot.core.util.http :refer [get-json map-to-query-string]]))
))
;; tryclj.com is expired :(
(comment
(fact "should eval as clojure code and return response from real service"
(clojure-cmd {:args "(* 10 2)"}) => "20")
(fact "should eval as clojure code and return response using clojail"
(clojure-cmd {:args "(* 10 2)"}) => "20")
(fact "should eval as clojure code and return response"
(clojure-cmd {:args "(+ 1 2)"}) => "3"
(provided
(get-json anything) => {:expr "(+ 1 2)" :result "3"}))
(fact "should return error message when request fail"
(clojure-cmd {:args "(+ 1 B)"}) => "Error"
(provided
(get-json anything) => {:error true :message "Error"}))
)
(fact "should return error message when request fail"
(clojure-cmd {:args "(+ 1 B)"}) => (throws Exception))

0 comments on commit 63db640

Please sign in to comment.