X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/44c95f99098fa6c6acbfa82d4b6cbc6015eb6e39..f28c121ae84586bec9cbadcfc5b296f563818112:/services/api/test/unit/api_client_authorization_test.rb diff --git a/services/api/test/unit/api_client_authorization_test.rb b/services/api/test/unit/api_client_authorization_test.rb index 51a6ff3ba8..e043f8914a 100644 --- a/services/api/test/unit/api_client_authorization_test.rb +++ b/services/api/test/unit/api_client_authorization_test.rb @@ -18,4 +18,38 @@ class ApiClientAuthorizationTest < ActiveSupport::TestCase assert_empty ApiClientAuthorization.where(api_token: newtoken), "Destroyed ApiClientAuth is still in database" end end + + test "accepts SystemRootToken" do + assert_nil ApiClientAuthorization.validate(token: "xxxSystemRootTokenxxx") + + # will create a new ApiClientAuthorization record + Rails.configuration.SystemRootToken = "xxxSystemRootTokenxxx" + + auth = ApiClientAuthorization.validate(token: "xxxSystemRootTokenxxx") + assert_equal "xxxSystemRootTokenxxx", auth.api_token + assert_equal User.find_by_uuid(system_user_uuid).id, auth.user_id + assert auth.api_client.is_trusted + + # now change the token and try to use the old one first + Rails.configuration.SystemRootToken = "newxxxSystemRootTokenxxx" + + # old token will fail + assert_nil ApiClientAuthorization.validate(token: "xxxSystemRootTokenxxx") + # new token will work + auth = ApiClientAuthorization.validate(token: "newxxxSystemRootTokenxxx") + assert_equal "newxxxSystemRootTokenxxx", auth.api_token + assert_equal User.find_by_uuid(system_user_uuid).id, auth.user_id + + # now change the token again and use the new one first + Rails.configuration.SystemRootToken = "new2xxxSystemRootTokenxxx" + + # new token will work + auth = ApiClientAuthorization.validate(token: "new2xxxSystemRootTokenxxx") + assert_equal "new2xxxSystemRootTokenxxx", auth.api_token + assert_equal User.find_by_uuid(system_user_uuid).id, auth.user_id + # old token will fail + assert_nil ApiClientAuthorization.validate(token: "newxxxSystemRootTokenxxx") + end + + end