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

Fixes #37733 - Add audits of ansible role changes on hosts #729

Merged
merged 1 commit into from
Sep 8, 2024

Conversation

adamlazik1
Copy link
Contributor

@adamlazik1 adamlazik1 commented Aug 14, 2024

This records audits when ansible role is added to a host or removed from a host.

Defining the to_label method is necessary so the name of host ansible
role is shown in the format role / host rather than id / host.

@adamlazik1
Copy link
Contributor Author

The look of the audits

image

@nofaralfasi
Copy link
Contributor

@adamlazik1 Could you add tests to this PR to help validate the changes?

@adamlazik1 adamlazik1 force-pushed the feat-37733 branch 2 times, most recently from 52bf11f to 1117f72 Compare September 3, 2024 11:25
@adamlazik1
Copy link
Contributor Author

Added the test, I hope it's in the correct place.

@@ -17,4 +17,25 @@ class HostAnsibleRoleTest < ActiveSupport::TestCase
end
should validate_uniqueness_of(:ansible_role_id).scoped_to(:host_id)
end

describe 'auditing' do
test 'audit creation and deletion of host ansible roles' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend splitting this into separate tests for each action. One test should focus on verifying the audit record for creation, and another for deletion.

ansible_role = FactoryBot.create(:ansible_role)
host_ansible_role = FactoryBot.create(:host_ansible_role, :with_auditing, host_id: host.id, ansible_role_id: ansible_role.id)

assert_not host_ansible_role.audits.blank?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it would be clearer to ensure that each test verifies only one audit record is created. This helps confirm that the auditing is working as expected.

@adamlazik1
Copy link
Contributor Author

Alright, I split the test and tried to extract some common parts.

Copy link
Contributor

@nofaralfasi nofaralfasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please update the assert_equal statements so that the expected value is the first argument, in line with common practice?

This records audits when ansible role is added to a host or removed from
a host.

Defining the `to_label` method is necessary so the name of host ansible
role is shown in the format `role / host` rather than `id / host`.
@adamlazik1
Copy link
Contributor Author

Done.

@nofaralfasi nofaralfasi merged commit 0c34388 into theforeman:master Sep 8, 2024
23 of 27 checks passed
@adamlazik1 adamlazik1 deleted the feat-37733 branch September 9, 2024 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants