Test that a string before the nesting does not hide it from the token's depth scan

Open Beginner friendly
#126 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
django, python
Domain
security, testing

Research direction

Start with the _shallow tests in tests/test_caller_backends.py and read the existing test_many_sibling_arrays_are_not_nesting test. Add the provided string-before-nesting cases and parametrize the sibling-array test over "[]" and "{}". Run the focused tests and confirm the new cases pass and catch both escaped-state mutants.

Written by the indexing model from the issue text.

Description

Non-blocking item from the approving review of #123. _shallow's tests (tests/test_caller_backends.py) put every string inside the deepest bracket, so they only check one direction: a string's brackets are not taken as nesting. Nothing checks that a string before the nesting does not hide it from the scan. Two mutants survive (dropping escaped = True on a backslash, and never resetting escaped), and either one brings back the SIGSEGV on a 1 MB thread.

Add (checked by the reviewer to pass at 3c39337 and to kill both mutants):

@pytest.mark.spec("HTTP-7")
@pytest.mark.parametrize("before", ['"\\""', '"\\\\"', '"\\\\\\""'])
def test_a_string_before_the_nesting_does_not_hide_it(before: str) -> None:
    head = text(header())[:-1] + ',"y":' + before + ',"x":' + "[" * 64 + "]" * 64 + "}"
    assert check(bearer(signed(raw_head=head)), IDENTITY, KEYS, NOW) == (None, None)

and parametrize test_many_sibling_arrays_are_not_nesting over "[]" and "{}".

Dominant language
Python
Stars
1
Forks
0
Avg merge
5h 30m
Merged PRs (30d)
85

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stack314/django-neolith

All issues in stack314/django-neolith

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.