-
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.
Refactored config secret file loading
- Loading branch information
Showing
3 changed files
with
112 additions
and
80 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
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,71 @@ | ||
;; This file is part of eduhub-validator-service | ||
;; | ||
;; 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.validator.service.config-test | ||
(:require [clojure.test :refer [deftest is]] | ||
[nl.surf.eduhub.validator.service.config :as config] | ||
[nl.surf.eduhub.validator.service.main :as main]) | ||
(:import [clojure.lang ExceptionInfo] | ||
[java.io File])) | ||
|
||
(def app (main/wrap-validator main/app-routes {})) | ||
|
||
(def default-env {:allowed-client-ids "default", | ||
:gateway-basic-auth-pass "default", | ||
:gateway-url "default", | ||
:ooapi-version "default", | ||
:surf-conext-client-id "default", | ||
:surf-conext-client-secret "default", | ||
:surf-conext-introspection-endpoint "default"}) | ||
|
||
(def default-expected-value {:allowed-client-ids "default", | ||
:gateway-url "default", | ||
:ooapi-version "default", | ||
:gateway-basic-auth {:pass "default", :user "john200"}, | ||
:introspection-basic-auth {:pass "default", :user "default"}, | ||
:introspection-endpoint-url "default"}) | ||
|
||
(defn- test-env [env] | ||
(config/load-config-from-env (merge default-env env))) | ||
|
||
(deftest missing-secret | ||
(is (= {:gateway-basic-auth-user "missing"} | ||
(last (test-env {}))))) | ||
|
||
(deftest only-value-secret | ||
(let [env {:gateway-basic-auth-user "john200"}] | ||
(is (= [default-expected-value] | ||
(test-env env))))) | ||
|
||
(deftest only-file-secret | ||
(let [path (.getAbsolutePath (File/createTempFile "test-secret" ".txt")) | ||
env {:gateway-basic-auth-user-file path}] | ||
(spit path "john200") | ||
(is (= [default-expected-value] | ||
(test-env env))))) | ||
|
||
(deftest only-file-secret-file-missing | ||
(let [env {:gateway-basic-auth-user-file "missing-file"}] | ||
(is (thrown? ExceptionInfo (test-env env))))) | ||
|
||
(deftest both-types-of-secret-specified | ||
(let [path (.getAbsolutePath (File/createTempFile "test-secret" ".txt")) | ||
env {:gateway-basic-auth-user "john200" | ||
:gateway-basic-auth-user-file path}] | ||
(spit path "john200") | ||
(is (thrown? ExceptionInfo (test-env env))))) |