diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index ff04317430c..f0eb3df30d6 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -2,5 +2,6 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase include OauthHelpers + include AvoHelpers driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400] end diff --git a/test/helpers/avo_helpers.rb b/test/helpers/avo_helpers.rb new file mode 100644 index 00000000000..1927d7b4bf1 --- /dev/null +++ b/test/helpers/avo_helpers.rb @@ -0,0 +1,24 @@ +module AvoHelpers + def avo_sign_in_as(user) + OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( + provider: "github", + uid: "1", + credentials: { + token: user.oauth_token, + expires: false + }, + info: { + name: user.login + } + ) + + @ip_address = create(:ip_address, ip_address: "127.0.0.1") + + stub_github_info_request(user.info_data) + + visit avo.root_path + click_button "Log in with GitHub" + + page.assert_text user.login + end +end diff --git a/test/system/avo/events_test.rb b/test/system/avo/events_test.rb index 31ecf3e9565..1e493143415 100644 --- a/test/system/avo/events_test.rb +++ b/test/system/avo/events_test.rb @@ -5,29 +5,8 @@ class Avo::EventsSystemTest < ApplicationSystemTestCase include ActiveJob::TestHelper - def sign_in_as(user) - OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( - provider: "github", - uid: "1", - credentials: { - token: user.oauth_token, - expires: false - }, - info: { - name: user.login - } - ) - @ip_address = create(:ip_address, ip_address: "127.0.0.1") - stub_github_info_request(user.info_data) - - visit avo.root_path - click_button "Log in with GitHub" - - page.assert_text user.login - end - test "user events" do - sign_in_as(create(:admin_github_user, :is_admin)) + avo_sign_in_as(create(:admin_github_user, :is_admin)) visit avo.root_path click_link "Events user events" @@ -46,7 +25,7 @@ def sign_in_as(user) end test "rubygem events" do - sign_in_as(create(:admin_github_user, :is_admin)) + avo_sign_in_as(create(:admin_github_user, :is_admin)) visit avo.root_path click_link "Events rubygem events" diff --git a/test/system/avo/manual_changes_test.rb b/test/system/avo/manual_changes_test.rb index ad990b0bf1a..9db82895c35 100644 --- a/test/system/avo/manual_changes_test.rb +++ b/test/system/avo/manual_changes_test.rb @@ -3,30 +3,9 @@ class Avo::ManualChangesSystemTest < ApplicationSystemTestCase make_my_diffs_pretty! - def sign_in_as(user) - OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( - provider: "github", - uid: "1", - credentials: { - token: user.oauth_token, - expires: false - }, - info: { - name: user.login - } - ) - - stub_github_info_request(user.info_data) - - visit avo.root_path - click_button "Log in with GitHub" - - page.assert_text user.login - end - test "auditing changes" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user Admin::LogTicketPolicy.any_instance.stubs(:avo_create?).returns(true) Admin::LogTicketPolicy.any_instance.stubs(:avo_update?).returns(true) diff --git a/test/system/avo/oidc_api_key_roles_test.rb b/test/system/avo/oidc_api_key_roles_test.rb index 26ddc401784..23f14311153 100644 --- a/test/system/avo/oidc_api_key_roles_test.rb +++ b/test/system/avo/oidc_api_key_roles_test.rb @@ -3,30 +3,9 @@ class Avo::OIDCApiKeyRolesSystemTest < ApplicationSystemTestCase make_my_diffs_pretty! - def sign_in_as(user) - OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( - provider: "github", - uid: "1", - credentials: { - token: user.oauth_token, - expires: false - }, - info: { - name: user.login - } - ) - - stub_github_info_request(user.info_data) - - visit avo.root_path - click_button "Log in with GitHub" - - page.assert_text user.login - end - test "manually changing roles" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user provider = create(:oidc_provider) user = create(:user) diff --git a/test/system/avo/oidc_providers_test.rb b/test/system/avo/oidc_providers_test.rb index 8b91d0ecaf0..a3d56d9462a 100644 --- a/test/system/avo/oidc_providers_test.rb +++ b/test/system/avo/oidc_providers_test.rb @@ -3,30 +3,9 @@ class Avo::OIDCProvidersSystemTest < ApplicationSystemTestCase make_my_diffs_pretty! - def sign_in_as(user) - OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( - provider: "github", - uid: "1", - credentials: { - token: user.oauth_token, - expires: false - }, - info: { - name: user.login - } - ) - - stub_github_info_request(user.info_data) - - visit avo.root_path - click_button "Log in with GitHub" - - page.assert_text user.login - end - test "refreshing provider" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user provider = create(:oidc_provider, issuer: "https://token.actions.githubusercontent.com", configuration: nil, jwks: nil) diff --git a/test/system/avo/rubygems_test.rb b/test/system/avo/rubygems_test.rb index b79ccc0ee3f..2356068849a 100644 --- a/test/system/avo/rubygems_test.rb +++ b/test/system/avo/rubygems_test.rb @@ -5,32 +5,9 @@ class Avo::RubygemsSystemTest < ApplicationSystemTestCase include ActiveJob::TestHelper - def sign_in_as(user) - OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( - provider: "github", - uid: "1", - credentials: { - token: user.oauth_token, - expires: false - }, - info: { - name: user.login - } - ) - - create(:ip_address, ip_address: "127.0.0.1") - - stub_github_info_request(user.info_data) - - visit avo.root_path - click_button "Log in with GitHub" - - page.assert_text user.login - end - test "release reserved namespace" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user rubygem = create(:rubygem, created_at: 40.days.ago) rubygem_attributes = rubygem.attributes.with_indifferent_access @@ -88,7 +65,7 @@ def sign_in_as(user) test "Yank a rubygem" do Minitest::Test.make_my_diffs_pretty! admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user security_user = create(:user, email: "security@rubygems.org") rubygem = create(:rubygem) @@ -163,7 +140,7 @@ def sign_in_as(user) test "Yank all version of rubygem" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user security_user = create(:user, email: "security@rubygems.org") rubygem = create(:rubygem) @@ -252,7 +229,7 @@ def sign_in_as(user) test "add owner" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user security_user = create(:user, email: "security@rubygems.org") rubygem = create(:rubygem) @@ -332,7 +309,7 @@ def sign_in_as(user) test "upload versions file" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user visit avo.resources_rubygems_path @@ -353,7 +330,7 @@ def sign_in_as(user) test "upload names file" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user visit avo.resources_rubygems_path @@ -374,7 +351,7 @@ def sign_in_as(user) test "upload info file" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user version = create(:version) visit avo.resources_rubygem_path(version.rubygem) diff --git a/test/system/avo/sendgrid_events_test.rb b/test/system/avo/sendgrid_events_test.rb index 01d309c0e25..363742cb49c 100644 --- a/test/system/avo/sendgrid_events_test.rb +++ b/test/system/avo/sendgrid_events_test.rb @@ -3,29 +3,9 @@ class Avo::SendgridEventsSystemTest < ApplicationSystemTestCase include ActiveJob::TestHelper - def sign_in_as(user) - OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( - provider: "github", - uid: "1", - credentials: { - token: user.oauth_token, - expires: false - }, - info: { - name: user.login - } - ) - stub_github_info_request(user.info_data) - - visit avo.root_path - click_button "Log in with GitHub" - - page.assert_text user.login - end - test "search for event" do user = FactoryBot.create(:admin_github_user, :is_admin) - sign_in_as(user) + avo_sign_in_as(user) visit avo.resources_sendgrid_events_path diff --git a/test/system/avo/users_test.rb b/test/system/avo/users_test.rb index 3c04bc1a8a8..0c8d6b6a015 100644 --- a/test/system/avo/users_test.rb +++ b/test/system/avo/users_test.rb @@ -5,31 +5,10 @@ class Avo::UsersSystemTest < ApplicationSystemTestCase include ActiveJob::TestHelper - def sign_in_as(user) - OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( - provider: "github", - uid: "1", - credentials: { - token: user.oauth_token, - expires: false - }, - info: { - name: user.login - } - ) - @ip_address = create(:ip_address, ip_address: "127.0.0.1") - stub_github_info_request(user.info_data) - - visit avo.root_path - click_button "Log in with GitHub" - - page.assert_text user.login - end - test "reset mfa" do Minitest::Test.make_my_diffs_pretty! admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user user = create(:user) user.enable_totp!(ROTP::Base32.random_base32, :ui_and_api) @@ -102,7 +81,7 @@ def sign_in_as(user) test "block user" do Minitest::Test.make_my_diffs_pretty! admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user user = create(:user) user.enable_totp!(ROTP::Base32.random_base32, :ui_and_api) @@ -200,7 +179,7 @@ def sign_in_as(user) test "reset api key" do perform_enqueued_jobs do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user user = create(:user) user_attributes = user.attributes.with_indifferent_access @@ -267,7 +246,7 @@ def sign_in_as(user) test "Yank rubygems" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user security_user = create(:user, email: "security@rubygems.org") ownership = create(:ownership) @@ -366,7 +345,7 @@ def sign_in_as(user) test "yank user" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user security_user = create(:user, email: "security@rubygems.org") user = create(:user) @@ -510,7 +489,7 @@ def sign_in_as(user) test "change user email" do perform_enqueued_jobs do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user user = create(:user) user_attributes = user.attributes.with_indifferent_access @@ -588,7 +567,7 @@ def sign_in_as(user) test "create user" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user visit avo.resources_users_path diff --git a/test/system/avo/versions_test.rb b/test/system/avo/versions_test.rb index 69a9d8c0934..1e7842843a9 100644 --- a/test/system/avo/versions_test.rb +++ b/test/system/avo/versions_test.rb @@ -5,31 +5,9 @@ class Avo::VersionsSystemTest < ApplicationSystemTestCase include ActiveJob::TestHelper - def sign_in_as(user) - OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( - provider: "github", - uid: "1", - credentials: { - token: user.oauth_token, - expires: false - }, - info: { - name: user.login - } - ) - - @ip_address = create(:ip_address, ip_address: "127.0.0.1") - stub_github_info_request(user.info_data) - - visit avo.root_path - click_button "Log in with GitHub" - - page.assert_text user.login - end - test "restore a rubygem version" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user rubygem = create(:rubygem) version = create(:version, rubygem: rubygem) @@ -139,7 +117,7 @@ def sign_in_as(user) test "run afer version write job" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user rubygem = create(:rubygem, owners: [create(:user)]) version = create(:version, rubygem: rubygem) diff --git a/test/system/avo/web_hooks_test.rb b/test/system/avo/web_hooks_test.rb index 58a3ad99824..bbc2c22ca7b 100644 --- a/test/system/avo/web_hooks_test.rb +++ b/test/system/avo/web_hooks_test.rb @@ -3,30 +3,10 @@ class Avo::WebHooksSystemTest < ApplicationSystemTestCase include ActiveJob::TestHelper - def sign_in_as(user) - OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( - provider: "github", - uid: "1", - credentials: { - token: user.oauth_token, - expires: false - }, - info: { - name: user.login - } - ) - stub_github_info_request(user.info_data) - - visit avo.root_path - click_button "Log in with GitHub" - - page.assert_text user.login - end - test "delete webhook" do Minitest::Test.make_my_diffs_pretty! admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user web_hook = create(:global_web_hook) diff --git a/test/system/maintenance_tasks_test.rb b/test/system/maintenance_tasks_test.rb index 5a07054de2f..207ea25cb7c 100644 --- a/test/system/maintenance_tasks_test.rb +++ b/test/system/maintenance_tasks_test.rb @@ -5,30 +5,9 @@ class MaintenanceTasksTest < ApplicationSystemTestCase include ActiveJob::TestHelper - def sign_in_as(user) - OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new( - provider: "github", - uid: "1", - credentials: { - token: user.oauth_token, - expires: false - }, - info: { - name: user.login - } - ) - - stub_github_info_request(user.info_data) - - visit admin_maintenance_tasks.root_path - click_button "Log in with GitHub" - - page.assert_text "Maintenance Tasks" - end - test "auditing create run" do admin_user = create(:admin_github_user, :is_admin) - sign_in_as admin_user + avo_sign_in_as admin_user visit admin_maintenance_tasks.root_path click_on "Maintenance::UserTotpSeedEmptyToNilTask" diff --git a/test/test_helper.rb b/test/test_helper.rb index a9965a35de9..db501610808 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -33,6 +33,7 @@ require "helpers/policy_helpers" require "helpers/webauthn_helpers" require "helpers/oauth_helpers" +require "helpers/avo_helpers" require "webmock/minitest" require "phlex/testing/rails/view_helper"