Skip to content

Commit 454d978

Browse files
committed
[fix] Get product configuration with view permission
The getProductConfiguration() function on Product endpoint requires a current product in the URL for checking view permission. The requirement of having view permission has been added in 8953b30. However there is no "current product" in the Product endpoint URL queries, but the product id is provided through a function parameter.
1 parent 585323a commit 454d978

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

web/server/codechecker_server/api/product_server.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def __require_permission(self, required, args=None):
6767
with DBSession(self.__session) as session:
6868
if args is None:
6969
args = dict(self.__permission_args)
70+
71+
if 'config_db_session' not in args:
7072
args['config_db_session'] = session
7173

7274
# Anonymous access is only allowed if authentication is
@@ -254,7 +256,9 @@ def getProductConfiguration(self, product_id):
254256
Get the product configuration --- WITHOUT THE DB PASSWORD --- of the
255257
given product.
256258
"""
257-
self.__require_permission([permissions.PRODUCT_VIEW])
259+
self.__require_permission([permissions.PRODUCT_VIEW], {
260+
'productID': product_id
261+
})
258262

259263
with DBSession(self.__session) as session:
260264
product = session.query(Product).get(product_id)

web/tests/functional/products/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def setup_class_common(workspace_name):
9696

9797
# Export the test configuration to the workspace.
9898
env.export_test_cfg(TEST_WORKSPACE, test_config)
99+
env.enable_auth(TEST_WORKSPACE)
99100

100101

101102
def teardown_class_common():

web/tests/functional/products/test_products.py

+13
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ def test_get_product_data(self):
181181
Confidentiality.CONFIDENTIAL,
182182
"Default Confidentiality was not Confidential")
183183

184+
def test_get_product_config_auth_server(self):
185+
"""
186+
Test if product configuration can be retrieved from an authenticated
187+
server.
188+
"""
189+
pr_client = env.setup_product_client(
190+
self.test_workspace, product=self.product_name)
191+
product_id = pr_client.getCurrentProduct().id
192+
193+
pr_client = env.setup_product_client(self.test_workspace)
194+
pr_config = pr_client.getProductConfiguration(product_id)
195+
self.assertIsNotNone(pr_config)
196+
184197
def test_editing(self):
185198
"""
186199
Test editing the product details (without reconnecting it).

0 commit comments

Comments
 (0)