Skip to content

Commit

Permalink
Merge pull request #18052 from juliancheal/raise_event_new_login
Browse files Browse the repository at this point in the history
Raise event on new user creation

(cherry picked from commit d952e08)

https://bugzilla.redhat.com/show_bug.cgi?id=1602136
  • Loading branch information
bdunne authored and simaishi committed Nov 7, 2018
1 parent 5ff8a19 commit 3c2d5cb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/authenticator/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
3 changes: 3 additions & 0 deletions db/fixtures/miq_event_definitions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
1 change: 1 addition & 0 deletions spec/models/authenticator/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/models/authenticator/ldap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3c2d5cb

Please sign in to comment.