X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2f3e496712802324e5d184f9ae59866df1772ef0..39507a40922e11e6863e4dd788ad3231e6fb3224:/services/api/test/functional/arvados/v1/api_client_authorizations_controller_test.rb diff --git a/services/api/test/functional/arvados/v1/api_client_authorizations_controller_test.rb b/services/api/test/functional/arvados/v1/api_client_authorizations_controller_test.rb index 0072792563..8877719b5b 100644 --- a/services/api/test/functional/arvados/v1/api_client_authorizations_controller_test.rb +++ b/services/api/test/functional/arvados/v1/api_client_authorizations_controller_test.rb @@ -37,22 +37,33 @@ class Arvados::V1::ApiClientAuthorizationsControllerTest < ActionController::Tes assert_response 403 end - test "admin search filters where scopes exactly match" do - def check_tokens_by_scopes(scopes, *expected_tokens) - expected_tokens.map! { |name| api_client_authorizations(name).api_token } - get :index, where: {scopes: scopes} - assert_response :success - got_tokens = JSON.parse(@response.body)['items'] - .map { |auth| auth['api_token'] } - assert_equal(expected_tokens.sort, got_tokens.sort, - "wrong results for scopes = #{scopes}") + def assert_found_tokens(auth, search_params, *expected_tokens) + authorize_with auth + expected_tokens.map! { |name| api_client_authorizations(name).api_token } + get :index, search_params + assert_response :success + got_tokens = JSON.parse(@response.body)['items'] + .map { |auth| auth['api_token'] } + assert_equal(expected_tokens.sort, got_tokens.sort, + "wrong results for #{search_params.inspect}") + end + + # Three-tuples with auth to use, scopes to find, and expected tokens. + # Make two tests for each tuple, one searching with where and the other + # with filter. + [[:admin_trustedclient, [], :admin_noscope], + [:active_trustedclient, ["GET /arvados/v1/users"], :active_userlist], + [:active_trustedclient, + ["POST /arvados/v1/api_client_authorizations", + "GET /arvados/v1/api_client_authorizations"], + :active_apitokens], + ].each do |auth, scopes, *expected| + test "#{auth.to_s} can find auths where scopes=#{scopes.inspect}" do + assert_found_tokens(auth, {where: {scopes: scopes}}, *expected) + end + + test "#{auth.to_s} can find auths filtered with scopes=#{scopes.inspect}" do + assert_found_tokens(auth, {filters: [['scopes', '=', scopes]]}, *expected) end - authorize_with :admin_trustedclient - check_tokens_by_scopes([], :admin_noscope) - authorize_with :active_trustedclient - check_tokens_by_scopes(["GET /arvados/v1/users"], :active_userlist) - check_tokens_by_scopes(["POST /arvados/v1/api_client_authorizations", - "GET /arvados/v1/api_client_authorizations"], - :active_apitokens) end end