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

fix specs

parent 9efeb572
module Emails module Emails
class CreateService < ::Emails::BaseService class CreateService < ::Emails::BaseService
prepend EE::Emails::CreateService prepend ::EE::Emails::CreateService
def execute def execute
@user.emails.create(email: @email) @user.emails.create(email: @email)
......
module Emails module Emails
class DestroyService < ::Emails::BaseService class DestroyService < ::Emails::BaseService
prepend EE::Emails::DestroyService prepend ::EE::Emails::DestroyService
def execute def execute
update_secondary_emails! if Email.find_by_email!(@email).destroy update_secondary_emails! if Email.find_by_email!(@email).destroy
......
...@@ -14,8 +14,10 @@ module Users ...@@ -14,8 +14,10 @@ module Users
assign_attributes(&block) assign_attributes(&block)
user_exists = @user.persisted?
if @user.save(validate: validate) if @user.save(validate: validate)
notify_success notify_success(user_exists)
else else
error(@user.errors.full_messages.uniq.join('. ')) error(@user.errors.full_messages.uniq.join('. '))
end end
...@@ -31,8 +33,8 @@ module Users ...@@ -31,8 +33,8 @@ module Users
protected protected
def notify_success def notify_success(user_exists)
notify_new_user(@user, nil) unless @user.persisted? notify_new_user(@user, nil) unless user_exists
success success
end end
...@@ -40,6 +42,10 @@ module Users ...@@ -40,6 +42,10 @@ module Users
private private
def assign_attributes(&block) 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? @user.assign_attributes(params) if params.any?
end end
end end
......
module EE module EE
module Emails module Emails
module CreateService module CreateService
include EE::Emails::BaseService include ::EE::Emails::BaseService
def execute def execute
email = super email = super
......
module EE module EE
module Emails module Emails
module DestroyService module DestroyService
include EE::Emails::BaseService include ::EE::Emails::BaseService
def execute def execute
result = super result = super
......
...@@ -5,8 +5,8 @@ module EE ...@@ -5,8 +5,8 @@ module EE
private private
def notify_success def notify_success(user_exists)
notify_new_user(@user, nil) unless @user.persisted? notify_new_user(@user, nil) unless user_exists
audit_changes(:email, as: 'email address') audit_changes(:email, as: 'email address')
audit_changes(:encrypted_password, as: 'password', skip_changes: true) audit_changes(:encrypted_password, as: 'password', skip_changes: true)
......
...@@ -154,6 +154,8 @@ feature 'Login' do ...@@ -154,6 +154,8 @@ feature 'Login' do
end end
it 'creates a security event after failed OAuth login' do 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]) 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') user = create(:omniauth_user, :two_factor, extern_uid: 'my-uid', provider: 'saml')
gitlab_sign_in_via('saml', user, 'wrong-uid') gitlab_sign_in_via('saml', user, 'wrong-uid')
...@@ -177,6 +179,8 @@ feature 'Login' do ...@@ -177,6 +179,8 @@ feature 'Login' do
end end
it 'blocks invalid login' do it 'blocks invalid login' do
stub_licensed_features(extended_audit_events: true)
user = create(:user, password: 'not-the-default') user = create(:user, password: 'not-the-default')
gitlab_sign_in(user) gitlab_sign_in(user)
......
...@@ -6,8 +6,11 @@ describe EE::Audit::Changes do ...@@ -6,8 +6,11 @@ describe EE::Audit::Changes do
let(:foo_instance) { Class.new { include EE::Audit::Changes }.new } let(:foo_instance) { Class.new { include EE::Audit::Changes }.new }
before do before do
stub_licensed_features(extended_audit_events: true)
foo_instance.instance_variable_set(:@current_user, user) foo_instance.instance_variable_set(:@current_user, user)
foo_instance.instance_variable_set(:@user, user) foo_instance.instance_variable_set(:@user, user)
allow(foo_instance).to receive(:model).and_return(user) allow(foo_instance).to receive(:model).and_return(user)
end 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