Skip to content

Commit

Permalink
Add avo_sign_as helper (#5045)
Browse files Browse the repository at this point in the history
Solves #4791
  • Loading branch information
JuanVqz authored Sep 21, 2024
1 parent 39ece2e commit 078120b
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 235 deletions.
1 change: 1 addition & 0 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
include OauthHelpers
include AvoHelpers
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
end
24 changes: 24 additions & 0 deletions test/helpers/avo_helpers.rb
Original file line number Diff line number Diff line change
@@ -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
25 changes: 2 additions & 23 deletions test/system/avo/events_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
23 changes: 1 addition & 22 deletions test/system/avo/manual_changes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 1 addition & 22 deletions test/system/avo/oidc_api_key_roles_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 1 addition & 22 deletions test/system/avo/oidc_providers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
37 changes: 7 additions & 30 deletions test/system/avo/rubygems_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: "[email protected]")
rubygem = create(:rubygem)
Expand Down Expand Up @@ -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: "[email protected]")
rubygem = create(:rubygem)
Expand Down Expand Up @@ -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: "[email protected]")
rubygem = create(:rubygem)
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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)
Expand Down
22 changes: 1 addition & 21 deletions test/system/avo/sendgrid_events_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 7 additions & 28 deletions test/system/avo/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: "[email protected]")

ownership = create(:ownership)
Expand Down Expand Up @@ -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: "[email protected]")

user = create(:user)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 078120b

Please sign in to comment.