From adb680dab6bb9328d0eca4b3d7360d05473a066e Mon Sep 17 00:00:00 2001 From: Julian Cheal Date: Wed, 3 Oct 2018 13:30:27 +0100 Subject: [PATCH 1/2] Raise event on new user creation Follow up to PR https://github.com/ManageIQ/manageiq/pull/17852 Fixes BZ https://bugzilla.redhat.com/show_bug.cgi?id=1602136 --- app/models/authenticator/base.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/authenticator/base.rb b/app/models/authenticator/base.rb index 39cb78c8a3b..63ae523781d 100644 --- a/app/models/authenticator/base.rb +++ b/app/models/authenticator/base.rb @@ -196,7 +196,9 @@ def audit_event end def audit_new_user(audit, user) - audit_success(audit.merge(:message => "User creation successful for User: #{user.name} with ID: #{user.userid}")) + msg = "User creation successful for User: #{user.name} with ID: #{user.userid}" + audit_success(audit.merge(:message => msg)) + MiqEvent.raise_evm_event_queue(MiqServer.my_server, "user_created", :event_details => msg) end def authorize? From e8377bafb11061715674af98b718bace19ecd4a1 Mon Sep 17 00:00:00 2001 From: Julian Cheal Date: Thu, 4 Oct 2018 14:27:41 +0100 Subject: [PATCH 2/2] Added tests --- db/fixtures/miq_event_definitions.csv | 3 +++ spec/models/authenticator/database_spec.rb | 1 + spec/models/authenticator/ldap_spec.rb | 15 +++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/db/fixtures/miq_event_definitions.csv b/db/fixtures/miq_event_definitions.csv index 4e4fd617761..a0b6f20cf27 100644 --- a/db/fixtures/miq_event_definitions.csv +++ b/db/fixtures/miq_event_definitions.csv @@ -4,6 +4,9 @@ name,description,event_type,set_type # login_failed,Login failed,Default,authentication +# Authorization +user_created,User created,Default,authorization + # # EVM Server operations # diff --git a/spec/models/authenticator/database_spec.rb b/spec/models/authenticator/database_spec.rb index 121b952120b..782ae843c00 100644 --- a/spec/models/authenticator/database_spec.rb +++ b/spec/models/authenticator/database_spec.rb @@ -46,6 +46,7 @@ def authenticate expect(AuditEvent).not_to receive(:failure) authenticate end + it "updates lastlogon" do expect(-> { authenticate }).to change { alice.reload.lastlogon } end diff --git a/spec/models/authenticator/ldap_spec.rb b/spec/models/authenticator/ldap_spec.rb index 919def02219..1ec6bbbe4c3 100644 --- a/spec/models/authenticator/ldap_spec.rb +++ b/spec/models/authenticator/ldap_spec.rb @@ -278,6 +278,21 @@ def authenticate expect(User.find_by_userid(task.userid)).to eq(alice) end + context "new user creation" do + let(:username) { 'bob' } + it "logs the success" do + authenticate + expect(MiqQueue.count).to eq 1 + expect(MiqQueue.first.args.last(2)).to eq( + ["user_created", + { + :event_details => "User creation successful for User: Bob Builderson with ID: bob" + } + ] + ) + end + end + context "with no corresponding LDAP user" do let(:alice_data) { nil } it "fails" do