3 class Arvados::V1::RepositoriesControllerTest < ActionController::TestCase
4 test "should get_all_logins with admin token" do
6 get :get_all_permissions
7 assert_response :success
10 test "should get_all_logins with non-admin token" do
11 authorize_with :active
12 get :get_all_permissions
16 test "get_all_permissions gives RW to repository owner" do
18 get :get_all_permissions
19 assert_response :success
21 json_response['repositories'].each do |repo|
22 if repo['uuid'] == repositories(:repository2).uuid
23 if repo['user_permissions'][users(:active).uuid]['can_write']
28 assert_equal(true, ok,
29 "No permission on own repo '@{repositories(:repository2).uuid}'")
32 test "get_all_permissions takes into account is_admin flag" do
34 get :get_all_permissions
35 assert_response :success
36 json_response['repositories'].each do |repo|
37 assert_not_nil(repo['user_permissions'][users(:admin).uuid],
38 "Admin user is not listed in perms for #{repo['uuid']}")
40 repo['user_permissions'][users(:admin).uuid]['can_write'],
41 "Admin has no perms for #{repo['uuid']}")
45 test "get_all_permissions does not give any access to user without permission" do
47 get :get_all_permissions
48 assert_response :success
49 assert_equal(authorized_keys(:project_viewer).authorized_user_uuid,
50 users(:project_viewer).uuid,
51 "project_viewer must have an authorized_key for this test to work")
52 json_response['repositories'].each do |repo|
54 repo['user_permissions'].has_key?(users(:project_viewer).uuid),
55 "project_viewer user should not have perms for #{repo['uuid']}")
59 test "get_all_permissions gives gitolite R to user with read-only access" do
61 get :get_all_permissions
62 assert_response :success
64 assert_equal(authorized_keys(:spectator).authorized_user_uuid,
65 users(:spectator).uuid,
66 "spectator must have an authorized_key for this test to work")
67 json_response['repositories'].each do |repo|
68 next unless repo['uuid'] == repositories(:foo).uuid
70 repo['user_permissions'][users(:spectator).uuid]['gitolite_permissions'],
71 "spectator user should have just R access to #{repo['uuid']}")
74 assert_equal true, found_it, "spectator user does not have R on foo repo"
77 test "get_all_permissions provides admin and active user keys" do
79 get :get_all_permissions
80 assert_response :success
81 [:active, :admin].each do |u|
82 assert_equal(1, json_response['user_keys'][users(u).uuid].andand.count,
83 "expected 1 key for #{u} (#{users(u).uuid})")
84 assert_equal(json_response['user_keys'][users(u).uuid][0]['public_key'],
85 authorized_keys(u).public_key,
86 "response public_key does not match fixture #{u}.")