Files
project-work/sources/notes.md
2026-11-12 16:08:41 -05:00

21 KiB
Raw Permalink Blame History

After all tasks created

  • Use full variable names in the new tests.
  • Review all tests in the test files edited or created; refactor the tests using dry-principle.md.
  • PRINCIPLE - another experiment: write as many good tests as I could have it do. Not just good tests - as many as it can. (this way you justify so many tests for just the searches concern)
  • Step3 had to correct it's way of generating a heading "Form exposure" to "Accepted search types versus implemented search types" - speak more simply is my goal. Form Exposure was correct and erudite. But it wasn't clear communication. I love the submission checklist - saved my *ss again. suggestions - in sandbox, paste text is available, need a copy text too - I generated a coverage report and had to snap shot it to capture it. Copy would be better.

===

None of the items on the scanner's list expose anything in production; they're all false positives or test data. But the folder does hold one real risk the list doesn't name: a tracked database backup containing working admin logins.

The listed items

┌─────────────────────────┬─────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Category │ Verdict │ Why │ ├─────────────────────────┼─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────┤ │ API key sk_/pk_/api_ │ False positive │ Every hit is an import line. The text api_ appears in module names like │ │ (7) │ │ api_object_data_permissions_v0. │ ├─────────────────────────┼─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────┤ │ HashiCorp Vault token │ │ This is the vendored TinyMCE editor library. Its minified code has strings like │ │ (2) │ False positive │ s.stopImmediatePropagation that look like the old Vault token format s.xxxx. No real token is │ │ │ │ in there. │ ├─────────────────────────┼─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Password passed to a │ False positive │ The matches are Vue item-key="kanban_card_id" attributes. │ │ command (3) │ │ │ ├─────────────────────────┼─────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Password/key/token in │ False positive (4) │ models.py and the two migrations match on default=uuid.uuid4. The 16 test files set password = │ │ code (20) │ / test data (16) │ "Test1234$", the test-suite password. │ ├─────────────────────────┼─────────────────────┼────────────────────────────────────────────────────────────────────┤ │ Email addresses (20) │ Not sensitive │ Project role addresses (support@, noreply@), made-up test domains (nearbeahc.org, │ │ │ fardesert.oks like a real person's data. │ └─────────────────────────┴─────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────┘
Real exposure risks the list doesn't spell out
These were probably among the "more were found" hits.

  1. db.sqlite3-bak: high. It's a 1.2 MB SQLite backup, and git tracks it. It contains: - 8 users, 2 of them superusers (admin, dark_admin). All ecked each stored hash.
    • A 2FA (TOTP) device record including its secret key. I didn't print the key. - 36 sessions and 8 knox token digests. All of them expirores only digests, so none can be reused directly.
    • 5 document records and 1 customer, all demo data.
      It isn't shipped in the package, because MANIFEST.in only includes NearBeach/*. The danger is someone renaming it to db.sqlite3 and deploying: that site would have known superuser logins on day one. My recrom the repo. I didn't delete it because that's your call.
  2. Hardcoded SECRET_KEY in local/settings.py:26: medium. It's labelled as test-only settings. But anyone who copies this file to start a deployment inherits a public signing key, which lets an attacker forinks and other signed values.
  3. Fixture superusers with known passwords: low to medium. All 15 accounts across the three files in NearBeach/fixtures/ use Test1234$, including 4 superusers. Unlike the backup, these files are shipped in harm if someone runs loaddata against a production database,but that's an easy mistake to make.
    For the scanner design
    This is a useful test set for the CLI we discussed. It shows that matching on text patterns alone produces a lot of noise: 32 of the 52 listed hits were false positives. Three rules would have found the real
  • tracked database or backup files;
  • SECRET_KEY written in as a literal value;
  • fixture files with superusers that have a known or weak password.

===

❯ how do I run NearBeach/?

Thought for 25s, ran 4 shell commands

You can run it locally with Django's development server; no Docker needed. Your machine already has Python 3.11 and Node 24, and the compiled frontend files are committed, so you don't need npm. I haven't run any of this; it comes from the project's setup docs (docs/002-local-development-environment-setup/index.rst) and from reading the code.

cd /home/eric/workspaces/dataannotation/project-6/NearBeach

python3 -m venv venv source venv/bin/activate pip install -r requirements-dev.txt

python manage.py migrate # creates a fresh db.sqlite3 python manage.py createsuperuser python manage.py runserver

Then open http://localhost:8000/login (the Django admin is at /admin/).

Things that will trip you up

  • Use localhost, not 127.0.0.1. ALLOWED_HOSTS in local/settings.py lists localhost, 0.0.0.0 and 192.168.1.105. Going to 127.0.0.1 gives a "DisallowedHost" error. The docs suggest editing the settiot to commit changes to it, so using localhost avoids theproblem.
  • The first login does extra setup. Logging in with a user tts you logged straight out. The first login also runsinitalize_base_values, which creates the permission sets, an admin group with your user in it, and a "No Organisation" record. A fresh superuser should therefore get in, but other users need adding to a
  • Skip manage.py initaliazeobjects. It calls User.objects.get(is_admin=True).first(), which fails because User has no is_admin field and .first() doesn't work on a single object.
  • Email and 2FA: you don't need SMTP settings to run it. Two-factor login is optional per user.

Option: start with demo data instead

To get the same users, groups and objects the tests use: python manage.py migrate python manage.py loaddata NearBeach_basic_setup.json Then log in as admin with password Test1234$. As I flagged eords, so only do this locally.

Only if you change the Vue code

npm install npm run watch # or: npm run prod for a one-off build The build output goes to NearBeach/static/NearBeach/, which up.

Leave these alone

  • db.sqlite3-bak: the settings point at db.sqlite3, so the bname it to run the app: it holds the eight Test1234$ users and the 2FA key.
  • local/settings.py: don't commit changes to it. The projectholds the hardcoded SECRET_KEY.

Do you want me to set it up and start the server for you?

❯ list the steps starting with 'cd' and this time include the option to start w/demo data

Thought for 9s

Choose either 4a or 4b at step 4.

  1. Go to the project folder cd /home/eric/workspaces/dataannotation/project-6/NearBeach

  2. Create and activate a virtual environment python3 -m venv venv source venv/bin/activate

  3. Install the Python dependencies pip install -r requirements-dev.txt

  4. Set up the database (choose one)

    4a. Empty database with your own admin user python manage.py migrate python manage.py createsuperuser Your first login automatically creates the permission sets, the admin group and the "No Organisation" record.

    4b. Demo data (the same users, groups and objects the tests use) python manage.py migrate python manage.py loaddata NearBeach_basic_setup.json Log in as admin with password Test1234$. Other accounts include team_leader, team_member, read_only and dark_admin, all with the same password. Only use this locally.

  5. Start the server python manage.py runserver

  6. Open the app

  7. Optional, only if you change the Vue code npm install npm run watch

To stop the server press Ctrl+C. Run deactivate to leave the virtual environment. To start fresh, delete db.sqlite3 and repeat from step 4. Don't touch db.sqlite3-bak.

step 1 response The environment is set up and both baselines are captured: all 114 tests pass. I mapped the nine search categories and propose 27 new test methods below. The baselines turned up four existing defects, including one 500 error, and several places where access is looser than the matching page, which need your decision before I write tests. No production code or tests were changed, and the working tree is clean apart from the gitignored venv/. Environment and baselines

Setup: the documented virtualenv venv command failed (virtualenv: command not found). I used python3 -m venv venv, which is what CircleCI does, then pip install -r requirements-dev.txt and coverage. Python is 3.12.3.
Unpinned versions: requirements.txt only sets minimums, so pip installed Django 6.1.3, DRF 3.18.3 and knox 5.1.0. CI would get the same latest versions. manage.py check reports no issues.
Existing search suite (manage.py test NearBeach.tests.tests_views.tests_search -v 2): 4 tests, all pass (8.1s, 32s wall-clock). They check status codes only, and several post search payloads to the search page rather than search_data.
Full suite (the CI command, under coverage): Ran 114 tests in 671.508s, OK. No failures, errors or skips, and no warnings in the output. That makes any later failure new.

Statement coverage Search suite alone Full suite search/search_objects.py 93.1% (54/58) 93.1% search_views.py 54.2% (103/190) 58.9% (112/190)

With branch coverage the figures are 89% / 50% (search suite) and 89% / 54% (full suite). To reach 80%, search_views.py needs at least 152 of its 190 statements covered. Line 108 in search_objects.py can only be reached through the 500 error below. Contract map

Shared rules:

Every search term is split on spaces, each word must match (case-insensitive substring), and an empty search matches everything.
The search field is limited to 250 characters; longer input returns 400.
Soft-deleted records are always excluded.
Logged-out users are sent to /login with no next parameter. Exceptions: the notification page sends them to /, and a GET to a POST-only endpoint returns 405 before the login check, except for sprint data.

Category Endpoints Request Response and matching Order / limit / pages Closed filter Access Main search/ (page), search/data/ (POST) array_of_objects (required, list), destination_page (required), search, include_closed, include_all_groups, exclude_destination + exclude_location_id For each requested type: {type: [{id,title,status}], type_number_of_pages, type_current_page}. Title match; a numeric word also matches the exact ID. Newest ID first (model default); 5 per page; page ≤1 gives page 1; pages past the end return []; current_page echoes the input Yes; rule differs by type (below) Logged in; only objects assigned to the user's groups. Superusers see everything only with include_all_groups Customer search/customer/, …/data/ (POST) search Django serializer list [{model,pk,fields}]; matches first name, last name or organisation name Last name, first name; max 50 No Logged in Organisation search/organisation/, …/data/ (POST) search Serializer list; matches organisation_name Name; max 25 No Logged in Group search/group/, …/data/ (GET or POST) search Serializer list; matches group_name Name; max 25 No Page: admin permission (administration_create_user ≥3) or superuser. Data: any logged-in user User search/user/, …/data/ (POST) search Plain list [{id,email,first_name,last_name,username}]; matches any of those four text fields; inactive users included Last name, first name; max 50 No Page: admin permission. Data: any logged-in user Sprint search/sprint/, …/data/ (POST) Same form as main search; array_of_objects=sprint is required {sprint: [{sprint_id,sprint_name,sprint_status}], sprint_number_of_pages, sprint_current_page} Newest first; 5 per page Hides Finished sprints Logged in; only sprints on projects or requirements in the user's groups, with no superuser bypass. Logged-out GET → 302 (not 405) Tag search/tag/ only (filtered in the browser) none Page context: tag_results, user_level Name No Tag permission ≥1 (superusers get level 4) Notification search/notification/, …/data/ (POST) search Serializer list; matches header or message Header; max 25 No Page: superuser only (everyone else → 302 to /). Data: any logged-in user Permission set search/permission_set/, …/data/ (POST) search Serializer list; matches permission_set_name Name; max 25 No Page: admin permission. Data: any logged-in user

Main search object types vs. the nine categories:

The form accepts 12 values for array_of_objects, but only 6 are actually searchable: kanban_board, project, request_for_change, requirement, requirement_item and task.
The status field has a different type depending on the object: RFCs return an integer, kanban boards a string, and the rest a status label.
"Closed" means something different per type: RFC statuses 5 and 6, kanban status Closed, and for the others a status whose higher-order status is Closed.
Requirement items are visible when the user can see the parent requirement.
search/scheduled_objects/ is also in search_views.py but isn't one of the nine categories.

Existing defects (confirmed, not fixed)

500 error in main search: posting a value the form accepts but search doesn't support (e.g. array_of_objects=customer) crashes with TypeError: cannot unpack non-iterable NoneType.
500 for users with no groups: the group, user, permission-set and tag pages all crash with TypeError: '>=' not supported…. The bug is in the permission decorators, not the search modules.
Looser access on data endpoints: the group, user, permission-set and notification data endpoints don't enforce their page's permission check, and group data also accepts GET.
current_page echoes the raw input: sending 0 or 99 returns 0 or 99, even though the results are page 1 or empty.

Proposed tests (27, plus one optional)

They would go in a new file under tests/tests_views/tests_search/, using the NearBeach_basic_setup.json fixture and force_login.

Main (10):
    Response keys and row shape for each type; types not requested are absent.
    Results limited to the user's groups (team lead sees only ID 2, including the requirement item via its parent).
    include_all_groups works for superusers only (dark_admin sees [1] or [2,1]; for the team lead it's ignored).
    Multiple words are combined with AND and matching is case-insensitive.
    A numeric word matches the ID but still respects group access.
    Closed objects are excluded per type unless include_closed is set (one subtest per type, plus RFC statuses 5 and 6).
    Pagination and ordering: 7 projects split 5 + 2, newest first, page 3 empty, page 0 returns page 1.
    exclude_destination only applies when the ID is also sent.
    Validation and method: 400 for missing or invalid fields, 405 for GET, redirect for logged-out users.
    The search page shows search_input and is_superuser, and returns 400 over 250 characters.
Customer (2): 11. Matching on names and organisation, ordering, serializer format, deleted records excluded. 12. 400 error text, 405 for GET, page context.
Organisation (2): 13. Ordering, deleted records excluded, 25-result cap. 14. 400 for invalid input, page context.
Group (3): 15. Page: admin gets 200, team lead gets 403. 16. Data matching, ordering, deleted records excluded. 17. 400 for invalid input.
User (2): 18. Page access and context fields. 19. Matching on each of the four fields, ordering, and only the five allowed keys returned (no password); 400 for invalid input.
Sprint (3): 20. Group scoping (team lead [4,2], admin [4,3,2,1]). 21. Finished sprints hidden unless include_closed; search words. 22. Pagination; 400 / 405 / 302 cases; page renders.
Tag (1): 23. Page context user_level (4 for team lead, 1 for read-only, 4 for admin); tags ordered by name with deleted ones excluded.
Notification (2): 24. Page is superuser-only; everyone else → 302 to /. 25. Data matches header or message, ordering; 400 and 405 cases.
Permission set (2): 26. Page access (admin 200, team lead 403). 27. Data matching ("read only" returns both read-only sets) and ordering; 400.
Optional: one scheduled-objects test, for coverage only.

Projected coverage from the search suite alone: about 95% or more for search_views.py and 57/58 (98%) for search_objects.py. Decisions for you

The two 500 errors: should the tests leave them out (my recommendation), or mark them as expectedFailure? Writing tests that expect a 500 would lock the bugs in.
The looser data-endpoint access: should tests assert that non-admins can use those four data endpoints? That would lock in what may be a security gap; otherwise the tests just won't assert on it.
How to measure the 80% target: on the search suite alone (stricter, my suggestion) or on the full suite?

Logs, the exact package versions and my probe scripts are in /tmp/probe/.