|
| 1 | +(ns clojurewerkz.neocons.rest.test-basic-http-authentication |
| 2 | + (:require [clojurewerkz.neocons.rest :as neorest] |
| 3 | + [clojurewerkz.neocons.rest.nodes :as nodes] |
| 4 | + [slingshot.slingshot :as slingshot]) |
| 5 | + (:import [slingshot ExceptionInfo]) |
| 6 | + (:use clojure.test)) |
| 7 | + |
| 8 | +;; This group of tests assumes you have Nginx or Apache proxy set up at neo4j-proxy.local |
| 9 | +;; that proxies to whatever Neo4J Server installation you want to use. It is excluded from default |
| 10 | +;; test selector and thus CI. Run it using |
| 11 | +;; |
| 12 | +;; TEST_HTTP_AUTHENTICATION=true NEO4J_LOGIN=neocons NEO4J_PASSWORD=SEcRe7 lein2 test :http-auth |
| 13 | +;; |
| 14 | +;; |
| 15 | +;; Example .htpasswd file for Apache or Nginx: |
| 16 | +;; |
| 17 | +;; neocons:$apr1$u9kPE9lO$FABK3Wu7XHSFwuQiepi3M. |
| 18 | +;; |
| 19 | +;; (neocons:SEcRe7) |
| 20 | +;; you can check your HTTP authentication setup using curl like so: |
| 21 | +;; |
| 22 | +;; curl --user neocons:SEcRe7 http://neo4j-proxy.local/db/data/ |
| 23 | +;; curl --user neocons:SEcRe7 http://neo4j-proxy.local/db/data/nodes/1 |
| 24 | + |
| 25 | +(when (get (System/getenv) "TEST_HTTP_AUTHENTICATION") |
| 26 | + (do |
| 27 | + (deftest ^{:http-auth true} test-connection-and-discovery-using-user-info-in-string-uri |
| 28 | + (try |
| 29 | + (neorest/connect! "http://neocons:incorrec7-pazzwd@neo4j-proxy.local/db/data/") |
| 30 | + (catch Exception e |
| 31 | + (let [d (.getData e)] |
| 32 | + (println d) |
| 33 | + (is (= (-> d :object :status) 401)))))) |
| 34 | + |
| 35 | + (deftest ^{:http-auth true} test-connection-and-discovery-using-user-info-in-string-uri |
| 36 | + (try |
| 37 | + (neorest/connect! "http://neocons:SEcRe7@neo4j-proxy.local/db/data/") |
| 38 | + (catch Exception e |
| 39 | + (let [d (.getData e)] |
| 40 | + (println d) |
| 41 | + (is (= (-> d :object :status) 401)))))) |
| 42 | + |
| 43 | + (let [neo4j-login (get (System/getenv) "NEO4J_LOGIN") |
| 44 | + neo4j-password (get (System/getenv) "NEO4J_PASSWORD")] |
| 45 | + (when (and neo4j-login neo4j-password) |
| 46 | + (deftest ^{:http-auth true} test-connection-and-discovery-with-http-credentials-provided-via-env-variables |
| 47 | + (neorest/connect! "http://neo4j-proxy.local/db/data/") |
| 48 | + (is (:version neorest/*endpoint*)) |
| 49 | + (is (:node-uri neorest/*endpoint*)) |
| 50 | + (is (:batch-uri neorest/*endpoint*)) |
| 51 | + (is (:relationship-types-uri neorest/*endpoint*))))) |
| 52 | + |
| 53 | + (deftest ^{:http-auth true} test-connection-and-discovery-with-provided-http-credentials |
| 54 | + (neorest/connect! "http://neo4j-proxy.local/db/data/" "neocons" "SEcRe7") |
| 55 | + (is (:version neorest/*endpoint*)) |
| 56 | + (is (:node-uri neorest/*endpoint*)) |
| 57 | + (is (:batch-uri neorest/*endpoint*)) |
| 58 | + (is (:relationship-types-uri neorest/*endpoint*))) |
| 59 | + |
| 60 | + (neorest/connect! "http://localhost:7474/db/data/" "neocons" "SEcRe7") |
| 61 | + |
| 62 | + (deftest ^{:http-auth true} test-creating-and-immediately-accessing-a-node-without-properties-with-http-auth |
| 63 | + (let [created-node (nodes/create) |
| 64 | + fetched-node (nodes/get (:id created-node))] |
| 65 | + (is (= (:id created-node) (:id fetched-node))))) |
| 66 | + |
| 67 | + (deftest ^{:http-auth true} test-creating-and-immediately-accessing-a-node-with-properties-with-http-auth |
| 68 | + (let [data { :key "value" } |
| 69 | + created-node (nodes/create data) |
| 70 | + fetched-node (nodes/get (:id created-node))] |
| 71 | + (is (= (:id created-node) (:id fetched-node))) |
| 72 | + (is (= (:data created-node) data)))))) |
0 commit comments