Skip to content

[repo-assist] test: add unit tests for SchemaReader.validateContentType - #491

Merged
sergey-tihon merged 1 commit into
masterfrom
repo-assist/test-validateContentType-coverage-cea7c0dce32ce8d4
Sep 9, 2026
Merged

[repo-assist] test: add unit tests for SchemaReader.validateContentType#491
sergey-tihon merged 1 commit into
masterfrom
repo-assist/test-validateContentType-coverage-cea7c0dce32ce8d4

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

What

Adds direct unit test coverage for SchemaReader.validateContentType in Utils.fs — the SSRF Content-Type allow-list check invoked after fetching a remote schema over HTTP(S). This function had zero direct unit tests despite being a security-relevant guard (it prevents processing of non-schema responses such as HTML, images, or binaries that a compromised/malicious endpoint could return during an SSRF attempt).

New tests (14)

  • Allowed schema media types: application/json, application/yaml, application/x-yaml, text/yaml, text/x-yaml, text/plain, application/octet-stream
  • Charset-parameter stripping (application/json; charset=utf-8)
  • Case-insensitive media-type comparison
  • Null Content-Type is tolerated (some servers omit the header)
  • Rejection of non-schema types (text/html, image/png) with Invalid Content-Type message
  • Full bypass of validation when SsrfProtection=false (development mode), for both a disallowed type and null

Why

Existing SsrfSecurityTests.fs thoroughly covers URL-scheme and IP-range SSRF protections but had no tests for the Content-Type layer of the same defense-in-depth mechanism. This closes that gap with minimal, self-contained tests that exercise the pure function directly (no network calls).

Trade-offs

None — purely additive test coverage; no production code changed.

Test Status

  • Build: dotnet build SwaggerProvider.sln -c Release succeeded (0 errors).
  • Format: dotnet fantomas --check on the modified file passes.
  • Unit tests: 562 passed (548 → 562, +14), 1 skipped (pre-existing, unrelated), 0 failed.
  • Integration/provider tests: not run (requires separate test-server build/start; unaffected by this change).

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@ae8d551f07c7ed7619f8c58c7bb4c3ac89395d38

Adds direct unit test coverage for validateContentType, the SSRF
Content-Type allow-list check used when reading remote schemas.
Previously this security-relevant function had no dedicated tests.

Covers: allowed schema media types (json/yaml variants, text/plain,
octet-stream), charset-parameter stripping, case-insensitive
comparison, null Content-Type handling, rejection of non-schema
types (text/html, image/png), and full bypass when SSRF protection
is disabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sergey-tihon
sergey-tihon marked this pull request as ready for review September 9, 2026 15:08
Copilot AI lite review requested due to automatic review settings September 9, 2026 15:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The PR is purely additive test coverage with no production code changes and low risk to the codebase.

Pull request overview

Adds direct unit-test coverage for SwaggerProvider.Internal.SchemaReader.validateContentType, the SSRF-related Content-Type allow-list guard used when fetching remote schemas.

Changes:

  • Added a new ContentTypeValidationTests module with 14 unit tests covering allowed/disallowed media types, case-insensitive matching, charset presence, null Content-Type handling, and the SsrfProtection=false bypass path.
File summaries
File Description
tests/SwaggerProvider.Tests/SsrfSecurityTests.fs Adds unit tests targeting validateContentType to strengthen SSRF defense-in-depth coverage.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +379 to +383
let ``Allow Content-Type with charset parameter``() =
// e.g. "application/json; charset=utf-8" — parameters must be stripped before comparison
let contentType = MediaTypeHeaderValue("application/json")
contentType.CharSet <- "utf-8"
validateContentType false contentType
@sergey-tihon
sergey-tihon merged commit 87633e4 into master Sep 9, 2026
10 checks passed
@sergey-tihon
sergey-tihon deleted the repo-assist/test-validateContentType-coverage-cea7c0dce32ce8d4 branch September 9, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants