Skip to content

Modify add/remove content fields do not properly handle non-valid inputs #3326

Closed

Description

@gerrod3

Version
pulpcore 3.22 (and probably most versions below)

Describe the bug
When parsing the content units for the add and remove fields for the modify endpoint, invalid inputs can cause a 500 error.

To Reproduce

# Using the pulp_file pytest fixtures
def test_bad_inputs(file_repo_api_client, file_random_content_unit):
     repo = file_repo_api_client.create(name="testing")
     body = {"add_content_units": file_random_content_unit}  # Valid form is file_random_conent_unit.pulp_href
     file_repo_api_client.modify(repo.pulp_href, body)

Expected behavior
The server should return a 400 stating the input for the add or remove field is invalid.

Additional context
Stack trace

pulp_1   | pulp [4c43a9c4-1225-4efc-94b7-3fb7093f5db5]: django.request:ERROR: Internal Server Error: /pulp/api/v3/repositories/file/file/c2fad42e-a21e-47b8-9f56-16514d850526/modify/
pulp_1   | Traceback (most recent call last):
pulp_1   |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
pulp_1   |     response = get_response(request)
pulp_1   |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
pulp_1   |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
pulp_1   |   File "/usr/local/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
pulp_1   |     return view_func(*args, **kwargs)
pulp_1   |   File "/usr/local/lib/python3.8/site-packages/rest_framework/viewsets.py", line 125, in view
pulp_1   |     return self.dispatch(request, *args, **kwargs)
pulp_1   |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
pulp_1   |     response = self.handle_exception(exc)
pulp_1   |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
pulp_1   |     self.raise_uncaught_exception(exc)
pulp_1   |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
pulp_1   |     raise exc
pulp_1   |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
pulp_1   |     response = handler(request, *args, **kwargs)
pulp_1   |   File "/src/pulpcore/pulpcore/plugin/actions.py", line 46, in modify
pulp_1   |     add_content_units[NamedModelViewSet.extract_pk(url)] = url
pulp_1   |   File "/src/pulpcore/pulpcore/app/viewsets/base.py", line 219, in extract_pk
pulp_1   |     match = resolve(urlparse(uri).path)
pulp_1   |   File "/usr/lib64/python3.8/urllib/parse.py", line 376, in urlparse
pulp_1   |     url, scheme, _coerce_result = _coerce_args(url, scheme)
pulp_1   |   File "/usr/lib64/python3.8/urllib/parse.py", line 128, in _coerce_args
pulp_1   |     return _decode_args(args) + (_encode_result,)
pulp_1   |   File "/usr/lib64/python3.8/urllib/parse.py", line 112, in _decode_args
pulp_1   |     return tuple(x.decode(encoding, errors) if x else '' for x in args)
pulp_1   |   File "/usr/lib64/python3.8/urllib/parse.py", line 112, in <genexpr>
pulp_1   |     return tuple(x.decode(encoding, errors) if x else '' for x in args)
pulp_1   | AttributeError: 'dict' object has no attribute 'decode'

Activity

  1. gerrod3 commented on Jan 25, 2023

    @gerrod3
    ContributorAuthor

    Related to #3486

  2. lubosmj commented on Feb 1, 2023

    @lubosmj
    Contributor

    Yes, the issues are related. I am attaching the snippet from the duplicate issue.

    pulp file remote create --name aaa --url https://fixtures.pulpproject.org/file/PULP_MANIFEST
    
    export REPO_HREF=$(pulp file repository create --name aaa --remote aaa | jq -r ".pulp_href")
    pulp file repository sync --name aaa
    
    export CONTENT_ORIGIN=$(pulp status | jq -r ".content_settings.content_origin")
    
    http ${CONTENT_ORIGIN}${REPO_HREF}modify/ remove_content_units:='[{"a": "b"}]' -v
    pulp [ab2982a30380488c92b083f1bdc1ff8c]: django.request:ERROR: Internal Server Error: /pulp/api/v3/repositories/file/file/b3f5c77a-6ede-4de4-9ce9-c245ce0aae19/modify/
    Traceback (most recent call last):
      File "/usr/local/lib/pulp/lib64/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
        response = get_response(request)
      File "/usr/local/lib/pulp/lib64/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "/usr/local/lib/pulp/lib64/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
        return view_func(*args, **kwargs)
      File "/usr/local/lib/pulp/lib64/python3.10/site-packages/rest_framework/viewsets.py", line 125, in view
        return self.dispatch(request, *args, **kwargs)
      File "/usr/local/lib/pulp/lib64/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
        response = self.handle_exception(exc)
      File "/usr/local/lib/pulp/lib64/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
        self.raise_uncaught_exception(exc)
      File "/usr/local/lib/pulp/lib64/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
        raise exc
      File "/usr/local/lib/pulp/lib64/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
        response = handler(request, *args, **kwargs) 
      File "/home/vagrant/devel/pulpcore/pulpcore/plugin/actions.py", line 61, in modify
        remove_content_units[NamedModelViewSet.extract_pk(url)] = url
      File "/home/vagrant/devel/pulpcore/pulpcore/app/viewsets/base.py", line 219, in extract_pk
        match = resolve(urlparse(uri).path)
      File "/usr/lib64/python3.10/urllib/parse.py", line 392, in urlparse
        url, scheme, _coerce_result = _coerce_args(url, scheme)
      File "/usr/lib64/python3.10/urllib/parse.py", line 128, in _coerce_args
        return _decode_args(args) + (_encode_result,)
      File "/usr/lib64/python3.10/urllib/parse.py", line 112, in _decode_args
        return tuple(x.decode(encoding, errors) if x else '' for x in args)
      File "/usr/lib64/python3.10/urllib/parse.py", line 112, in <genexpr>
        return tuple(x.decode(encoding, errors) if x else '' for x in args)
    AttributeError: 'dict' object has no attribute 'decode'
    
  3. self-assigned this
    on Feb 1, 2023
  4. moved this to In Progress in RH Pulp Kanban boardon Feb 1, 2023
  5. added a commit that references this issue on Feb 6, 2023
    a19e747
  6. moved this from In Progress to Needs review in RH Pulp Kanban boardon Feb 6, 2023
  7. added 2 commits that reference this issue on Feb 6, 2023
    5d26589
    eda234e
  8. added 3 commits that reference this issue on Feb 14, 2023
    3ddbc33
    0099df3
    6d46d6b
  9. added 3 commits that reference this issue on Feb 23, 2023
    e03b055
    847ce1d
    d0e5aa8
  10. added a commit that references this issue on Feb 23, 2023
    b2d6563
  11. moved this from Needs review to Done in RH Pulp Kanban boardon Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions