Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise event on new user creation #18052

Merged
merged 2 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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