-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up handling secrets in files (#332)
- Loading branch information
Showing
2 changed files
with
108 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
;; This file is part of eduhub-mapper | ||
;; | ||
;; Copyright (C) 2022 SURFnet B.V. | ||
;; | ||
;; This program is free software: you can redistribute it and/or | ||
;; modify it under the terms of the GNU Affero General Public License | ||
;; as published by the Free Software Foundation, either version 3 of | ||
;; the License, or (at your option) any later version. | ||
;; | ||
;; This program is distributed in the hope that it will be useful, but | ||
;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
;; Affero General Public License for more details. | ||
;; | ||
;; You should have received a copy of the GNU Affero General Public | ||
;; License along with this program. If not, see | ||
;; <https://www.gnu.org/licenses/>. | ||
|
||
(ns nl.surf.eduhub-rio-mapper.config-test | ||
(:require [clojure.test :refer [deftest is]] | ||
[nl.surf.eduhub-rio-mapper.config :as config]) | ||
(:import [clojure.lang ExceptionInfo] | ||
[java.io File])) | ||
|
||
(def default-env {:surf-conext-introspection-endpoint "https://gateway.dev.surfnet.nl/", | ||
:keystore-alias "default", | ||
:gateway-password "default", | ||
:keystore "test/keystore.jks", | ||
:clients-info-path "test/test-clients.json", | ||
:rio-recipient-oin "default", | ||
:truststore "truststore.jks", | ||
:keystore-password "default", | ||
:rio-update-url "default", | ||
:gateway-user "default", | ||
:surf-conext-client-id "default", | ||
:surf-conext-client-secret "default", | ||
:gateway-root-url "https://gateway.test.surfeduhub.nl/", | ||
:rio-read-url "default"}) | ||
|
||
(def default-expected-value {:keystore-pass "default", | ||
:gateway-credentials | ||
{:password "default", :username "default"}, | ||
:trust-store-pass "repelsteeltje!", | ||
:redis-conn {:spec {:uri "redis://localhost"}}}) | ||
|
||
(defn- test-env [env] | ||
(config/load-config-from-env (merge default-env env))) | ||
|
||
(deftest missing-secret | ||
(is (= {:truststore-password "missing"} | ||
(last (test-env {}))))) | ||
|
||
(deftest only-value-secret | ||
(let [env {:truststore-password "repelsteeltje!"}] | ||
(is (= default-expected-value | ||
(-> env test-env first (select-keys [:keystore-pass :gateway-credentials :trust-store-pass :redis-conn])))))) | ||
|
||
(deftest only-file-secret | ||
(let [path (.getAbsolutePath (File/createTempFile "test-secret" ".txt")) | ||
env {:truststore-password-file path}] | ||
(spit path "repelsteeltje!") | ||
(is (= default-expected-value | ||
(-> env test-env first (select-keys [:keystore-pass :gateway-credentials :trust-store-pass :redis-conn])))))) | ||
|
||
(deftest file-secret-for-env-with-default | ||
(let [path (.getAbsolutePath (File/createTempFile "test-secret" ".txt")) | ||
env {:redis-uri-file path :truststore-password "repelsteeltje!"}] | ||
(spit path "redis://localhost:6381") | ||
(is (= (assoc-in default-expected-value [:redis-conn :spec :uri] "redis://localhost:6381") | ||
(-> env test-env first (select-keys [:keystore-pass :gateway-credentials :trust-store-pass :redis-conn])))))) | ||
|
||
(deftest only-file-secret-file-missing | ||
(let [env {:truststore-password-file "missing-file"}] | ||
(is (thrown? ExceptionInfo (test-env env))))) | ||
|
||
(deftest both-types-of-secret-specified | ||
(let [path (.getAbsolutePath (File/createTempFile "test-secret" ".txt")) | ||
env {:truststore-password "repelsteeltje!" | ||
:truststore-password-file path}] | ||
(spit path "repelsteeltje!") | ||
(is (thrown? ExceptionInfo (test-env env))))) |