Commit 8df3f70c authored by James Lopez's avatar James Lopez

fix specs

parent 9efeb572
module Emails
class CreateService < ::Emails::BaseService
prepend EE::Emails::CreateService
prepend ::EE::Emails::CreateService
def execute
@user.emails.create(email: @email)
......
module Emails
class DestroyService < ::Emails::BaseService
prepend EE::Emails::DestroyService
prepend ::EE::Emails::DestroyService
def execute
update_secondary_emails! if Email.find_by_email!(@email).destroy
......
......@@ -14,8 +14,10 @@ module Users
assign_attributes(&block)
user_exists = @user.persisted?
if @user.save(validate: validate)
notify_success
notify_success(user_exists)
else
error(@user.errors.full_messages.uniq.join('. '))
end
......@@ -31,8 +33,8 @@ module Users
protected
def notify_success
notify_new_user(@user, nil) unless @user.persisted?
def notify_success(user_exists)
notify_new_user(@user, nil) unless user_exists
success
end
......@@ -40,6 +42,10 @@ module Users
private
def assign_attributes(&block)
if @user.user_synced_attributes_metadata
params.except!(*@user.user_synced_attributes_metadata.read_only_attributes)
end
@user.assign_attributes(params) if params.any?
end
end
......
module EE
module Emails
module CreateService
include EE::Emails::BaseService
include ::EE::Emails::BaseService
def execute
email = super
......
module EE
module Emails
module DestroyService
include EE::Emails::BaseService
include ::EE::Emails::BaseService
def execute
result = super
......
......@@ -5,8 +5,8 @@ module EE
private
def notify_success
notify_new_user(@user, nil) unless @user.persisted?
def notify_success(user_exists)
notify_new_user(@user, nil) unless user_exists
audit_changes(:email, as: 'email address')
audit_changes(:encrypted_password, as: 'password', skip_changes: true)
......
......@@ -154,6 +154,8 @@ feature 'Login' do
end
it 'creates a security event after failed OAuth login' do
stub_licensed_features(extended_audit_events: true)
stub_omniauth_saml_config(enabled: true, auto_link_saml_user: true, allow_single_sign_on: ['saml'], providers: [mock_saml_config])
user = create(:omniauth_user, :two_factor, extern_uid: 'my-uid', provider: 'saml')
gitlab_sign_in_via('saml', user, 'wrong-uid')
......@@ -177,6 +179,8 @@ feature 'Login' do
end
it 'blocks invalid login' do
stub_licensed_features(extended_audit_events: true)
user = create(:user, password: 'not-the-default')
gitlab_sign_in(user)
......
......@@ -6,8 +6,11 @@ describe EE::Audit::Changes do
let(:foo_instance) { Class.new { include EE::Audit::Changes }.new }
before do
stub_licensed_features(extended_audit_events: true)
foo_instance.instance_variable_set(:@current_user, user)
foo_instance.instance_variable_set(:@user, user)
allow(foo_instance).to receive(:model).and_return(user)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment