mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add system test for user security keys (#23372)
This commit is contained in:
parent
d108762c94
commit
0a3f1852c6
@ -27,7 +27,10 @@
|
|||||||
{{/unless}}
|
{{/unless}}
|
||||||
<div class="controls pref-second-factor">
|
<div class="controls pref-second-factor">
|
||||||
{{#if this.isCurrentUser}}
|
{{#if this.isCurrentUser}}
|
||||||
<LinkTo @route="preferences.second-factor" class="btn btn-default">
|
<LinkTo
|
||||||
|
@route="preferences.second-factor"
|
||||||
|
class="btn btn-default btn-second-factor"
|
||||||
|
>
|
||||||
{{d-icon "lock"}}
|
{{d-icon "lock"}}
|
||||||
<span>{{i18n "user.second_factor.enable"}}</span>
|
<span>{{i18n "user.second_factor.enable"}}</span>
|
||||||
</LinkTo>
|
</LinkTo>
|
||||||
|
@ -22,12 +22,9 @@ module SystemHelpers
|
|||||||
expect(page).to have_content("Signed in to #{user.encoded_username} successfully")
|
expect(page).to have_content("Signed in to #{user.encoded_username} successfully")
|
||||||
end
|
end
|
||||||
|
|
||||||
def sign_out
|
|
||||||
delete File.join(GlobalSetting.relative_url_root || "", "/session")
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup_system_test
|
def setup_system_test
|
||||||
SiteSetting.login_required = false
|
SiteSetting.login_required = false
|
||||||
|
SiteSetting.has_login_hint = false
|
||||||
SiteSetting.content_security_policy = false
|
SiteSetting.content_security_policy = false
|
||||||
SiteSetting.force_hostname = Capybara.server_host
|
SiteSetting.force_hostname = Capybara.server_host
|
||||||
SiteSetting.port = Capybara.server_port
|
SiteSetting.port = Capybara.server_port
|
||||||
|
@ -109,7 +109,6 @@ describe "Custom sidebar sections", type: :system do
|
|||||||
section_modal.save
|
section_modal.save
|
||||||
|
|
||||||
expect(sidebar).to have_section("My section")
|
expect(sidebar).to have_section("My section")
|
||||||
take_screenshot
|
|
||||||
expect(sidebar).to have_section_link("Faq", target: "_blank")
|
expect(sidebar).to have_section_link("Faq", target: "_blank")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -15,6 +15,25 @@ module PageObjects
|
|||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def click_profile_tab
|
||||||
|
click_link("user-menu-button-profile")
|
||||||
|
has_css?("#quick-access-profile")
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def click_logout_button
|
||||||
|
find("#quick-access-profile .logout .btn").click
|
||||||
|
has_css?(".d-header .login-button")
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def sign_out
|
||||||
|
open
|
||||||
|
click_profile_tab
|
||||||
|
click_logout_button
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
def has_group_mentioned_notification?(topic, user_that_mentioned_group, group_mentioned)
|
def has_group_mentioned_notification?(topic, user_that_mentioned_group, group_mentioned)
|
||||||
expect(find("#quick-access-replies .group-mentioned").text).to eq(
|
expect(find("#quick-access-replies .group-mentioned").text).to eq(
|
||||||
"#{user_that_mentioned_group.username} @#{group_mentioned.name} #{topic.title}",
|
"#{user_that_mentioned_group.username} @#{group_mentioned.name} #{topic.title}",
|
||||||
|
19
spec/system/page_objects/pages/user_preferences_security.rb
Normal file
19
spec/system/page_objects/pages/user_preferences_security.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module PageObjects
|
||||||
|
module Pages
|
||||||
|
class UserPreferencesSecurity < PageObjects::Pages::Base
|
||||||
|
def visit(user)
|
||||||
|
page.visit("/u/#{user.username}/preferences/security")
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def visit_second_factor(password)
|
||||||
|
click_link(class: "btn-second-factor")
|
||||||
|
|
||||||
|
find(".second-factor input#password").fill_in(with: password)
|
||||||
|
find(".second-factor .btn-primary").click
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
45
spec/system/user_page/user_preferences_security_spec.rb
Normal file
45
spec/system/user_page/user_preferences_security_spec.rb
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe "User preferences for Security", type: :system do
|
||||||
|
fab!(:password) { "kungfukenny" }
|
||||||
|
fab!(:email) { "email@user.com" }
|
||||||
|
fab!(:user) { Fabricate(:user, email: email, password: password) }
|
||||||
|
let(:user_preferences_security_page) { PageObjects::Pages::UserPreferencesSecurity.new }
|
||||||
|
let(:user_menu) { PageObjects::Components::UserMenu.new }
|
||||||
|
|
||||||
|
before do
|
||||||
|
user.activate
|
||||||
|
sign_in(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Security keys" do
|
||||||
|
it "adds a 2F security key and logs in with it" do
|
||||||
|
# simulate browser credential authorization
|
||||||
|
options = ::Selenium::WebDriver::VirtualAuthenticatorOptions.new
|
||||||
|
page.driver.browser.add_virtual_authenticator(options)
|
||||||
|
|
||||||
|
user_preferences_security_page.visit(user)
|
||||||
|
user_preferences_security_page.visit_second_factor(password)
|
||||||
|
|
||||||
|
find(".security-key .new-security-key").click
|
||||||
|
expect(user_preferences_security_page).to have_css("input#security-key-name")
|
||||||
|
|
||||||
|
find(".modal-body input#security-key-name").fill_in(with: "First Key")
|
||||||
|
find(".add-security-key").click
|
||||||
|
|
||||||
|
expect(user_preferences_security_page).to have_css(".security-key .second-factor-item")
|
||||||
|
|
||||||
|
user_menu.sign_out
|
||||||
|
|
||||||
|
# login flow
|
||||||
|
find(".d-header .login-button").click
|
||||||
|
find("input#login-account-name").fill_in(with: user.username)
|
||||||
|
find("input#login-account-password").fill_in(with: password)
|
||||||
|
|
||||||
|
find(".modal-footer .btn-primary").click
|
||||||
|
find("#security-key .btn-primary").click
|
||||||
|
|
||||||
|
expect(page).to have_css(".header-dropdown-toggle.current-user")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user