From 0d11ffcd98801e34a428857ded076b69c8b67f45 Mon Sep 17 00:00:00 2001 From: nimrodshn Date: Thu, 29 Mar 2018 15:41:27 +0300 Subject: [PATCH] Fallback to default user ('system') when session is logged out fixing specs fix failed tests adding userid as param to scan_job_create --- .../manageiq/providers/kubernetes/container_manager_mixin.rb | 5 ++--- .../kubernetes/container_manager/scanning/job_spec.rb | 2 +- .../manageiq/providers/kubernetes/container_manager_spec.rb | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/manageiq/providers/kubernetes/container_manager_mixin.rb b/app/models/manageiq/providers/kubernetes/container_manager_mixin.rb index b701f9cf11..5fff8fcec4 100644 --- a/app/models/manageiq/providers/kubernetes/container_manager_mixin.rb +++ b/app/models/manageiq/providers/kubernetes/container_manager_mixin.rb @@ -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, diff --git a/spec/models/manageiq/providers/kubernetes/container_manager/scanning/job_spec.rb b/spec/models/manageiq/providers/kubernetes/container_manager/scanning/job_spec.rb index dbe6f4c8e6..65ec76191f 100644 --- a/spec/models/manageiq/providers/kubernetes/container_manager/scanning/job_spec.rb +++ b/spec/models/manageiq/providers/kubernetes/container_manager/scanning/job_spec.rb @@ -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) expect(job).to have_attributes( :dispatch_status => "pending", :state => "waiting_to_start", diff --git a/spec/models/manageiq/providers/kubernetes/container_manager_spec.rb b/spec/models/manageiq/providers/kubernetes/container_manager_spec.rb index 66ecc2691f..dae2291cad 100644 --- a/spec/models/manageiq/providers/kubernetes/container_manager_spec.rb +++ b/spec/models/manageiq/providers/kubernetes/container_manager_spec.rb @@ -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")