Repository navigation
CMR-11629: As a CMR operator I want the CMR to validate EDL JWTs with EDL when local verification is off #2538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
b6cc622
b372241
fa01976
6cd9c88
985003e
3284f4e
fa62e53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| (ns cmr.transmit.test.edl-token-validation | ||
| (:require | ||
| [clojure.test :refer [deftest is testing]] | ||
| [cmr.common.util :as common-util] | ||
| [cmr.transmit.config :as transmit-config] | ||
| [cmr.transmit.http-helper :as http-helper] | ||
| [cmr.transmit.launchpad-user-cache :as launchpad-user-cache] | ||
| [cmr.transmit.tokens :as tokens] | ||
| [cmr.transmit.urs :as urs])) | ||
|
|
||
| (def ^:private token "eyJ0eXAiOiJKV1QifQ.eyJ1aWQiOiJ1c2VyMSJ9.c2lnbmF0dXJlLXZhbHVl") | ||
|
|
||
| (defn- get-token-user | ||
| [response] | ||
| (let [sent (atom nil)] | ||
| (with-redefs [http-helper/request (fn [_ _ request] (reset! sent request) response)] | ||
| [(try | ||
| (urs/get-token-user {} (str "Bearer " token)) | ||
| (catch clojure.lang.ExceptionInfo e (:type (ex-data e)))) | ||
| @sent]))) | ||
|
|
||
| (deftest get-token-user-test | ||
| (let [[result sent] (get-token-user {:status 200 :body {:username "user1" :sub "user1" :active true}})] | ||
| (is (= {:uid "user1"} result)) | ||
| (is (= {:token token} (get-in sent [:http-options :form-params]))) | ||
| (is (= [(transmit-config/urs-username) (transmit-config/urs-password)] | ||
| (get-in sent [:http-options :basic-auth])))) | ||
| (is (= :unauthorized (first (get-token-user {:status 400 :body {:error "invalid_token"}})))) | ||
| (is (= :unauthorized (first (get-token-user {:status 200 :body {:username "user1" :active false}})))) | ||
| (is (= :dependency-failed (first (get-token-user {:status 503 :body ""}))))) | ||
|
|
||
| (deftest jwt-validated-with-edl-when-local-verification-off-test | ||
| (with-redefs [common-util/is-jwt-token? (constantly true) | ||
| transmit-config/local-edl-verification (constantly false) | ||
| launchpad-user-cache/get-edl-token-user (constantly {:uid "edl-user"})] | ||
| (testing "local verification off" | ||
| (is (= "edl-user" (tokens/get-user-id {} token)))))) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| (ns cmr.transmit.test.tokens | ||
| (:require | ||
| [clojure.string :as string] | ||
| [clojure.test :refer [deftest is]] | ||
| [cmr.transmit.tokens :as tokens])) | ||
|
|
||
| (deftest loggable-params-test | ||
| (let [system-token "system-token-0123456789-abcdefghij" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't we have a random text generator for using in tests instead of having a hard coded token?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it probably wouldn't hurt but this is more deterministic. |
||
| user-token "user-token-0123456789-abcdefghij" | ||
| logged (pr-str (#'tokens/loggable-params | ||
| {:connection-manager :pool | ||
| :socket-timeout 1000 | ||
| :headers {"Authorization" system-token "Accept" "application/json"} | ||
| :form-params {:id user-token}}))] | ||
| (is (not (string/includes? logged system-token))) | ||
| (is (not (string/includes? logged user-token))) | ||
| (is (not (string/includes? logged ":connection-manager"))) | ||
| (is (string/includes? logged "application/json")))) | ||
Uh oh!
There was an error while loading. Please reload this page.