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 #18738 - fixes the sub query #6639

Merged
merged 1 commit into from Mar 17, 2017
Merged

Conversation

ares
Copy link
Contributor

@ares ares commented Mar 1, 2017

I think this has been introduced by this change 142ccd5#diff-56ae1a984a0feed9e676a8e2f8240113R90

I'm not sure but I think it's similarly broken for all katello resources since this is generic method in api_controller. The problem I believe is in the fact the query needs to select only id attribute but it can contain other conditions, like name = Library. Doing the pluck introduces one more SQL query but make it safer since it does the (SELECT *) and returns id only, therefore it supports all conditions specified in filters.

I'm not familiar enough with katello testing infrastructure, so pointing me to some place where I could add a test for this and tips how to stub data would be appreciated.

@mention-bot
Copy link

@ares, thanks for your PR! By analyzing the history of the files in this pull request, we identified @johnpmitsch, @jlsherrill and @komidore64 to be potential reviewers.

def test_scoped_search_with_permissions
cv = FactoryGirl.create(:katello_content_view)
setup_current_user_with_permissions(:name => 'view_content_views', :search => "name = #{cv.name}"
@query = ContentView.authorized(:view_content_views)

Choose a reason for hiding this comment

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

unexpected token tIVAR

@ares ares force-pushed the fix/18738 branch 2 times, most recently from fd6a145 to 146d62f Compare March 2, 2017 06:50
@query = ContentView.authorized(:view_content_views)
params = {}
@controller.stubs(:params).returns(params)
login_user(setup_user_with_permissions(:name => 'view_content_views', :search => "name = #{cv.name}", User.find(users(:restricted).id)))

Choose a reason for hiding this comment

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

unexpected token tRPAREN

@ares ares force-pushed the fix/18738 branch 2 times, most recently from fbab4c9 to 9e90c02 Compare March 2, 2017 13:31
@ares
Copy link
Contributor Author

ares commented Mar 3, 2017

Ok, I've got tests green. The tests does not test it on Activation key but still has some value. The reason why I don't test it on AK is that there's no factory defined for it and I don't feel up to experiment with what it needs. If someone provides the factory to easily create AK, I'm happy to add one more tests. But I hope that this does not block the PR. I'd appreciate if someone could review and test. I don't have write permissions on this repo so whoever ACKs please merge too :-)

EDIT: oh too soon, the test seems to fail again

@ares
Copy link
Contributor Author

ares commented Mar 6, 2017

[test]

def test_scoped_search_with_permissions
cv = FactoryGirl.create(:katello_content_view)
user = FactoryGirl.create(:user, :organization_ids => [cv.organization_id])
login_user(setup_user_with_permissions({:name => 'view_content_views', :search => "name = #{cv.name}"}, user.id)))

Choose a reason for hiding this comment

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

unexpected token tRPAREN

@jlsherrill
Copy link
Member

@ares this change makes sense, looks like a test is still failing.

@ares
Copy link
Contributor Author

ares commented Mar 8, 2017

Yeah, honestly I don't know why and I'd appreciate if someone else provides the test or I'll remove it completely. I spent too much time on this already and without deeper knowledge of katello fixtures and factories I'm not sure how to move further within reasonable time.

@ares ares force-pushed the fix/18738 branch 2 times, most recently from 301c4e9 to 43436c5 Compare March 14, 2017 12:35
@ares
Copy link
Contributor Author

ares commented Mar 14, 2017

Tests should be green now, I removed my test that was failing.

@ares
Copy link
Contributor Author

ares commented Mar 17, 2017

What's the status here?

@ehelms
Copy link
Member

ehelms commented Mar 17, 2017

@jlsherrill please re-review

@jlsherrill
Copy link
Member

Status was me finding time :)

@jlsherrill
Copy link
Member

@ares doesn't look like the current test actually tests the problem. I had been meaning to help you write a test but hadn't found the time, but here you go:

diff --git a/test/controllers/api/v2/api_controller_test.rb b/test/controllers/api/v2/api_controller_test.rb
index 68c708b..63c8c5c 100644
--- a/test/controllers/api/v2/api_controller_test.rb
+++ b/test/controllers/api/v2/api_controller_test.rb
@@ -4,6 +4,8 @@ require "katello_test_helper"
 
 module Katello
   class Api::V2::ApiControllerTest < ActionController::TestCase
+    include Katello::AuthorizationSupportMethods
+
     def setup
       @controller = Katello::Api::V2::ApiController.new
       @query = Erratum.all
@@ -62,6 +64,21 @@ module Katello
       assert_nil response[:error], "error"
     end
 
+    def test_with_reduced_perms
+      params = {}
+      @controller.stubs(:params).returns(params)
+      @default_sort = %w(name desc)
+
+      User.current = users(:restricted)
+      key = katello_activation_keys(:simple_key)
+      setup_current_user_with_permissions(:name => "view_activation_keys",
+                                          :search => "environment = #{key.environment}")
+
+      @options = { :resource_class => Katello::ActivationKey }
+      keys = @controller.scoped_search(ActivationKey.readable, @default_sort[0], @default_sort[1], @options)
+      assert_includes keys[:results], key
+    end
+
     def test_scoped_search_zero_total
       @query = Erratum.where('1=0')
       params = {}

mind updating to add this test instead?

@ares
Copy link
Contributor Author

ares commented Mar 17, 2017

Thanks a lot @jlsherrill, patch applied, let's see the test results now.

@jlsherrill
Copy link
Member

ACK thanks @ares!

@jlsherrill jlsherrill merged commit 211df8b into Katello:master Mar 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants