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

Propagate userid through to create a scanning job with current userid #244

Merged
merged 1 commit into from
Apr 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,12 @@ def default_authentication_type
:bearer
end

def scan_job_create(entity)
check_policy_prevent(:request_containerimage_scan, entity, User.current_user.userid, :raw_scan_job_create)
def scan_job_create(entity, userid)
check_policy_prevent(:request_containerimage_scan, entity, userid, :raw_scan_job_create)
end

def raw_scan_job_create(target_class, target_id = nil, userid = nil, target_name = nil)
raise MiqException::Error, _("target_class must be a class not an instance") if target_class.kind_of?(ContainerImage)
userid ||= User.current_user.userid
Job.create_job(
"ManageIQ::Providers::Kubernetes::ContainerManager::Scanning::Job",
:userid => userid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def fetch_oscap_arf
# https://github.com/ManageIQ/manageiq-providers-kubernetes/pull/54/files
image = FactoryGirl.create(:container_image, :ext_management_system => @ems)
User.current_user = FactoryGirl.create(:user, :userid => "bob")
job = @ems.raw_scan_job_create(image.class, image.id)
job = @ems.raw_scan_job_create(image.class, image.id, User.current_user.userid)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

raw_scan_job_create is a callback that is called when scheduling the scan. It is only called through scan_job_create and never directly and now with this patch - always with a userid parameter. That is why I had to add the userid here.

expect(job).to have_attributes(
:dispatch_status => "pending",
:state => "waiting_to_start",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
it ".scan_job_create" do
image = FactoryGirl.create(:container_image, :ext_management_system => @ems)
User.current_user = FactoryGirl.create(:user, :userid => "bob")
job = @ems.raw_scan_job_create(image.class, image.id)
job = @ems.raw_scan_job_create(image.class, image.id, User.current_user.userid)

expect(job.state).to eq("waiting_to_start")
expect(job.status).to eq("ok")
Expand Down