From 07bc3fe69c122d04d08e4d5714e984a38823d561 Mon Sep 17 00:00:00 2001 From: Thomas Bellebaum Date: Wed, 27 Oct 2021 14:45:46 +0200 Subject: [PATCH] Reduced code duplications in tests And fixed a bug where certain attributes were not updated via the admin API --- omejdn.rb | 1 + tests/config_testsetup.rb | 87 ++++++++++++++++++++++++++++ tests/test_admin_api.rb | 98 ++++++------------------------- tests/test_oauth2.rb | 105 +++++++--------------------------- tests/test_selfservice_api.rb | 90 +++-------------------------- 5 files changed, 135 insertions(+), 246 deletions(-) create mode 100644 tests/config_testsetup.rb diff --git a/omejdn.rb b/omejdn.rb index 2abb12c..c908b6a 100644 --- a/omejdn.rb +++ b/omejdn.rb @@ -553,6 +553,7 @@ def self.get client.attributes = c['attributes'] client.allowed_scopes = c['allowed_scopes'] client.redirect_uri = c['redirect_uri'] + client.allowed_resources = c['allowed_resources'] clients << client end Config.client_config = clients diff --git a/tests/config_testsetup.rb b/tests/config_testsetup.rb new file mode 100644 index 0000000..07bd7ce --- /dev/null +++ b/tests/config_testsetup.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +class TestSetup + + def self.setup + @backup_users = File.read './config/users.yml' + @backup_clients = File.read './config/clients.yml' + @backup_omejdn = File.read './config/omejdn.yml' + File.open('./config/users.yml', 'w') { |file| file.write(users.to_yaml) } + File.open('./config/clients.yml', 'w') { |file| file.write(clients.to_yaml) } + File.open('./config/omejdn.yml', 'w') { |file| file.write(config.to_yaml) } + end + + def self.teardown + File.open('./config/users.yml', 'w') { |file| file.write(@backup_users) } + File.open('./config/clients.yml', 'w') { |file| file.write(@backup_clients) } + File.open('./config/omejdn.yml', 'w') { |file| file.write(@backup_omejdn) } + end + + def self.users + [{ + 'username' => 'testUser', + 'attributes' => [ + { 'key' => 'omejdn', 'value' => 'write' }, + { 'key' => 'openid', 'value' => true }, + { 'key' => 'profile', 'value' => true }, + { 'key' => 'email', 'value' => 'admin@example.com' }, + { 'key' => 'asdfasf', 'value' => 'asdfasf' }, + { 'key' => 'exampleKey', 'value' => 'exampleValue' } + ], + 'password' => '$2a$12$s1UhO7bRO9b5fTTiRE4KxOR88vz3462Bxn8DGh/iDX26Neh95AHrC' # "mypassword" + }, + { + 'username' => 'testUser2', + 'attributes' => [ + { 'key' => 'omejdn', 'value' => 'write' } + ], + 'password' => '$2a$12$Be9.8qVsGOVpUFO4ebiMBel/TNetkPhnUkJ8KENHjHLiDG.IXi0Zi' + }] + end + + def self.clients + [{ + 'client_id' => 'testClient', + 'name' => 'omejdn admin ui', + 'allowed_scopes' => ['omejdn:write'], + 'redirect_uri' => 'http://localhost:4200', + 'attributes' => [] + }, + { + 'client_id' => 'testClient2', + 'name' => 'omejdn admin ui', + 'allowed_scopes' => ['omejdn:write'], + 'redirect_uri' => 'http://localhost:4200', + 'attributes' => [], + 'allowed_resources' => ['http://example.org','http://localhost:4567/api'] + }] + end + + def self.config + { + 'host' => 'http://localhost:4567', + 'openid' => true, + 'token' => { + 'expiration' => 3600, + 'signing_key' => 'omejdn_priv.pem', + 'algorithm' => 'RS256', + 'audience' => 'TestServer', + 'issuer' => 'http://localhost:4567' + }, + 'id_token' => { + 'expiration' => 3600, + 'signing_key' => 'omejdn_priv.pem', + 'algorithm' => 'RS256', + 'issuer' => 'http://localhost:4567' + }, + 'user_backend' => ['yaml'], + 'user_backend_default' => 'yaml', + 'user_selfservice' => { + 'enabled' => true, + 'allow_deletion' => true, + 'allow_password_change' => true, + 'editable_attributes' => ['name'] + } + } + end +end diff --git a/tests/test_admin_api.rb b/tests/test_admin_api.rb index 78bb0e7..8d54129 100644 --- a/tests/test_admin_api.rb +++ b/tests/test_admin_api.rb @@ -7,6 +7,7 @@ require 'webrick/https' require_relative '../omejdn' require_relative '../lib/token_helper' +require_relative 'config_testsetup' class AdminApiTest < Test::Unit::TestCase include Rack::Test::Methods @@ -16,78 +17,16 @@ def app end def setup - @backup_users = File.read './config/users.yml' - @backup_clients = File.read './config/clients.yml' - @backup_omejdn = File.read './config/omejdn.yml' - File.open('./config/users.yml', 'w') { |file| file.write(users_testsetup.to_yaml) } - File.open('./config/clients.yml', 'w') { |file| file.write(clients_testsetup.to_yaml) } - File.open('./config/omejdn.yml', 'w') { |file| file.write(config_testsetup.to_yaml) } + TestSetup.setup client = Client.find_by_id 'testClient' - @token = TokenHelper.build_access_token client, ['omejdn:admin'], config_testsetup['host']+"/api", nil + @token = TokenHelper.build_access_token client, ['omejdn:admin'], TestSetup.config['host']+"/api", nil @insufficient_token = TokenHelper.build_access_token client, ['omejdn:write'], "test", nil @testCertificate = File.read './tests/test_resources/testClient.pem' - end def teardown - File.open('./config/users.yml', 'w') { |file| file.write(@backup_users) } - File.open('./config/clients.yml', 'w') { |file| file.write(@backup_clients) } - File.open('./config/omejdn.yml', 'w') { |file| file.write(@backup_omejdn) } - end - - def users_testsetup - [{ - 'username' => 'testUser', - 'attributes' => [ - { 'key' => 'omejdn', 'value' => 'write' }, - { 'key' => 'openid', 'value' => true }, - { 'key' => 'profile', 'value' => true }, - { 'key' => 'email', 'value' => 'admin@example.com' }, - { 'key' => 'asdfasf', 'value' => 'asdfasf' }, - { 'key' => 'exampleKey', 'value' => 'exampleValue' } - ], - 'password' => '$2a$12$Be9.8qVsGOVpUFO4ebiMBel/TNetkPhnUkJ8KENHjHLiDG.IXi0Zi' - }] - end - - def clients_testsetup - [{ - 'client_id' => 'testClient', - 'name' => 'omejdn admin ui', - 'allowed_scopes' => ['omejdn:write'], - 'redirect_uri' => 'http://localhost:4200', - 'attributes' => [] - }, - { - 'client_id' => 'testClient2', - 'name' => 'omejdn admin ui', - 'allowed_scopes' => ['omejdn:write'], - 'redirect_uri' => 'http://localhost:4200', - 'attributes' => [] - }] - end - - def config_testsetup - { - 'host' => 'http://localhost:4567', - 'openid' => true, - 'token' => { - 'expiration' => 3600, - 'signing_key' => 'omejdn_priv.pem', - 'algorithm' => 'RS256', - 'audience' => 'TestServer', - 'issuer' => 'http://localhost:4567' - }, - 'id_token' => { - 'expiration' => 3600, - 'signing_key' => 'omejdn_priv.pem', - 'algorithm' => 'RS256', - 'issuer' => 'http://localhost:4567' - }, - 'user_backend' => ['yaml'], - 'user_backend_default' => 'yaml' - } + TestSetup.teardown end def test_require_admin_scope @@ -100,19 +39,19 @@ def test_get_users get '/api/v1/config/users', {}, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } # p last_response assert last_response.ok? - assert_equal users_testsetup, JSON.parse(last_response.body) + assert_equal TestSetup.users, JSON.parse(last_response.body) end def test_get_user get '/api/v1/config/users/testUser', {}, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } # p last_response assert last_response.ok? - assert_equal users_testsetup[0], JSON.parse(last_response.body) + assert_equal TestSetup.users[0], JSON.parse(last_response.body) end def test_post_user user = { - 'username' => 'testUser2', + 'username' => 'testUser3', 'attributes' => [ { 'key' => 'exampleKey2', 'value' => 'exampleValue2' } ], @@ -121,7 +60,7 @@ def test_post_user post '/api/v1/config/users', user.to_json, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } # p last_response assert last_response.created? - get '/api/v1/config/users/testUser2', {}, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } + get '/api/v1/config/users/testUser3', {}, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } # p last_response assert last_response.ok? new_user = JSON.parse(last_response.body) @@ -174,11 +113,11 @@ def test_change_user_password def test_get_clients get '/api/v1/config/clients', {}, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } assert last_response.ok? - assert_equal clients_testsetup, JSON.parse(last_response.body) + assert_equal TestSetup.clients, JSON.parse(last_response.body) end def test_put_clients - new_clients = clients_testsetup + new_clients = TestSetup.clients new_clients[1]['name'] = 'Test name' put '/api/v1/config/clients', new_clients.to_json, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } assert last_response.no_content? @@ -190,16 +129,13 @@ def test_put_clients def test_get_client get '/api/v1/config/clients/testClient', {}, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } assert last_response.ok? - assert_equal clients_testsetup[0], JSON.parse(last_response.body) + assert_equal TestSetup.clients[0], JSON.parse(last_response.body) end def test_put_client - client = { - 'name' => 'omejdn admin ui', - 'allowed_scopes' => ['omejdn:write'], - 'redirect_uri' => 'http://localhost:4200', - 'attributes' => [] - } + client = TestSetup.clients[1] + client.delete("client_id") + client['name'] = "Alternative Name" put '/api/v1/config/clients/testClient2', client.to_json, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } assert last_response.no_content? get '/api/v1/config/clients/testClient2', {}, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } @@ -234,15 +170,15 @@ def test_delete_client def test_get_config get '/api/v1/config/omejdn', {}, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } assert last_response.ok? - assert_equal config_testsetup, JSON.parse(last_response.body) + assert_equal TestSetup.config, JSON.parse(last_response.body) end def test_put_config - put '/api/v1/config/omejdn', config_testsetup.to_json, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } + put '/api/v1/config/omejdn', TestSetup.config.to_json, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } assert last_response.no_content? get '/api/v1/config/omejdn', {}, { 'HTTP_AUTHORIZATION' => "Bearer #{@token}" } assert last_response.ok? - assert_equal config_testsetup, JSON.parse(last_response.body) + assert_equal TestSetup.config, JSON.parse(last_response.body) end def test_post_put_delete_certificate diff --git a/tests/test_oauth2.rb b/tests/test_oauth2.rb index d1396aa..859895f 100644 --- a/tests/test_oauth2.rb +++ b/tests/test_oauth2.rb @@ -7,6 +7,7 @@ require 'webrick/https' require_relative '../omejdn' require_relative '../lib/token_helper' +require_relative 'config_testsetup' class OAuth2Test < Test::Unit::TestCase include Rack::Test::Methods @@ -24,81 +25,19 @@ def setup @certificate_ec512 = File.read './tests/test_resources/ec512.cert' @certificate_rsa = File.read './tests/test_resources/rsa.cert' - @backup_users = File.read './config/users.yml' - @backup_clients = File.read './config/clients.yml' - @backup_omejdn = File.read './config/omejdn.yml' - File.open('./config/users.yml', 'w') { |file| file.write(users_testsetup.to_yaml) } - File.open('./config/clients.yml', 'w') { |file| file.write(clients_testsetup.to_yaml) } - File.open('./config/omejdn.yml', 'w') { |file| file.write(config_testsetup.to_yaml) } - + TestSetup.setup + @client = Client.find_by_id 'testClient' @client2 = Client.find_by_id 'testClient2' @testCertificate = File.read './tests/test_resources/testClient.pem' end def teardown - File.open('./config/users.yml', 'w') { |file| file.write(@backup_users) } - File.open('./config/clients.yml', 'w') { |file| file.write(@backup_clients) } - File.open('./config/omejdn.yml', 'w') { |file| file.write(@backup_omejdn) } + TestSetup.teardown @client.certificate = nil @client2.certificate = nil end - def users_testsetup - [{ - 'username' => 'testUser', - 'attributes' => [ - { 'key' => 'omejdn', 'value' => 'write' }, - { 'key' => 'openid', 'value' => true }, - { 'key' => 'profile', 'value' => true }, - { 'key' => 'email', 'value' => 'admin@example.com' }, - { 'key' => 'asdfasf', 'value' => 'asdfasf' }, - { 'key' => 'exampleKey', 'value' => 'exampleValue' } - ], - 'password' => '$2a$12$s1UhO7bRO9b5fTTiRE4KxOR88vz3462Bxn8DGh/iDX26Neh95AHrC' # "mypassword" - }] - end - - def clients_testsetup - [{ - 'client_id' => 'testClient', - 'name' => 'omejdn admin ui', - 'allowed_scopes' => ['omejdn:write'], - 'redirect_uri' => 'http://localhost:4200', - 'attributes' => [] - }, - { - 'client_id' => 'testClient2', - 'name' => 'omejdn admin ui', - 'allowed_scopes' => ['omejdn:write'], - 'redirect_uri' => 'http://localhost:4200', - 'attributes' => [], - 'allowed_resources' => ['http://example.org','http://localhost:4567/api'] - }] - end - - def config_testsetup - { - 'host' => 'http://localhost:4567', - 'openid' => true, - 'token' => { - 'expiration' => 3600, - 'signing_key' => 'omejdn_priv.pem', - 'algorithm' => 'RS256', - 'audience' => 'TestServer', - 'issuer' => 'http://localhost:4567' - }, - 'id_token' => { - 'expiration' => 3600, - 'signing_key' => 'omejdn_priv.pem', - 'algorithm' => 'RS256', - 'issuer' => 'http://localhost:4567' - }, - 'user_backend' => ['yaml'], - 'user_backend_default' => 'yaml' - } - end - def request_client_credentials(client, alg, key, certificate, query_additions='', should_work=true) iss = client.client_id now = Time.new.to_i @@ -120,15 +59,15 @@ def check_keys(hash, keylist) def extract_access_token(response) check_keys response, ["access_token","expires_in","token_type","scope"] - assert_equal response["expires_in"], config_testsetup['token']['expiration'] + assert_equal response["expires_in"], TestSetup.config['token']['expiration'] assert_equal response["token_type"], "bearer" assert_equal response["scope"], "omejdn:write" - jwt = JWT.decode(response['access_token'], Server.load_key.public_key, true, { algorithm: config_testsetup['token']['algorithm'] }) + jwt = JWT.decode(response['access_token'], Server.load_key.public_key, true, { algorithm: TestSetup.config['token']['algorithm'] }) check_keys jwt[1], ['typ','kid','alg'] assert_equal jwt[1]['typ'], 'at+jwt' assert_equal jwt[1]['kid'], 'default' - assert_equal jwt[1]['alg'], config_testsetup['token']['algorithm'] + assert_equal jwt[1]['alg'], TestSetup.config['token']['algorithm'] return jwt[0] end @@ -139,8 +78,8 @@ def test_client_credentials check_keys at, ['scope','aud','iss','nbf','iat','jti','exp','client_id','sub'] assert_equal at['scope'], 'omejdn:write' - assert_equal at['aud'], [config_testsetup['token']['audience'], config_testsetup['host']+'/api'] - assert_equal at['iss'], config_testsetup['token']['issuer'] + assert_equal at['aud'], [TestSetup.config['token']['audience'], TestSetup.config['host']+'/api'] + assert_equal at['iss'], TestSetup.config['token']['issuer'] assert at['nbf'] <= Time.new.to_i assert_equal at['iat'], at['nbf'] assert_equal at['exp'], at['nbf']+response["expires_in"] @@ -158,8 +97,8 @@ def test_client_credentials_with_resources check_keys at, ['scope','aud','iss','nbf','iat','jti','exp','client_id','sub'] assert_equal at['scope'], 'omejdn:write' - assert_equal at['aud'], ['http://example.org', config_testsetup['host']+'/api'] - assert_equal at['iss'], config_testsetup['token']['issuer'] + assert_equal at['aud'], ['http://example.org', TestSetup.config['host']+'/api'] + assert_equal at['iss'], TestSetup.config['token']['issuer'] assert at['nbf'] <= Time.new.to_i assert_equal at['iat'], at['nbf'] assert_equal at['exp'], at['nbf']+response["expires_in"] @@ -175,8 +114,8 @@ def test_client_credentials_scope_rejection check_keys at, ['scope','aud','iss','nbf','iat','jti','exp','client_id','sub'] assert_equal at['scope'], 'omejdn:write' - assert_equal at['aud'], [config_testsetup['token']['audience'], config_testsetup['host']+'/api'] - assert_equal at['iss'], config_testsetup['token']['issuer'] + assert_equal at['aud'], [TestSetup.config['token']['audience'], TestSetup.config['host']+'/api'] + assert_equal at['iss'], TestSetup.config['token']['issuer'] assert at['nbf'] <= Time.new.to_i assert_equal at['iat'], at['nbf'] assert_equal at['exp'], at['nbf']+response["expires_in"] @@ -231,42 +170,42 @@ def request_authorization(user, client, query_additions='', should_work=true) end def test_authorization_flow - response = request_authorization users_testsetup[0], @client + response = request_authorization TestSetup.users[0], @client at = extract_access_token response check_keys at, ['scope','aud','iss','nbf','iat','jti','exp','client_id','sub', 'omejdn'] assert_equal at['scope'], 'omejdn:write' - assert_equal at['aud'], [config_testsetup['token']['audience'], config_testsetup['host']+'/api'] - assert_equal at['iss'], config_testsetup['token']['issuer'] + assert_equal at['aud'], [TestSetup.config['token']['audience'], TestSetup.config['host']+'/api'] + assert_equal at['iss'], TestSetup.config['token']['issuer'] assert at['nbf'] <= Time.new.to_i assert_equal at['iat'], at['nbf'] assert_equal at['exp'], at['nbf']+response["expires_in"] assert at['jti'] assert_equal at['client_id'], @client.client_id - assert_equal at['sub'], users_testsetup[0]['username'] + assert_equal at['sub'], TestSetup.users[0]['username'] assert_equal 'write', at['omejdn'] end def test_authorization_flow_with_bad_resources resources = '&resource=a&resource=b' - response = request_authorization users_testsetup[0], @client2, resources, false + response = request_authorization TestSetup.users[0], @client2, resources, false end def test_authorization_flow_with_resources resources = '&resource=http://example.org' - response = request_authorization users_testsetup[0], @client2, resources + response = request_authorization TestSetup.users[0], @client2, resources at = extract_access_token response check_keys at, ['scope','aud','iss','nbf','iat','jti','exp','client_id','sub', 'omejdn'] assert_equal at['scope'], 'omejdn:write' - assert_equal at['aud'], ['http://example.org', config_testsetup['host']+'/api'] - assert_equal at['iss'], config_testsetup['token']['issuer'] + assert_equal at['aud'], ['http://example.org', TestSetup.config['host']+'/api'] + assert_equal at['iss'], TestSetup.config['token']['issuer'] assert at['nbf'] <= Time.new.to_i assert_equal at['iat'], at['nbf'] assert_equal at['exp'], at['nbf']+response["expires_in"] assert at['jti'] assert_equal at['client_id'], @client2.client_id - assert_equal at['sub'], users_testsetup[0]['username'] + assert_equal at['sub'], TestSetup.users[0]['username'] assert_equal 'write', at['omejdn'] end end diff --git a/tests/test_selfservice_api.rb b/tests/test_selfservice_api.rb index 7a66fa7..0a3ab30 100644 --- a/tests/test_selfservice_api.rb +++ b/tests/test_selfservice_api.rb @@ -7,8 +7,9 @@ require 'webrick/https' require_relative '../omejdn' require_relative '../lib/token_helper' +require_relative 'config_testsetup' -class SelfsServiceApiTest < Test::Unit::TestCase +class SelfServiceApiTest < Test::Unit::TestCase include Rack::Test::Methods def app @@ -16,91 +17,16 @@ def app end def setup - @backup_users = File.read './config/users.yml' - @backup_clients = File.read './config/clients.yml' - @backup_omejdn = File.read './config/omejdn.yml' - File.open('./config/users.yml', 'w') { |file| file.write(users_testsetup.to_yaml) } - File.open('./config/clients.yml', 'w') { |file| file.write(clients_testsetup.to_yaml) } - File.open('./config/omejdn.yml', 'w') { |file| file.write(config_testsetup.to_yaml) } - + TestSetup.setup user = User.find_by_id 'testUser' client = Client.find_by_id 'testClient' - @write_token = TokenHelper.build_access_token client, ['omejdn:write'], config_testsetup['host']+"/api", user - @read_token = TokenHelper.build_access_token client, ['omejdn:read'], config_testsetup['host']+"/api", user - @useless_token = TokenHelper.build_access_token client, [], config_testsetup['host']+"/api", user + @write_token = TokenHelper.build_access_token client, ['omejdn:write'], TestSetup.config['host']+"/api", user + @read_token = TokenHelper.build_access_token client, ['omejdn:read'], TestSetup.config['host']+"/api", user + @useless_token = TokenHelper.build_access_token client, [], TestSetup.config['host']+"/api", user end def teardown - File.open('./config/users.yml', 'w') { |file| file.write(@backup_users) } - File.open('./config/clients.yml', 'w') { |file| file.write(@backup_clients) } - File.open('./config/omejdn.yml', 'w') { |file| file.write(@backup_omejdn) } - end - - def users_testsetup - [{ - 'username' => 'testUser', - 'attributes' => [ - { 'key' => 'omejdn', 'value' => 'write' }, - { 'key' => 'openid', 'value' => true }, - { 'key' => 'profile', 'value' => true }, - { 'key' => 'email', 'value' => 'admin@example.com' }, - { 'key' => 'asdfasf', 'value' => 'asdfasf' }, - { 'key' => 'exampleKey', 'value' => 'exampleValue' } - ], - 'password' => '$2a$12$s1UhO7bRO9b5fTTiRE4KxOR88vz3462Bxn8DGh/iDX26Neh95AHrC' # "mypassword" - }, - { - 'username' => 'testUser2', - 'attributes' => [ - { 'key' => 'omejdn', 'value' => 'write' } - ], - 'password' => '$2a$12$Be9.8qVsGOVpUFO4ebiMBel/TNetkPhnUkJ8KENHjHLiDG.IXi0Zi' - }] - end - - def clients_testsetup - [{ - 'client_id' => 'testClient', - 'name' => 'omejdn admin ui', - 'allowed_scopes' => ['omejdn:write'], - 'redirect_uri' => 'http://localhost:4200', - 'attributes' => [] - }, - { - 'client_id' => 'testClient2', - 'name' => 'omejdn admin ui', - 'allowed_scopes' => ['omejdn:write'], - 'redirect_uri' => 'http://localhost:4200', - 'attributes' => [] - }] - end - - def config_testsetup - { - 'host' => 'http://localhost:4567', - 'openid' => true, - 'token' => { - 'expiration' => 3600, - 'signing_key' => 'omejdn_priv.pem', - 'algorithm' => 'RS256', - 'audience' => 'TestServer', - 'issuer' => 'http://localhost:4567' - }, - 'id_token' => { - 'expiration' => 3600, - 'signing_key' => 'omejdn_priv.pem', - 'algorithm' => 'RS256', - 'issuer' => 'http://localhost:4567' - }, - 'user_backend' => ['yaml'], - 'user_backend_default' => 'yaml', - 'user_selfservice' => { - 'enabled' => true, - 'allow_deletion' => true, - 'allow_password_change' => true, - 'editable_attributes' => ['name'] - } - } + TestSetup.teardown end def test_require_read_scope @@ -123,7 +49,7 @@ def test_require_write_scope def test_get get '/api/v1/user', {}, { 'HTTP_AUTHORIZATION' => "Bearer #{@read_token}" } assert last_response.ok? - expected = users_testsetup[0] + expected = TestSetup.users[0] expected.delete('password') assert_equal expected, JSON.parse(last_response.body) end