Commit 9514d151 authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'qa-testcases-195-instance-audit-logs' into 'master'

Add test for instance audit logs

Closes gitlab-org/quality/testcases#195

See merge request gitlab-org/gitlab!16610
parents 0794d0ea 4c93691c
......@@ -10,7 +10,7 @@
.float-right
- if impersonation_enabled? && @user != current_user && @user.can?(:log_in)
= link_to 'Impersonate', impersonate_admin_user_path(@user), method: :post, class: "btn btn-nr btn-grouped btn-info"
= link_to 'Impersonate', impersonate_admin_user_path(@user), method: :post, class: "btn btn-nr btn-grouped btn-info", data: { qa_selector: 'impersonate_user_link' }
= link_to edit_admin_user_path(@user), class: "btn btn-nr btn-grouped" do
%i.fa.fa-pencil-square-o
Edit
......
.gl-responsive-table-row{ role: 'row' }
.gl-responsive-table-row{ role: 'row', data: { qa_selector: 'user_row_content' } }
.table-section.section-40
.table-mobile-header{ role: 'rowheader' }
= _('Name')
......
......@@ -4,7 +4,7 @@
.row-main-content
.row-title.str-truncated-100
= image_tag avatar_icon_for_user(user), class: 'avatar s16 d-xs-flex d-md-none mr-1 prepend-top-2', alt: _('Avatar for %{name}') % { name: sanitize_name(user.name) }
= link_to user.name, admin_user_path(user), class: 'text-plain js-user-link', data: { user_id: user.id }
= link_to user.name, admin_user_path(user), class: 'text-plain js-user-link', data: { user_id: user.id, qa_selector: 'username_link' }
= render_if_exists 'admin/users/user_listing_note', user: user
......
......@@ -44,7 +44,7 @@
= hidden_field_tag "filter", h(params[:filter])
.search-holder
.search-field-holder
= search_field_tag :search_query, params[:search_query], placeholder: s_('AdminUsers|Search by name, email or username'), class: 'form-control search-text-input js-search-input', spellcheck: false
= search_field_tag :search_query, params[:search_query], placeholder: s_('AdminUsers|Search by name, email or username'), class: 'form-control search-text-input js-search-input', spellcheck: false, data: { qa_selector: 'user_search_field' }
- if @sort.present?
= hidden_field_tag :sort, @sort
= icon("search", class: "search-icon")
......
......@@ -73,7 +73,7 @@
= render 'layouts/header/current_user_dropdown'
- if has_impersonation_link
%li.nav-item.impersonation.ml-0
= link_to admin_impersonation_path, class: 'nav-link impersonation-btn', method: :delete, title: _('Stop impersonation'), aria: { label: _('Stop impersonation') }, data: { toggle: 'tooltip', placement: 'bottom', container: 'body' } do
= link_to admin_impersonation_path, class: 'nav-link impersonation-btn', method: :delete, title: _('Stop impersonation'), aria: { label: _('Stop impersonation') }, data: { toggle: 'tooltip', placement: 'bottom', container: 'body', qa_selector: 'stop_impersonation_link' } do
= icon('user-secret')
- if header_link?(:sign_in)
%li.nav-item
......
......@@ -6,7 +6,7 @@
= sprite_icon('admin', size: 24)
.sidebar-context-title
= _('Admin Area')
%ul.sidebar-top-level-items
%ul.sidebar-top-level-items{ data: { qa_selector: 'admin_sidebar_overview_submenu_content' } }
= nav_link(controller: %w(dashboard admin admin/projects users groups jobs runners gitaly_servers), html_options: {class: 'home'}) do
= link_to admin_root_path, class: 'shortcuts-tree' do
.nav-icon-container
......@@ -28,7 +28,7 @@
%span
= _('Projects')
= nav_link(controller: :users) do
= link_to admin_users_path, title: _('Users') do
= link_to admin_users_path, title: _('Users') , data: { qa_selector: 'users_overview_link' } do
%span
= _('Users')
= nav_link(controller: :groups) do
......@@ -49,13 +49,13 @@
= _('Gitaly Servers')
= nav_link(controller: admin_monitoring_nav_links) do
= link_to admin_system_info_path do
= link_to admin_system_info_path, data: { qa_selector: 'admin_monitoring_link' } do
.nav-icon-container
= sprite_icon('monitor')
%span.nav-item-name
= _('Monitoring')
%ul.sidebar-sub-level-items
%ul.sidebar-sub-level-items{ data: { qa_selector: 'admin_sidebar_monitoring_submenu_content' } }
= nav_link(controller: %w(system_info background_jobs logs health_check requests_profiles), html_options: { class: "fly-out-top-item" } ) do
= link_to admin_system_info_path do
%strong.fly-out-top-item-name
......@@ -225,7 +225,7 @@
%span.nav-item-name.qa-admin-settings-item
= _('Settings')
%ul.sidebar-sub-level-items.qa-admin-sidebar-submenu
%ul.sidebar-sub-level-items.qa-admin-sidebar-settings-submenu
= nav_link(controller: :application_settings, html_options: { class: "fly-out-top-item" } ) do
= link_to admin_application_settings_path do
%strong.fly-out-top-item-name
......
......@@ -64,7 +64,7 @@
%strong.fly-out-top-item-name
= _('Access Tokens')
= nav_link(controller: :emails) do
= link_to profile_emails_path do
= link_to profile_emails_path, data: { qa_selector: 'profile_emails_link' } do
.nav-icon-container
= sprite_icon('mail')
%span.nav-item-name
......@@ -76,7 +76,7 @@
= _('Emails')
- if current_user.allow_password_authentication?
= nav_link(controller: :passwords) do
= link_to edit_profile_password_path do
= link_to edit_profile_password_path , data: { qa_selector: 'profile_password_link' } do
.nav-icon-container
= sprite_icon('lock')
%span.nav-item-name
......
......@@ -13,9 +13,9 @@
= form_for 'email', url: profile_emails_path do |f|
.form-group
= f.label :email, _('Email'), class: 'label-bold'
= f.text_field :email, class: 'form-control'
= f.text_field :email, class: 'form-control', data: { qa_selector: 'email_address_field' }
.prepend-top-default
= f.submit _('Add email address'), class: 'btn btn-success'
= f.submit _('Add email address'), class: 'btn btn-success', data: { qa_selector: 'add_email_address_button' }
%hr
%h4.prepend-top-0
= _('Linked emails (%{email_count})') % { email_count: @emails.count + 1 }
......@@ -45,7 +45,7 @@
- if @primary_email === current_user.notification_email
%span.badge.badge-info= s_('Profiles|Default notification email')
- @emails.each do |email|
%li
%li{ data: { qa_selector: 'email_row_content' } }
= render partial: 'shared/email_with_badge', locals: { email: email.email, verified: email.confirmed? }
%span.float-right
- if email.email === current_user.commit_email
......@@ -58,6 +58,6 @@
- confirm_title = "#{email.confirmation_sent_at ? _('Resend confirmation email') : _('Send confirmation email')}"
= link_to confirm_title, resend_confirmation_instructions_profile_email_path(email), method: :put, class: 'btn btn-sm btn-warning prepend-left-10'
= link_to profile_email_path(email), data: { confirm: _('Are you sure?')}, method: :delete, class: 'btn btn-sm btn-danger prepend-left-10' do
= link_to profile_email_path(email), data: { confirm: _('Are you sure?'), qa_selector: 'delete_email_link'}, method: :delete, class: 'btn btn-sm btn-danger prepend-left-10' do
%span.sr-only= _('Remove')
= icon('trash')
......@@ -20,16 +20,16 @@
- unless @user.password_automatically_set?
.form-group
= f.label :current_password, _('Current password'), class: 'label-bold'
= f.password_field :current_password, required: true, class: 'form-control'
= f.password_field :current_password, required: true, class: 'form-control', data: { qa_selector: 'current_password_field' }
%p.form-text.text-muted
= _('You must provide your current password in order to change it.')
.form-group
= f.label :password, _('New password'), class: 'label-bold'
= f.password_field :password, required: true, class: 'form-control'
= f.password_field :password, required: true, class: 'form-control', data: { qa_selector: 'new_password_field' }
.form-group
= f.label :password_confirmation, _('Password confirmation'), class: 'label-bold'
= f.password_field :password_confirmation, required: true, class: 'form-control'
= f.password_field :password_confirmation, required: true, class: 'form-control', data: { qa_selector: 'confirm_password_field' }
.prepend-top-default.append-bottom-default
= f.submit _('Save password'), class: "btn btn-success append-right-10"
= f.submit _('Save password'), class: "btn btn-success append-right-10", data: { qa_selector: 'save_password_button' }
- unless @user.password_automatically_set?
= link_to _('I forgot my password'), reset_profile_password_path, method: :put, class: "account-btn-link"
......@@ -36,7 +36,7 @@
%th Date
%tbody
- @events.map(&:present).each do |event|
%tr
%tr{ data: { qa_selector: 'admin_audit_log_row_content' } }
%td
- if (author_link = event.author_name)
= author_link
......
- if License.feature_available?(:admin_audit_log)
= nav_link path: 'audit_logs#index' do
= link_to admin_audit_logs_path, title: 'Audit Log' do
= link_to admin_audit_logs_path, title: 'Audit Log', data: { qa_selector: 'admin_monitoring_audit_logs_link' } do
%span
Audit Log
......@@ -290,6 +290,8 @@ module QA
autoload :Menu, 'qa/page/profile/menu'
autoload :PersonalAccessTokens, 'qa/page/profile/personal_access_tokens'
autoload :SSHKeys, 'qa/page/profile/ssh_keys'
autoload :Emails, 'qa/page/profile/emails'
autoload :Password, 'qa/page/profile/password'
autoload :TwoFactorAuth, 'qa/page/profile/two_factor_auth'
end
......@@ -332,6 +334,13 @@ module QA
autoload :PerformanceBar, 'qa/page/admin/settings/component/performance_bar'
end
end
module Overview
module Users
autoload :Index, 'qa/page/admin/overview/users/index'
autoload :Show, 'qa/page/admin/overview/users/show'
end
end
end
module Mattermost
......
......@@ -61,6 +61,10 @@ module QA
end
end
module Monitoring
autoload :AuditLog, 'qa/ee/page/admin/monitoring/audit_log.rb'
end
module Settings
autoload :Templates, 'qa/ee/page/admin/settings/templates'
autoload :Integration, 'qa/ee/page/admin/settings/integration'
......
......@@ -18,6 +18,18 @@ module QA
view 'ee/app/views/layouts/nav/sidebar/_licenses_link.html.haml' do
element :link_license_menu
end
view 'ee/app/views/layouts/nav/ee/admin/_new_monitoring_sidebar.html.haml' do
element :admin_monitoring_audit_logs_link
end
end
end
def go_to_monitoring_audit_logs
hover_element(:admin_monitoring_link) do
within_submenu(:admin_sidebar_monitoring_submenu_content) do
click_element :admin_monitoring_audit_logs_link
end
end
end
......@@ -30,7 +42,7 @@ module QA
end
def go_to_template_settings
hover_settings do
hover_element(:admin_settings_item) do
within_submenu do
click_element :admin_settings_template_item
end
......
# frozen_string_literal: true
module QA
module EE
module Page
module Admin
module Monitoring
class AuditLog < QA::Page::Base
view 'ee/app/views/admin/audit_logs/index.html.haml' do
element :admin_audit_log_row_content
end
def has_audit_log_row?(text)
has_element?(:admin_audit_log_row_content, text: text)
end
end
end
end
end
end
end
......@@ -6,12 +6,16 @@ module QA
class Menu < Page::Base
view 'app/views/layouts/nav/sidebar/_admin.html.haml' do
element :admin_sidebar
element :admin_sidebar_submenu
element :admin_sidebar_settings_submenu
element :admin_settings_item
element :admin_settings_repository_item
element :admin_settings_general_item
element :admin_settings_metrics_and_profiling_item
element :admin_settings_preferences_link
element :admin_monitoring_link
element :admin_sidebar_monitoring_submenu_content
element :admin_sidebar_overview_submenu_content
element :users_overview_link
end
view 'app/views/layouts/nav/sidebar/_admin.html.haml' do
......@@ -19,59 +23,65 @@ module QA
end
def go_to_preferences_settings
hover_settings do
within_submenu do
hover_element(:admin_settings_item) do
within_submenu(:admin_sidebar_settings_submenu) do
click_element :admin_settings_preferences_link
end
end
end
def go_to_repository_settings
hover_settings do
within_submenu do
hover_element(:admin_settings_item) do
within_submenu(:admin_sidebar_settings_submenu) do
click_element :admin_settings_repository_item
end
end
end
def go_to_integration_settings
hover_settings do
within_submenu do
hover_element(:admin_settings_item) do
within_submenu(:admin_sidebar_settings_submenu) do
click_element :integration_settings_link
end
end
end
def go_to_general_settings
hover_settings do
within_submenu do
hover_element(:admin_settings_item) do
within_submenu(:admin_sidebar_settings_submenu) do
click_element :admin_settings_general_item
end
end
end
def go_to_metrics_and_profiling_settings
hover_settings do
within_submenu do
hover_element(:admin_settings_item) do
within_submenu(:admin_sidebar_settings_submenu) do
click_element :admin_settings_metrics_and_profiling_item
end
end
end
def go_to_network_settings
hover_settings do
within_submenu do
hover_element(:admin_settings_item) do
within_submenu(:admin_sidebar_settings_submenu) do
click_element :admin_settings_network_item
end
end
end
def go_to_users_overview
within_submenu(:admin_sidebar_overview_submenu_content) do
click_element :users_overview_link
end
end
private
def hover_settings
def hover_element(element)
within_sidebar do
scroll_to_element(:admin_settings_item)
find_element(:admin_settings_item).hover
scroll_to_element(element)
find_element(element).hover
yield
end
......@@ -83,8 +93,8 @@ module QA
end
end
def within_submenu
within_element(:admin_sidebar_submenu) do
def within_submenu(element)
within_element(element) do
yield
end
end
......
# frozen_string_literal: true
module QA
module Page
module Admin
module Overview
module Users
class Index < QA::Page::Base
view 'app/views/admin/users/index.html.haml' do
element :user_search_field
end
view 'app/views/admin/users/_user.html.haml' do
element :user_row_content
end
view 'app/views/admin/users/_user_detail.html.haml' do
element :username_link
end
def search_user(username)
find_element(:user_search_field).set(username).send_keys(:return)
end
def click_user(username)
within_element(:user_row_content, text: username) do
click_element(:username_link)
end
end
end
end
end
end
end
end
# frozen_string_literal: true
module QA
module Page
module Admin
module Overview
module Users
class Show < QA::Page::Base
view 'app/views/admin/users/_head.html.haml' do
element :impersonate_user_link
end
def click_impersonate_user
click_element(:impersonate_user_link)
end
end
end
end
end
end
end
......@@ -42,7 +42,7 @@ module QA
element :login_page, required: true
end
def sign_in_using_credentials(user = nil)
def sign_in_using_credentials(user: nil, skip_page_validation: false)
# Don't try to log-in if we're already logged-in
return if Page::Main::Menu.perform(&:signed_in?)
......@@ -52,9 +52,9 @@ module QA
raise NotImplementedError if Runtime::User.ldap_user? && user&.credentials_given?
if Runtime::User.ldap_user?
sign_in_using_ldap_credentials(user || Runtime::User)
sign_in_using_ldap_credentials(user: user || Runtime::User)
else
sign_in_using_gitlab_credentials(user || Runtime::User)
sign_in_using_gitlab_credentials(user: user || Runtime::User, skip_page_validation: skip_page_validation)
end
end
end
......@@ -68,13 +68,13 @@ module QA
using_wait_time 0 do
set_initial_password_if_present
sign_in_using_gitlab_credentials(admin)
sign_in_using_gitlab_credentials(user: admin)
end
Page::Main::Menu.perform(&:has_personal_area?)
end
def sign_in_using_ldap_credentials(user)
def sign_in_using_ldap_credentials(user:)
Page::Main::Menu.perform(&:sign_out_if_signed_in)
using_wait_time 0 do
......@@ -148,18 +148,18 @@ module QA
def sign_out_and_sign_in_as(user:)
Menu.perform(&:sign_out_if_signed_in)
has_sign_in_tab?
sign_in_using_credentials(user)
sign_in_using_credentials(user: user)
end
private
def sign_in_using_gitlab_credentials(user)
def sign_in_using_gitlab_credentials(user:, skip_page_validation: false)
switch_to_sign_in_tab if has_sign_in_tab?
switch_to_standard_tab if has_standard_tab?
fill_element :login_field, user.username
fill_element :password_field, user.password
click_element :sign_in_button, Page::Main::Menu
click_element :sign_in_button, !skip_page_validation && Page::Main::Menu
end
def set_initial_password_if_present
......
......@@ -13,6 +13,7 @@ module QA
element :navbar, required: true
element :user_avatar, required: true
element :user_menu, required: true
element :stop_impersonation_link
end
view 'app/views/layouts/nav/_dashboard.html.haml' do
......@@ -95,6 +96,10 @@ module QA
has_element?(:admin_area_link, wait: wait)
end
def click_stop_impersonation_link
click_element(:stop_impersonation_link)
end
private
def within_top_menu
......
# frozen_string_literal: true
module QA
module Page
module Profile
class Emails < Page::Base
view 'app/views/profiles/emails/index.html.haml' do
element :email_address_field
element :add_email_address_button
element :email_row_content
element :delete_email_link
end
def add_email_address(email_address)
find_element(:email_address_field).set email_address
click_element(:add_email_address_button)
end
def delete_email_address(email_address)
page.accept_alert do
within_element(:email_row_content, text: email_address) do
click_element(:delete_email_link)
end
end
end
end
end
end
end
......@@ -9,6 +9,8 @@ module QA
element :access_token_title, 'Access Tokens' # rubocop:disable QA/ElementWithPattern
element :top_level_items, '.sidebar-top-level-items' # rubocop:disable QA/ElementWithPattern
element :ssh_keys, 'SSH Keys' # rubocop:disable QA/ElementWithPattern
element :profile_emails_link
element :profile_password_link
end
def click_access_tokens
......@@ -23,6 +25,18 @@ module QA
end
end
def click_emails
within_sidebar do
click_element(:profile_emails_link)
end
end
def click_password
within_sidebar do
click_element(:profile_password_link)
end
end
private
def within_sidebar
......
# frozen_string_literal: true
module QA
module Page
module Profile
class Password < Page::Base
view 'app/views/profiles/passwords/edit.html.haml' do
element :current_password_field
element :new_password_field
element :confirm_password_field
element :save_password_button
end
def update_password(new_password, current_password)
find_element(:current_password_field).set current_password
find_element(:new_password_field).set new_password
find_element(:confirm_password_field).set new_password
click_element(:save_password_button)
end
end
end
end
end
......@@ -30,7 +30,7 @@ module QA
Page::Main::Menu.perform(&:sign_out)
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform do |login|
login.sign_in_using_credentials(user)
login.sign_in_using_credentials(user: user)
end
upstream.project.visit!
......
......@@ -53,7 +53,7 @@ module QA
if credentials_given?
Page::Main::Login.perform do |login|
login.sign_in_using_credentials(self)
login.sign_in_using_credentials(user: self)
end
else
Page::Main::Login.perform do |login|
......
......@@ -50,7 +50,7 @@ module QA
unless Page::Main::Menu.perform { |p| p.has_personal_area?(wait: 0) }
Runtime::Browser.visit(@address, Page::Main::Login)
Page::Main::Login.perform { |login| login.sign_in_using_credentials(@user) }
Page::Main::Login.perform { |login| login.sign_in_using_credentials(user: @user) }
end
token = Resource::PersonalAccessToken.fabricate!.access_token
......
......@@ -164,7 +164,7 @@ module QA
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform do |login_page|
login_page.sign_in_using_ldap_credentials(user)
login_page.sign_in_using_ldap_credentials(user: user)
end
group.visit!
......
......@@ -44,7 +44,7 @@ module QA
end
Page::Main::Login.perform do |menu|
menu.sign_in_using_credentials(@user)
menu.sign_in_using_credentials(user: @user)
end
@group.sandbox.visit!
......@@ -72,7 +72,7 @@ module QA
end
Page::Main::Login.perform do |menu|
menu.sign_in_using_credentials(@user)
menu.sign_in_using_credentials(user: @user)
end
@group.sandbox.visit!
......
# frozen_string_literal: true
require 'securerandom'
module QA
context 'Manage' do
shared_examples 'instance audit event logs' do |expected_events|
it 'logs audit events for UI operations' do
Page::Main::Menu.perform(&:click_admin_area)
QA::Page::Admin::Menu.perform(&:go_to_monitoring_audit_logs)
EE::Page::Admin::Monitoring::AuditLog.perform do |audit_log_page|
expected_events.each do |expected_event|
expect(audit_log_page).to have_audit_log_row(expected_event)
end
end
end
end
describe 'Instance audit logs' do
context 'Failed sign in' do
before do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
invalid_user = QA::Resource::User.new.tap do |user|
user.username = 'bad_user_name'
user.password = 'bad_pasword'
end
Page::Main::Login.perform do |login_page|
login_page.sign_in_using_credentials(user: invalid_user, skip_page_validation: true)
end
sign_in
end
it_behaves_like 'instance audit event logs', ["Failed to login with STANDARD authentication"]
end
context 'Successful sign in' do
before do
sign_in
end
it_behaves_like 'instance audit event logs', ["Signed in with STANDARD authentication"]
end
context 'Add SSH key' do
before do
sign_in
Resource::SSHKey.fabricate! do |resource|
resource.title = "key for instance audit event logs test #{Time.now.to_f}"
end
end
it_behaves_like 'instance audit event logs', ["Added SSH key"]
end
context 'Add and delete email' do
before do
sign_in
new_email_address = '[email protected]'
Page::Main::Menu.perform(&:click_settings_link)
Page::Profile::Menu.perform(&:click_emails)
Page::Profile::Emails.perform do |emails|
emails.add_email_address(new_email_address)