PageRenderTime 200ms CodeModel.GetById 21ms RepoModel.GetById 17ms 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. -include("uce.hrl").
  20. -include_lib("eunit/include/eunit.hrl").
  21. role_test_() ->
  22. { setup
  23. , fun fixtures:setup/0
  24. , fun fixtures:teardown/1
  25. , fun([_, BaseUrl, [Root, _Participant, Ugly|_]]) ->
  26. [?_test(test_add(BaseUrl, Root)),
  27. ?_test(test_add_unauthorized(BaseUrl, Ugly)),
  28. ?_test(test_add_conflict(BaseUrl, Root)),
  29. ?_test(test_add_missing_name(BaseUrl, Root)),
  30. ?_test(test_delete_unauthorized(BaseUrl, Ugly)),
  31. ?_test(test_delete(BaseUrl, Root)),
  32. ?_test(test_delete_not_found(BaseUrl, Root)),
  33. ?_test(test_add_access(BaseUrl, Root)),
  34. ?_test(test_add_access_not_found(BaseUrl, Root)),
  35. ?_test(test_add_access_unauthorized(BaseUrl, Ugly)),
  36. ?_test(test_delete_access(BaseUrl, Root)),
  37. ?_test(test_delete_access_not_found(BaseUrl, Root)),
  38. ?_test(test_delete_access_unauthorized(BaseUrl, Ugly))
  39. ]
  40. end
  41. }.
  42. test_add(BaseUrl, {RootUid, RootSid}) ->
  43. Params = [{"uid", RootUid},
  44. {"sid", RootSid},
  45. {"name", "test_role"}],
  46. {struct, [{"result", "created"}]} =
  47. tests_utils:post(BaseUrl, "/role/", Params).
  48. test_add_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
  49. Params = [{"uid", UglyUid},
  50. {"sid", UglySid},
  51. {"name", "test_role"}],
  52. {struct, [{"error", "unauthorized"}]} =
  53. tests_utils:post(BaseUrl, "/role/", Params).
  54. test_add_conflict(BaseUrl, {RootUid, RootSid}) ->
  55. Params = [{"uid", RootUid},
  56. {"sid", RootSid},
  57. {"name", "test_role"}],
  58. {struct, [{"error", "conflict"}]} =
  59. tests_utils:post(BaseUrl, "/role/", Params).
  60. test_add_missing_name(BaseUrl, {RootUid, RootSid}) ->
  61. Params = [{"uid", RootUid},
  62. {"sid", RootSid}],
  63. {struct, [{"error", "missing_parameters"}, {"infos", _}]} =
  64. tests_utils:post(BaseUrl, "/role/", Params).
  65. test_delete_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
  66. Params = [{"uid", UglyUid},
  67. {"sid", UglySid}],
  68. {struct, [{"error", "unauthorized"}]} =
  69. tests_utils:delete(BaseUrl, "/role/test_role", Params).
  70. test_delete(BaseUrl, {RootUid, RootSid}) ->
  71. Params = [{"uid", RootUid},
  72. {"sid", RootSid}],
  73. {struct, [{"result", "ok"}]} =
  74. tests_utils:delete(BaseUrl, "/role/test_role", Params).
  75. test_delete_not_found(BaseUrl, {RootUid, RootSid}) ->
  76. Params = [{"uid", RootUid},
  77. {"sid", RootSid}],
  78. {struct, [{"error", "not_found"}]} =
  79. tests_utils:delete(BaseUrl, "/role/test_role", Params).
  80. test_add_access(BaseUrl, {RootUid, RootSid}) ->
  81. Params = [{"uid", RootUid},
  82. {"sid", RootSid},
  83. {"object", "testobject"},
  84. {"action", "testaction"},
  85. {"conditions[a]", "b"}],
  86. {struct, [{"result", "ok"}]} =
  87. tests_utils:post(BaseUrl, "/role/default/acl", Params).
  88. test_add_access_not_found(BaseUrl, {RootUid, RootSid}) ->
  89. Params = [{"uid", RootUid},
  90. {"sid", RootSid},
  91. {"object", "testobject"},
  92. {"action", "testaction"},
  93. {"conditions[a]", "b"}],
  94. {struct, [{"error", "not_found"}]} =
  95. tests_utils:post(BaseUrl, "/role/unexistent_role/acl", Params).
  96. test_add_access_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
  97. Params = [{"uid", UglyUid},
  98. {"sid", UglySid},
  99. {"object", "testobject"},
  100. {"action", "testaction"},
  101. {"conditions[a]", "b"}],
  102. {struct, [{"error", "unauthorized"}]} =
  103. tests_utils:post(BaseUrl, "/role/default/acl", Params).
  104. test_delete_access(BaseUrl, {RootUid, RootSid}) ->
  105. Params = [{"uid", RootUid},
  106. {"sid", RootSid},
  107. {"conditions[a]", "b"}],
  108. {struct, [{"result", "ok"}]} =
  109. tests_utils:delete(BaseUrl, "/role/default/acl/testaction/testobject", Params).
  110. test_delete_access_not_found(BaseUrl, {RootUid, RootSid}) ->
  111. Params = [{"uid", RootUid},
  112. {"sid", RootSid},
  113. {"conditions[a]", "b"}],
  114. {struct, [{"error", "not_found"}]} =
  115. tests_utils:delete(BaseUrl, "/role/unexistent_role/acl/testaction/testobject", Params).
  116. test_delete_access_unauthorized(BaseUrl, {UglyUid, UglySid}) ->
  117. Params = [{"uid", UglyUid},
  118. {"sid", UglySid},
  119. {"conditions[a]", "b"}],
  120. {struct, [{"error", "unauthorized"}]} =
  121. tests_utils:delete(BaseUrl, "/role/default/acl/testaction/testobject", Params).