Skip to content

feat: adding mock certificate support for ssl testing#123

Merged
jaredwray merged 8 commits intomainfrom
claude/fix-https-credential-validation-VfVAk
Feb 13, 2026
Merged

feat: adding mock certificate support for ssl testing#123
jaredwray merged 8 commits intomainfrom
claude/fix-https-credential-validation-VfVAk

Conversation

@jaredwray
Copy link
Owner

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @jaredwray, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the MockHttp server by integrating robust HTTPS capabilities. It introduces a standalone module for generating self-signed SSL certificates, which is then seamlessly incorporated into the MockHttp class. This allows the mock server to operate securely over HTTPS, offering flexibility through automatic certificate generation or the use of custom certificates, thereby improving its utility for testing secure applications.

Highlights

  • Self-Signed Certificate Generation: A new utility (src/certificate.ts) has been added to generate self-signed X.509 certificates and private keys using only Node.js's built-in crypto module. This utility supports custom common names, subject alternative names (DNS and IP), validity periods, and key sizes. It also provides functions to write these certificates to disk.
  • HTTPS Support for MockHttp: The MockHttp class now includes comprehensive support for HTTPS. Users can enable HTTPS by setting the https option to true (which triggers auto-generation of a self-signed certificate), or by providing custom PEM-encoded certificate and private key strings or file paths.
  • Configurable HTTPS Options: The new HttpsOptions type allows for detailed configuration of HTTPS, including options for auto-generating certificates (e.g., common name, validity days) and specifying whether to load certificates from provided strings or file paths.
  • Type and Function Exports: New types (CertificateOptions, CertificateResult, CertificateFileOptions, HttpsOptions) and functions (generateCertificate, generateCertificateFiles) related to certificate management and HTTPS configuration are now exported from the main index.ts file, making them accessible to consumers of the library.
Changelog
  • src/certificate.ts
    • Added a new module for generating self-signed X.509 certificates and private keys.
  • src/index.ts
    • Exported new types and functions related to certificate generation and HTTPS options.
  • src/mock-http.ts
    • Added HttpsOptions type to configure HTTPS behavior.
    • Introduced https property to MockHttpOptions and MockHttp class for enabling and configuring HTTPS.
    • Implemented logic to resolve HTTPS credentials, including auto-generation and loading from strings or files.
    • Modified the start method to initialize the Fastify server with HTTPS options if configured.
  • test/certificate.test.ts
    • Added new test suite for generateCertificate and generateCertificateFiles functions, covering various options and PEM format validation.
  • test/mock-http.test.ts
    • Added new test suite for HTTPS functionality in MockHttp, verifying auto-generation, custom cert/key usage, and error handling.
Activity
  • The pull request was created by jaredwray.
  • No comments or reviews have been made yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

❌ Patch coverage is 97.40933% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.52%. Comparing base (e68c72f) to head (c1cafcd).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
src/certificate.ts 96.73% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #123      +/-   ##
===========================================
- Coverage   100.00%   99.52%   -0.48%     
===========================================
  Files           36       37       +1     
  Lines          850     1042     +192     
  Branches       173      208      +35     
===========================================
+ Hits           850     1037     +187     
- Misses           0        5       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1cafcd475

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +433 to +436
this._server = Fastify({
...getFastifyConfig(this._logging),
https: {
key: this._httpsCredentials.key,

Choose a reason for hiding this comment

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

P1 Badge Propagate HTTPS startup failures to callers

This HTTPS branch is executed inside start()'s broad try/catch, so malformed PEM input causes Fastify({ https: ... }) to throw, get logged, and then start() still resolves; callers can observe isHttps === true even though the server is not usable. This makes TLS misconfiguration look like a successful startup and breaks readiness/error handling paths that depend on await start() rejecting when startup fails.

Useful? React with 👍 / 👎.

Comment on lines +208 to +210
if (ip.includes(".")) {
const parts = ip.split(".").map(Number);
return Buffer.from(parts);

Choose a reason for hiding this comment

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

P2 Badge Parse IPv6-mapped addresses correctly in SAN encoding

The IP encoder classifies any value containing . as IPv4, so valid IPv6 text forms with embedded dotted quads (for example ::ffff:127.0.0.1) are mis-encoded as a 4-byte IPv4 SAN instead of a 16-byte IPv6 SAN. That produces certificates whose SubjectAltName does not match the requested IP representation and can cause TLS IP validation failures for those addresses.

Useful? React with 👍 / 👎.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant and well-implemented feature for HTTPS support, including a self-contained module for generating mock SSL certificates. The code is well-structured, and the comprehensive tests for certificate generation and its integration into MockHttp are excellent. My feedback includes minor suggestions to improve code clarity and reduce duplication.

const leftGroups = left ? left.split(":") : [];
const rightGroups = right ? right.split(":") : [];
const missing = 8 - leftGroups.length - rightGroups.length;
const middle = Array.from({ length: missing }).fill("0000") as string[];

Choose a reason for hiding this comment

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

medium

This line can be simplified. Array(n) creates a new array of length n, and .fill() can be called on it directly. This avoids the need for Array.from and the type assertion as string[], resulting in cleaner code.

Suggested change
const middle = Array.from({ length: missing }).fill("0000") as string[];
const middle = Array(missing).fill("0000");

Comment on lines +215 to +223
if (options?.https !== undefined) {
if (options.https === true) {
this._https = { autoGenerate: true };
} else if (options.https === false) {
this._https = undefined;
} else {
this._https = options.https;
}
}

Choose a reason for hiding this comment

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

medium

The logic for handling the https option is duplicated between the constructor and the https setter. You can simplify the constructor by calling the setter directly. This improves maintainability by centralizing the logic.

		if (options?.https !== undefined) {
			this.https = options.https;
		}

@jaredwray jaredwray merged commit 1abdff0 into main Feb 13, 2026
7 of 9 checks passed
@jaredwray jaredwray deleted the claude/fix-https-credential-validation-VfVAk branch February 13, 2026 18:49
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.

2 participants