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}.")
91 test "default index includes fetch_url" do
92 authorize_with :active
94 assert_response :success
95 assert_includes(json_response["items"].map { |r| r["fetch_url"] },
96 "git@git.zzzzz.arvadosapi.com:active/foo.git")
100 {cfg: :git_repo_ssh_base, cfgval: "git@example.com:", match: %r"^git@example.com:/"},
101 {cfg: :git_repo_ssh_base, cfgval: true, match: %r"^git@git.zzzzz.arvadosapi.com:/"},
102 {cfg: :git_repo_ssh_base, cfgval: false, refute: /^git@/ },
103 {cfg: :git_repo_https_base, cfgval: "https://example.com/", match: %r"https://example.com/"},
104 {cfg: :git_repo_https_base, cfgval: true, match: %r"^https://git.zzzzz.arvadosapi.com/"},
105 {cfg: :git_repo_https_base, cfgval: false, refute: /^http/ },
107 test "set #{expect[:cfg]} to #{expect[:cfgval]}" do
108 Rails.configuration.send expect[:cfg].to_s+"=", expect[:cfgval]
109 authorize_with :active
111 assert_response :success
112 json_response['items'].each do |r|
114 r['clone_urls'].each do |u|
115 refute_match expect[:refute], u
118 assert r['clone_urls'].any? do |u|
119 expect[:prefix].match u
126 test "select push_url in index" do
127 authorize_with :active
128 get(:index, {select: ["uuid", "push_url"]})
129 assert_response :success
130 assert_includes(json_response["items"].map { |r| r["push_url"] },
131 "git@git.zzzzz.arvadosapi.com:active/foo.git")
134 test "select clone_urls in index" do
135 authorize_with :active
136 get(:index, {select: ["uuid", "clone_urls"]})
137 assert_response :success
138 assert_includes(json_response["items"].map { |r| r["clone_urls"] }.flatten,
139 "git@git.zzzzz.arvadosapi.com:active/foo.git")