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
46 viewer_uuid = users(:project_viewer).uuid
47 assert_equal(authorized_keys(:project_viewer).authorized_user_uuid,
49 "project_viewer must have an authorized_key for this test to work")
51 get :get_all_permissions
52 assert_response :success
53 readable_repos = json_response["repositories"].select do |repo|
54 repo["user_permissions"].has_key?(viewer_uuid)
56 assert_equal(["arvados"], readable_repos.map { |r| r["name"] },
57 "project_viewer should only have permissions on public repos")
60 test "get_all_permissions gives gitolite R to user with read-only access" do
62 get :get_all_permissions
63 assert_response :success
65 assert_equal(authorized_keys(:spectator).authorized_user_uuid,
66 users(:spectator).uuid,
67 "spectator must have an authorized_key for this test to work")
68 json_response['repositories'].each do |repo|
69 next unless repo['uuid'] == repositories(:foo).uuid
71 repo['user_permissions'][users(:spectator).uuid]['gitolite_permissions'],
72 "spectator user should have just R access to #{repo['uuid']}")
75 assert_equal true, found_it, "spectator user does not have R on foo repo"
78 test "get_all_permissions provides admin and active user keys" do
80 get :get_all_permissions
81 assert_response :success
82 [:active, :admin].each do |u|
83 assert_equal(1, json_response['user_keys'][users(u).uuid].andand.count,
84 "expected 1 key for #{u} (#{users(u).uuid})")
85 assert_equal(json_response['user_keys'][users(u).uuid][0]['public_key'],
86 authorized_keys(u).public_key,
87 "response public_key does not match fixture #{u}.")