|
1 | | -;(ns cmr.access-control.int-test.access-control-group-member-test |
2 | | -; (:require |
3 | | -; [clojure.test :refer [deftest is testing use-fixtures]] |
4 | | -; [cmr.mock-echo.client.echo-util :as e] |
5 | | -; [cmr.access-control.int-test.fixtures :as fixtures] |
6 | | -; [cmr.access-control.test.util :as u])) |
7 | | -; |
8 | | -;(use-fixtures :once (fixtures/int-test-fixtures)) |
9 | | -;(use-fixtures :each |
10 | | -; (fixtures/reset-fixture {"prov1guid" "PROV1"} ["user1" "user2" "user3" "user4" "user5"]) |
11 | | -; (fixtures/grant-all-group-fixture ["PROV1"])) |
12 | | -; |
13 | | -;(defn- assert-group-member-count-correct |
14 | | -; "Asserts that when retrieving the group the correct number of members is returned." |
15 | | -; [token concept-id num-expected] |
16 | | -; (is (= num-expected (:num_members (u/get-group token concept-id))))) |
17 | | -; |
18 | | -;(deftest group-members-test |
19 | | -; (let [token (e/login (u/conn-context) "user1") |
20 | | -; group (u/make-group) |
21 | | -; {:keys [concept_id]} (u/create-group token group)] |
22 | | -; |
23 | | -; (testing "Initially no members are in the group" |
24 | | -; (assert-group-member-count-correct token concept_id 0) |
25 | | -; (is (= {:status 200 :body []} (u/get-members token concept_id)))) |
26 | | -; |
27 | | -; (testing "Successful add members to group" |
28 | | -; (let [response (u/add-members token concept_id ["user1" "user2" "user1"])] |
29 | | -; (assert-group-member-count-correct token concept_id 2) |
30 | | -; (is (= {:status 200 :concept_id concept_id :revision_id 2} response)) |
31 | | -; (is (= {:status 200 :body ["user1" "user2"]} (u/get-members token concept_id))))) |
32 | | -; |
33 | | -; (testing "Add more members to the group" |
34 | | -; (let [response (u/add-members token concept_id ["user3" "user4" "user3" "user1"])] |
35 | | -; (assert-group-member-count-correct token concept_id 4) |
36 | | -; (is (= {:status 200 :concept_id concept_id :revision_id 3} response)) |
37 | | -; (is (= {:status 200 :body ["user1" "user2" "user3" "user4"]} (u/get-members token concept_id))))) |
38 | | -; |
39 | | -; (testing "Add members that do not exist" |
40 | | -; (is (= {:status 400 |
41 | | -; :errors ["The following users do not exist [notexist1, notexist2]"]} |
42 | | -; (u/add-members |
43 | | -; token concept_id |
44 | | -; ["notexist1" "user1" "notexist2" "user2" "notexist2"]))) |
45 | | -; (assert-group-member-count-correct token concept_id 4)) |
46 | | -; |
47 | | -; (testing "Removing members" |
48 | | -; ;; Removing duplicates, members not in the group, and non-existent users is allowed. |
49 | | -; (let [response (u/remove-members token concept_id |
50 | | -; ["user3" |
51 | | -; "user1" |
52 | | -; "user3" ; duplicate |
53 | | -; "notexist3" ; doesn't exist |
54 | | -; "user5"])] ; exists but not in group |
55 | | -; (assert-group-member-count-correct token concept_id 2) |
56 | | -; (is (= {:status 200 :concept_id concept_id :revision_id 4} response)) |
57 | | -; (is (= {:status 200 :body ["user2" "user4"]} (u/get-members token concept_id))))) |
58 | | -; |
59 | | -; (testing "Add and remove with a deleted group" |
60 | | -; (is (= 200 (:status (u/delete-group token concept_id)))) |
61 | | -; (is (= {:status 404 |
62 | | -; :errors [(format "Group with concept id [%s] was deleted." concept_id)]} |
63 | | -; (u/add-members token concept_id ["user1"]))) |
64 | | -; (is (= {:status 404 |
65 | | -; :errors [(format "Group with concept id [%s] was deleted." concept_id)]} |
66 | | -; (u/remove-members token concept_id ["user1"])))) |
67 | | -; |
68 | | -; (testing "Add and remove with a non existent group" |
69 | | -; (is (= {:status 404 |
70 | | -; :errors ["Group could not be found with concept id [AG1234-CMR]"]} |
71 | | -; (u/add-members token "AG1234-CMR" ["user1"]))) |
72 | | -; (is (= {:status 404 |
73 | | -; :errors ["Group could not be found with concept id [AG1234-CMR]"]} |
74 | | -; (u/remove-members token "AG1234-CMR" ["user1"])))))) |
| 1 | +(ns cmr.access-control.int-test.access-control-group-member-test |
| 2 | + (:require |
| 3 | + [clojure.test :refer [deftest is testing use-fixtures]] |
| 4 | + [cmr.mock-echo.client.echo-util :as e] |
| 5 | + [cmr.access-control.int-test.fixtures :as fixtures] |
| 6 | + [cmr.access-control.test.util :as u])) |
| 7 | + |
| 8 | +(use-fixtures :once (fixtures/int-test-fixtures)) |
| 9 | +(use-fixtures :each |
| 10 | + (fixtures/reset-fixture {"prov1guid" "PROV1"} ["user1" "user2" "user3" "user4" "user5"]) |
| 11 | + (fixtures/grant-all-group-fixture ["PROV1"])) |
| 12 | + |
| 13 | +(defn- assert-group-member-count-correct |
| 14 | + "Asserts that when retrieving the group the correct number of members is returned." |
| 15 | + [token concept-id num-expected] |
| 16 | + (is (= num-expected (:num_members (u/get-group token concept-id))))) |
| 17 | + |
| 18 | +(deftest group-members-test |
| 19 | + (let [token (e/login (u/conn-context) "user1") |
| 20 | + group (u/make-group) |
| 21 | + {:keys [concept_id]} (u/create-group token group)] |
| 22 | + |
| 23 | + (testing "Initially no members are in the group" |
| 24 | + (assert-group-member-count-correct token concept_id 0) |
| 25 | + (is (= {:status 200 :body []} (u/get-members token concept_id)))) |
| 26 | + |
| 27 | + (testing "Successful add members to group" |
| 28 | + (let [response (u/add-members token concept_id ["user1" "user2" "user1"])] |
| 29 | + (assert-group-member-count-correct token concept_id 2) |
| 30 | + (is (= {:status 200 :concept_id concept_id :revision_id 2} response)) |
| 31 | + (is (= {:status 200 :body ["user1" "user2"]} (u/get-members token concept_id))))) |
| 32 | + |
| 33 | + (testing "Add more members to the group" |
| 34 | + (let [response (u/add-members token concept_id ["user3" "user4" "user3" "user1"])] |
| 35 | + (assert-group-member-count-correct token concept_id 4) |
| 36 | + (is (= {:status 200 :concept_id concept_id :revision_id 3} response)) |
| 37 | + (is (= {:status 200 :body ["user1" "user2" "user3" "user4"]} (u/get-members token concept_id))))) |
| 38 | + |
| 39 | + (testing "Add members that do not exist" |
| 40 | + (is (= {:status 400 |
| 41 | + :errors ["The following users do not exist [notexist1, notexist2]"]} |
| 42 | + (u/add-members |
| 43 | + token concept_id |
| 44 | + ["notexist1" "user1" "notexist2" "user2" "notexist2"]))) |
| 45 | + (assert-group-member-count-correct token concept_id 4)) |
| 46 | + |
| 47 | + (testing "Removing members" |
| 48 | + ;; Removing duplicates, members not in the group, and non-existent users is allowed. |
| 49 | + (let [response (u/remove-members token concept_id |
| 50 | + ["user3" |
| 51 | + "user1" |
| 52 | + "user3" ; duplicate |
| 53 | + "notexist3" ; doesn't exist |
| 54 | + "user5"])] ; exists but not in group |
| 55 | + (assert-group-member-count-correct token concept_id 2) |
| 56 | + (is (= {:status 200 :concept_id concept_id :revision_id 4} response)) |
| 57 | + (is (= {:status 200 :body ["user2" "user4"]} (u/get-members token concept_id))))) |
| 58 | + |
| 59 | + (testing "Add and remove with a deleted group" |
| 60 | + (is (= 200 (:status (u/delete-group token concept_id)))) |
| 61 | + (is (= {:status 404 |
| 62 | + :errors [(format "Group with concept id [%s] was deleted." concept_id)]} |
| 63 | + (u/add-members token concept_id ["user1"]))) |
| 64 | + (is (= {:status 404 |
| 65 | + :errors [(format "Group with concept id [%s] was deleted." concept_id)]} |
| 66 | + (u/remove-members token concept_id ["user1"])))) |
| 67 | + |
| 68 | + (testing "Add and remove with a non existent group" |
| 69 | + (is (= {:status 404 |
| 70 | + :errors ["Group could not be found with concept id [AG1234-CMR]"]} |
| 71 | + (u/add-members token "AG1234-CMR" ["user1"]))) |
| 72 | + (is (= {:status 404 |
| 73 | + :errors ["Group could not be found with concept id [AG1234-CMR]"]} |
| 74 | + (u/remove-members token "AG1234-CMR" ["user1"])))))) |
0 commit comments