-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0022108
commit dffd2ac
Showing
12 changed files
with
116 additions
and
17 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
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
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,35 @@ | ||
(ns swlkup.resolver.root.ngo.invalidate-token | ||
(:require [clojure.spec.alpha :as s] | ||
[specialist-server.type :as t] | ||
[swlkup.auth.core :refer [auth+role->entity]] | ||
[swlkup.model.token :as token] | ||
[swlkup.model.auth :as auth] | ||
[swlkup.model.ngo :as ngo] | ||
[xtdb.api :as xt])) | ||
|
||
(s/fdef invalidate_token | ||
:args (s/tuple map? (s/keys :req-un [::auth/auth ::token/token]) map? map?) | ||
:ret t/boolean) | ||
|
||
(defn invalidate_token | ||
[_node opt ctx _info] | ||
(let [{:keys [q_id_unary tx-fn-put tx-fn-call sync]} (:db_ctx ctx) | ||
[ngo:id] (auth+role->entity ctx (:auth opt) ::ngo/doc) | ||
token:id (q_id_unary '{:find [?id] | ||
:where [[?t :xt/spec :swlkup.model.token/doc] | ||
[?t :ngo ->ngo:id] | ||
[?t :token ->token] | ||
[?t :xt/id ?id]] | ||
:in [[->ngo:id ->token]]} | ||
[ngo:id (:token opt)]) ;; Tuple binding | ||
tx_result (when token:id | ||
(tx-fn-put :invalidate-token | ||
'(fn [ctx eid] | ||
(let [db (xtdb.api/db ctx) | ||
entity (xtdb.api/entity db eid)] | ||
[[::xt/put (assoc entity :valid false)]]))) | ||
(tx-fn-call :invalidate-token token:id))] | ||
(sync) | ||
(boolean (:xtdb.api/tx-id tx_result)))) | ||
|
||
(s/def ::invalidate_token (t/resolver #'invalidate_token)) |
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,23 @@ | ||
(ns swlkup.resolver.token-invalidate-test | ||
(:require [clojure.test :refer [use-fixtures deftest is]] | ||
[mount.core :as mount] | ||
[swlkup.resolver.core :refer [graphql]])) | ||
|
||
(def mail "[email protected]") | ||
(def password "Vr(+cFtUG=rsj2:/]*uR") | ||
(def token "InvalidateTest") | ||
|
||
(use-fixtures :once (fn [testcases] (mount/stop) (mount/start) (testcases) (mount/stop))) | ||
|
||
(deftest invalidation | ||
|
||
(is (= (graphql {:query (str "{lookup(token: \"" token "\") {ngo{name}}}")}) | ||
{:data {:lookup {:ngo {:name "Example NGO"}}}})) | ||
|
||
(is (= (graphql {:query "mutation Invalidate($auth: Auth!, $token:String!) { invalidate_token(auth: $auth, token: $token) }" | ||
:variables {:auth {:mail mail :password password} | ||
:token token}}) | ||
{:data {:invalidate_token true}})) | ||
|
||
(is (= (graphql {:query (str "{lookup(token: \"" token "\") {ngo{name}}}")}) | ||
{:data {:lookup {:ngo nil}}}))) |
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