From 14f39b80284cfefb211753d1ed36733a31f626ad Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 20 Jan 2023 17:21:29 +0100 Subject: [PATCH 1/3] :tada: Add unit tests for access tokens rpc methods --- .../backend_tests/rpc_access_tokens_test.clj | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 backend/test/backend_tests/rpc_access_tokens_test.clj diff --git a/backend/test/backend_tests/rpc_access_tokens_test.clj b/backend/test/backend_tests/rpc_access_tokens_test.clj new file mode 100644 index 000000000..7868eb179 --- /dev/null +++ b/backend/test/backend_tests/rpc_access_tokens_test.clj @@ -0,0 +1,76 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS INC + +(ns backend-tests.rpc-access-tokens-test + (:require + [app.common.uuid :as uuid] + [app.db :as db] + [app.http :as http] + [app.storage :as sto] + [app.rpc :as-alias rpc] + [backend-tests.helpers :as th] + [clojure.test :as t] + [mockery.core :refer [with-mocks]])) + +(t/use-fixtures :once th/state-init) +(t/use-fixtures :each th/database-reset) + +(t/deftest access-tokens-crud + (let [prof (th/create-profile* 1 {:is-active true}) + team-id (:default-team-id prof) + proj-id (:default-project-id prof) + atoken (atom nil)] + + (t/testing "create access token" + (let [params {::th/type :create-access-token + ::rpc/profile-id (:id prof) + :name "token 1" + :perms ["get-profile"]} + out (th/command! params)] + ;; (th/print-result! out) + (t/is (nil? (:error out))) + + (let [result (:result out)] + (reset! atoken result) + (t/is (contains? result :id)) + (t/is (contains? result :created-at)) + (t/is (contains? result :updated-at)) + (t/is (contains? result :token)) + (t/is (contains? result :perms))))) + + (t/testing "get access token" + (let [params {::th/type :get-access-tokens + ::rpc/profile-id (:id prof)} + out (th/command! params)] + ;; (th/print-result! out) + (t/is (nil? (:error out))) + (let [[result :as results] (:result out)] + (t/is (= 1 (count results))) + (t/is (contains? result :id)) + (t/is (contains? result :created-at)) + (t/is (contains? result :updated-at)) + (t/is (contains? result :token)) + (t/is (contains? result :perms)) + (t/is (= @atoken result))))) + + (t/testing "delete access token" + (let [params {::th/type :delete-access-token + ::rpc/profile-id (:id prof) + :id (:id @atoken)} + out (th/command! params)] + ;; (th/print-result! out) + (t/is (nil? (:error out))) + (t/is (nil? (:result out))))) + + (t/testing "get access token after delete" + (let [params {::th/type :get-access-tokens + ::rpc/profile-id (:id prof)} + out (th/command! params)] + ;; (th/print-result! out) + (t/is (nil? (:error out))) + (let [results (:result out)] + (t/is (= 0 (count results)))))) + )) From fa17ce5d40e8b9bd4ead09c2027cf4f99b3e76cf Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 21 Jan 2023 10:56:47 +0100 Subject: [PATCH 2/3] :paperclip: Avoid email index change on profile indexes migration --- backend/src/app/migrations/sql/0100-mod-profile-indexes.sql | 3 --- 1 file changed, 3 deletions(-) diff --git a/backend/src/app/migrations/sql/0100-mod-profile-indexes.sql b/backend/src/app/migrations/sql/0100-mod-profile-indexes.sql index a27313a0a..2aa84b3e1 100644 --- a/backend/src/app/migrations/sql/0100-mod-profile-indexes.sql +++ b/backend/src/app/migrations/sql/0100-mod-profile-indexes.sql @@ -1,6 +1,3 @@ -DROP INDEX profile__email__idx; -CREATE INDEX profile__email__idx ON profile(email); - ALTER TABLE profile ADD COLUMN default_project_id uuid NULL REFERENCES project(id) ON DELETE SET NULL DEFERRABLE, ADD COLUMN default_team_id uuid NULL REFERENCES team(id) ON DELETE SET NULL DEFERRABLE; From 504f75a1cfea5b9edf6999a1d93f29a9204e32e7 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 23 Jan 2023 09:59:55 +0100 Subject: [PATCH 3/3] :bug: Fix health check http endpoint --- backend/src/app/http/debug.clj | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/backend/src/app/http/debug.clj b/backend/src/app/http/debug.clj index 1d342b9fb..580fefb0f 100644 --- a/backend/src/app/http/debug.clj +++ b/backend/src/app/http/debug.clj @@ -349,15 +349,14 @@ (defn health-handler "Mainly a task that performs a health check." - [{:keys [pool]} _] - (db/with-atomic [conn pool] - (try - (db/exec-one! conn ["select count(*) as count from server_prop;"]) - (yrs/response 200 "OK") - (catch Throwable cause - (l/warn :hint "unable to execute query on health handler" - :cause cause) - (yrs/response 503 "KO"))))) + [{:keys [::db/pool]} _] + (try + (db/exec-one! pool ["select count(*) as count from server_prop;"]) + (yrs/response 200 "OK") + (catch Throwable cause + (l/warn :hint "unable to execute query on health handler" + :cause cause) + (yrs/response 503 "KO")))) (defn changelog-handler [_ _]