|
12 | 12 | [cmr.system-int-test.utils.ingest-util :as ingest] |
13 | 13 | [cmr.system-int-test.utils.metadata-db-util :as mdb] |
14 | 14 | [cmr.system-int-test.utils.url-helper :as url] |
15 | | - [cmr.transmit.config :as transmit-config])) |
| 15 | + [cmr.transmit.config :as transmit-config]) |
| 16 | + (:import |
| 17 | + (org.apache.commons.codec.digest DigestUtils))) |
16 | 18 |
|
17 | 19 | (use-fixtures :each (join-fixtures |
18 | 20 | [(ingest/reset-fixture {"provguid1" "PROV1" "provguid2" "PROV2"}) |
|
21 | 23 | (deftest launchpad-user-cache-test |
22 | 24 | (testing "launchpad cache initial value" |
23 | 25 | (let [launchpad-token (echo-util/login-with-launchpad-token (system/context) "user1") |
24 | | - token-key (hash launchpad-token)] |
| 26 | + token-key (keyword (DigestUtils/sha256Hex launchpad-token))] |
25 | 27 | (is (empty? (cache-util/list-cache-keys (url/ingest-read-caches-url) "launchpad-user" transmit-config/mock-echo-system-token))) |
26 | 28 | (let [concept (data-umm-c/collection-concept {}) |
27 | 29 | {:keys [concept-id revision-id]} (ingest/ingest-concept concept {:token launchpad-token})] |
|
84 | 86 | (testing "Transient errors (429, 504) are not cached" |
85 | 87 | (let [resp (ingest/ingest-concept (data-umm-c/collection-concept {}) {:token "ABC-429-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"})] |
86 | 88 | (is (= 429 (:status resp))) |
87 | | - (is (some #(re-find #"Rate limit exceeded" %) (:errors resp)))) |
| 89 | + (is (some #(re-find #"Launchpad rate limit exceeded" %) (:errors resp)))) |
88 | 90 |
|
89 | 91 | (is (empty? (cache-util/list-cache-keys (url/ingest-read-caches-url) "launchpad-user" transmit-config/mock-echo-system-token)))) |
90 | 92 |
|
91 | 93 | (testing "Gateway timeout errors (504) are not cached" |
92 | 94 | (let [resp (ingest/ingest-concept (data-umm-c/collection-concept {}) {:token "ABC-504-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"})] |
93 | 95 | (is (= 504 (:status resp))) |
94 | | - (is (some #(re-find #"Gateway timeout" %) (:errors resp)))) |
| 96 | + (is (some #(re-find #"\(gateway timeout\)" %) (:errors resp)))) |
95 | 97 |
|
96 | 98 | (is (empty? (cache-util/list-cache-keys (url/ingest-read-caches-url) "launchpad-user" transmit-config/mock-echo-system-token))))) |
97 | 99 |
|
98 | 100 | (deftest non-transient-errors-are-cached-test |
99 | 101 | (testing "Non-transient errors are cached for 5 minutes" |
100 | 102 | (let [token "ABC-INV-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ" |
101 | | - token-key (hash token)] |
| 103 | + token-key (keyword (DigestUtils/sha256Hex token))] |
102 | 104 | (let [resp (ingest/ingest-concept (data-umm-c/collection-concept {}) {:token token})] |
103 | 105 | (is (= 401 (:status resp)))) |
104 | 106 |
|
| 107 | + ;; Verify the error is cached |
105 | 108 | (is (seq (cache-util/list-cache-keys (url/ingest-read-caches-url) "launchpad-user" transmit-config/mock-echo-system-token))) |
| 109 | + (let [cached-value (cache-util/get-cache-value |
| 110 | + (url/ingest-read-caches-url) |
| 111 | + "launchpad-user" |
| 112 | + token-key |
| 113 | + transmit-config/mock-echo-system-token |
| 114 | + 200)] |
| 115 | + (is (false? (:valid cached-value))) |
| 116 | + (is (:error-message cached-value)) |
| 117 | + (is (:expiration-time cached-value))) |
106 | 118 |
|
| 119 | + ;; Advance past the 5 minute cache expiration |
107 | 120 | (dev-sys-util/advance-time! 301) |
108 | 121 |
|
| 122 | + ;; After expiration, revalidation fails and cache is evicted (not re-cached) |
109 | 123 | (let [resp (ingest/ingest-concept (data-umm-c/collection-concept {}) {:token token})] |
110 | | - (is (= 401 (:status resp))))))) |
| 124 | + (is (= 401 (:status resp)))) |
| 125 | + |
| 126 | + ;; Verify the cache is now empty after failed revalidation |
| 127 | + (is (empty? (cache-util/list-cache-keys (url/ingest-read-caches-url) "launchpad-user" transmit-config/mock-echo-system-token)))))) |
0 commit comments