Skip to content

test: take client addresses in the session-store and connection-limit tests from test-constants - #702

Merged
billchurch merged 3 commits into
mainfrom
issue-701-test-take-client-addresses-in-the-sessio
Dec 5, 2026
Merged

billchurch merged 3 commits into
mainfrom
issue-701-test-take-client-addresses-in-the-sessio

Conversation

@billchurch

Copy link
Copy Markdown
Owner

Closes #701

What

SonarCloud S1313 (hardcoded IP addresses) flagged test fixtures in two test files added with the resource-limits work. This moves every address and network key in them into named constants in tests/test-constants.ts, as the testing rule asks. No behaviour change: only test code moves.

  • tests/test-constants.ts: new constants TEST_SUBNETS.PRIVATE_192_2_24, DOCUMENTATION_V6_CLIENT_KEY_64, LOCALHOST_V6_CLIENT_KEY_64, DOCUMENTATION_V6_SUBNET_48, DOCUMENTATION_V6_SUBNET_ALT_48, and TEST_IPS.DOCUMENTATION_V6_EXPANDED_UPPER, each with //NOSONAR like the existing entries.
  • tests/unit/middleware/session-store-policy.vitest.ts: the expected /24, /48 and /64 keys and the expanded upper-case IPv6 address now come from those constants, plus the existing TEST_SUBNETS.PRIVATE_192 and PRIVATE_10_24.
  • tests/unit/services/connection-limits.vitest.ts: ::1, fe80::1%eth0 and 2001:db8::1 use the existing TEST_IPS constants; the ULA sample fd12:3456::1 becomes the existing TEST_IPS.UNIQUE_LOCAL_V6 (fd00::5), still a unique-local address, so the test checks the same thing.

The other test files added in the same change were scanned for IP literals in single, double and template strings without //NOSONAR; these two files were the only ones with any.

Checks (local)

  • npm run lint: 0 errors
  • npm run lint:sonar: 0 errors; the 2 warnings are in app/config/trust-proxy.ts, which this PR doesn't touch. The changed files alone: clean
  • npm run typecheck: clean
  • npm test: 206 files passed, 2 skipped; 3182 tests passed, 11 skipped

SonarCloud: scripts/sonar-pr.sh result posted below once the analysis runs.

…ection-limit tests from test-constants

Move the hardcoded IPv4/IPv6 addresses and network keys in
session-store-policy.vitest.ts and connection-limits.vitest.ts into named
constants in tests/test-constants.ts (SonarCloud S1313). No behaviour change.
@billchurch

Copy link
Copy Markdown
Owner Author

Standards review (head d681631)

Reviewed git diff origin/main..HEAD (3 test files, no app code) against AGENTS.md and .claude/rules/{testing,typescript,security}.md.

  • Testing rule (test IPs from tests/test-constants.ts): met. No IP or network literal is left in either file; the only remaining string fixture is 'nonsense', which isn't an address.
  • Constants file conventions: new entries go in the existing TEST_SUBNETS / TEST_IPS groups, follow their SCREAMING_SNAKE naming, and carry //NOSONAR like their neighbours (the file is where S1313 literals are meant to live). Existing constants are reused wherever one already had the exact value (TEST_SUBNETS.PRIVATE_192, PRIVATE_10_24; TEST_IPS.LOCALHOST_V6, LINK_LOCAL_V6_ZONE, DOCUMENTATION_V6, UNIQUE_LOCAL_V6).
  • TypeScript style: ESM .js import, single quotes, no semicolons, no any. A first pass left three changed lines over 100 characters; fixed in d681631, and no added line is over 100 now.
  • Lint: npm run lint 0 errors; eslint -c eslint.config.sonar.mjs on the three changed files: clean.

Findings: none open (the one minor line-length finding is fixed).

@billchurch

Copy link
Copy Markdown
Owner Author

Spec review against #701 (head d681631)

Issue asks Done
Move the client addresses flagged in session-store-policy.vitest.ts (alerts #113–#118) into tests/test-constants.ts Yes. Every address and network-key literal in the file, including lines 102–107, 119, 122, 124 and 132, now comes from TEST_IPS / TEST_SUBNETS
The same in connection-limits.vitest.ts (alerts #119, #120, lines 166–167) Yes. Lines 165–167 and the 2001:db8::1 on 171 use TEST_IPS constants
Named constants for client and network addresses, documentation ranges where used Yes. The new names say what each value is (*_CLIENT_KEY_64, *_SUBNET_48, PRIVATE_192_2_24, DOCUMENTATION_V6_EXPANDED_UPPER). The IPv6 fixtures were already in 2001:db8::/32. The IPv4 fixtures stay on the existing private-range constants because networkKeyFor's /24 grouping is what the tests check, so swapping to 192.0.2.0/24 would change the fixtures without adding anything
Check the other test files added in the same change Done. Searched every test line added by b523efc1 for IPv4/IPv6 literals in single, double and template strings without //NOSONAR: these two files were the only hits
No behaviour change Holds. Test-only diff; every replacement has the same string value, except fd12:3456::1 → TEST_IPS.UNIQUE_LOCAL_V6 (fd00::5), still a ULA (fc00::/7), so the assertion checks the same thing
Checks: lint, lint:sonar, typecheck, npm test, then scripts/sonar-pr.sh clean See the checks comment. sonar-pr.sh: gate OK, 0 issues, 0 hotspots. The alerts close when the branch's SonarCloud result reaches main (still open on the default branch until then; none open on refs/pull/702/merge)

Findings: none.

@billchurch

Copy link
Copy Markdown
Owner Author

Checks at head d68163189bf2b984e320d7d004d190ddd57b1de7

Local (after npm ci --ignore-scripts and npm rebuild better-sqlite3, as CI does):

Check Result
npm run lint pass, 0 errors
npm run lint:sonar 0 errors; 2 warnings, both in app/config/trust-proxy.ts (untouched here). Changed files: clean
npm run typecheck pass
npm test pass: 206 files passed, 2 skipped; 3182 tests passed, 11 skipped
scripts/sonar-pr.sh 702 exit 0: quality gate OK at d68163189bf2, 0 open issues, 0 hotspots

CI on this head (run 47461180305):

Check Result
docker-image-scan pass
dependency-review pass
SonarCloud Code Analysis pass
build-lint-test fail, but only at the Security audit step. Lint, typecheck, build and unit/integration tests passed. npm audit --audit-level=high fails on the HIGH advisories for engine.io (GHSA-c8pq-854x-25q2, also hits socket.io) and cross-spawn (GHSA-w3gc-668g-rf8f, also hits eslint). main fails the same way at b523efc1 (run 47459232633), so this PR didn't cause it. #703 (for #700) fixes both. Once it merges, I'll merge origin/main into this branch so build-lint-test goes green

@billchurch
billchurch marked this pull request as ready for review December 5, 2026 01:30
@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

@billchurch

Copy link
Copy Markdown
Owner Author

Checks at head 01196810b68ca991c764ee3556196c4f783eb3b3

This head merges origin/main, which now includes #703. The PR's own diff is unchanged (the same 3 test files), so the standards and spec reviews above still apply.

Local (after npm ci --ignore-scripts and npm rebuild better-sqlite3):

Check Result
npm run lint pass, 0 errors
npm run lint:sonar 0 errors; the same 2 warnings in app/config/trust-proxy.ts (untouched here)
npm run typecheck pass
npm test pass: 206 files passed, 2 skipped; 3187 tests passed, 11 skipped
npm audit --audit-level=high pass
scripts/sonar-pr.sh 702 exit 0: quality gate OK at 01196810b68c, 0 open issues, 0 hotspots

CI (run 47461976665): build-lint-test pass, docker-image-scan pass, dependency-review pass, SonarCloud Code Analysis pass (Trivy skipped, as the workflow does on PRs).

@billchurch
billchurch merged commit 2b34408 into main Dec 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: take client addresses in the session-store and connection-limit tests from test-constants (S1313 #113-#120)

1 participant