PageRenderTime 92ms CodeModel.GetById 50ms app.highlight 21ms RepoModel.GetById 19ms app.codeStats 0ms

/ucengine/src/tests/role_tests.erl

http://github.com/AF83/ucengine
Erlang | 138 lines | 104 code | 17 blank | 17 comment | 0 complexity | 77af4fda65d1ecf10a13140579fc846b MD5 | raw file
  1%%
  2%%  U.C.Engine - Unified Collaboration Engine
  3%%  Copyright (C) 2011 af83
  4%%
  5%%  This program is free software: you can redistribute it and/or modify
  6%%  it under the terms of the GNU Affero General Public License as published by
  7%%  the Free Software Foundation, either version 3 of the License, or
  8%%  (at your option) any later version.
  9%%
 10%%  This program is distributed in the hope that it will be useful,
 11%%  but WITHOUT ANY WARRANTY; without even the implied warranty of
 12%%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13%%  GNU Affero General Public License for more details.
 14%%
 15%%  You should have received a copy of the GNU Affero General Public License
 16%%  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 17%%
 18-module(role_tests).
 19
 20-include("uce.hrl").
 21-include_lib("eunit/include/eunit.hrl").
 22
 23role_test_() ->
 24    { setup
 25    , fun fixtures:setup/0
 26    , fun fixtures:teardown/1
 27    , fun([_, BaseUrl, [Root, _Participant, Ugly|_]]) ->
 28              [?_test(test_add(BaseUrl, Root)),
 29               ?_test(test_add_unauthorized(BaseUrl, Ugly)),
 30               ?_test(test_add_conflict(BaseUrl, Root)),
 31               ?_test(test_add_missing_name(BaseUrl, Root)),
 32
 33               ?_test(test_delete_unauthorized(BaseUrl, Ugly)),
 34               ?_test(test_delete(BaseUrl, Root)),
 35               ?_test(test_delete_not_found(BaseUrl, Root)),
 36
 37               ?_test(test_add_access(BaseUrl, Root)),
 38               ?_test(test_add_access_not_found(BaseUrl, Root)),
 39               ?_test(test_add_access_unauthorized(BaseUrl, Ugly)),
 40               ?_test(test_delete_access(BaseUrl, Root)),
 41               ?_test(test_delete_access_not_found(BaseUrl, Root)),
 42               ?_test(test_delete_access_unauthorized(BaseUrl, Ugly))
 43              ]
 44      end
 45    }.
 46
 47test_add(BaseUrl, {RootUid, RootSid}) ->
 48    Params = [{"uid", RootUid},
 49              {"sid", RootSid},
 50              {"name", "test_role"}],
 51    {struct, [{"result", "created"}]} =
 52        tests_utils:post(BaseUrl, "/role/", Params).
 53
 54test_add_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
 55    Params = [{"uid", UglyUid},
 56              {"sid", UglySid},
 57              {"name", "test_role"}],
 58    {struct, [{"error", "unauthorized"}]} =
 59        tests_utils:post(BaseUrl, "/role/", Params).
 60
 61test_add_conflict(BaseUrl, {RootUid, RootSid}) ->
 62    Params = [{"uid", RootUid},
 63              {"sid", RootSid},
 64              {"name", "test_role"}],
 65    {struct, [{"error", "conflict"}]} =
 66        tests_utils:post(BaseUrl, "/role/", Params).
 67
 68test_add_missing_name(BaseUrl, {RootUid, RootSid}) ->
 69    Params = [{"uid", RootUid},
 70              {"sid", RootSid}],
 71    {struct, [{"error", "missing_parameters"}, {"infos", _}]} =
 72        tests_utils:post(BaseUrl, "/role/", Params).
 73
 74test_delete_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
 75    Params = [{"uid", UglyUid},
 76              {"sid", UglySid}],
 77    {struct, [{"error", "unauthorized"}]} =
 78        tests_utils:delete(BaseUrl, "/role/test_role", Params).
 79
 80test_delete(BaseUrl, {RootUid, RootSid}) ->
 81    Params = [{"uid", RootUid},
 82              {"sid", RootSid}],
 83    {struct, [{"result", "ok"}]} =
 84        tests_utils:delete(BaseUrl, "/role/test_role", Params).
 85
 86test_delete_not_found(BaseUrl, {RootUid, RootSid}) ->
 87    Params = [{"uid", RootUid},
 88              {"sid", RootSid}],
 89    {struct, [{"error", "not_found"}]} =
 90        tests_utils:delete(BaseUrl, "/role/test_role", Params).
 91
 92test_add_access(BaseUrl, {RootUid, RootSid}) ->
 93    Params = [{"uid", RootUid},
 94              {"sid", RootSid},
 95              {"object", "testobject"},
 96              {"action", "testaction"},
 97              {"conditions[a]", "b"}],
 98    {struct, [{"result", "ok"}]} =
 99        tests_utils:post(BaseUrl, "/role/default/acl", Params).
100
101test_add_access_not_found(BaseUrl, {RootUid, RootSid}) ->
102    Params = [{"uid", RootUid},
103              {"sid", RootSid},
104              {"object", "testobject"},
105              {"action", "testaction"},
106              {"conditions[a]", "b"}],
107    {struct, [{"error", "not_found"}]} =
108        tests_utils:post(BaseUrl, "/role/unexistent_role/acl", Params).
109
110test_add_access_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
111    Params = [{"uid", UglyUid},
112              {"sid", UglySid},
113              {"object", "testobject"},
114              {"action", "testaction"},
115              {"conditions[a]", "b"}],
116    {struct, [{"error", "unauthorized"}]} =
117        tests_utils:post(BaseUrl, "/role/default/acl", Params).
118
119test_delete_access(BaseUrl, {RootUid, RootSid}) ->
120    Params = [{"uid", RootUid},
121              {"sid", RootSid},
122              {"conditions[a]", "b"}],
123    {struct, [{"result", "ok"}]} =
124        tests_utils:delete(BaseUrl, "/role/default/acl/testaction/testobject", Params).
125
126test_delete_access_not_found(BaseUrl, {RootUid, RootSid}) ->
127    Params = [{"uid", RootUid},
128              {"sid", RootSid},
129              {"conditions[a]", "b"}],
130    {struct, [{"error", "not_found"}]} =
131        tests_utils:delete(BaseUrl, "/role/unexistent_role/acl/testaction/testobject", Params).
132
133test_delete_access_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
134    Params = [{"uid", UglyUid},
135              {"sid", UglySid},
136              {"conditions[a]", "b"}],
137    {struct, [{"error", "unauthorized"}]} =
138        tests_utils:delete(BaseUrl, "/role/default/acl/testaction/testobject", Params).