Skip to content

feat: adding mock certificate support for ssl testing#122

Merged
jaredwray merged 7 commits intomainfrom
feat-adding-mock-certificate-support-for-ssl-testing
Feb 13, 2026
Merged

feat: adding mock certificate support for ssl testing#122
jaredwray merged 7 commits intomainfrom
feat-adding-mock-certificate-support-for-ssl-testing

Conversation

@jaredwray
Copy link
Owner

@jaredwray jaredwray commented Feb 13, 2026

Please check if the PR fulfills these requirements

  • Followed the Contributing and Code of Conduct guidelines.
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
feat: adding mock certificate support for ssl testing

@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 introduces robust support for HTTPS within the MockHttp server, significantly improving its utility for testing SSL/TLS-enabled applications. By integrating a new certificate generation module, the server can now be configured to use either auto-generated or user-provided certificates, streamlining the setup for secure mock environments.

Highlights

  • Self-Signed Certificate Generation: Introduced a new utility (src/certificate.ts) capable of generating self-signed X.509 certificates and PKCS#8 private keys using Node.js's built-in crypto module. This includes comprehensive ASN.1 DER encoding helpers for various certificate components.
  • HTTPS Support for MockHttp: Enhanced the MockHttp class to support HTTPS. Users can now enable HTTPS by providing a boolean flag or an HttpsOptions object, which allows for specifying custom certificate and key files (PEM-encoded strings or file paths) or automatically generating a self-signed certificate.
  • Flexible Certificate Handling: The new HTTPS implementation offers flexibility in certificate management. It can automatically generate a self-signed certificate if none is provided, or load existing PEM-encoded certificates and keys from strings or file paths, making it suitable for various testing scenarios.
Changelog
  • src/certificate.ts
    • Added CertificateOptions and CertificateResult types for certificate generation.
    • Implemented encodeLength, encodeTlv, encodeSequence, encodeSet, encodeInteger, encodeBitString, encodeOctetString, encodeOid, encodeUtf8String, encodePrintableString, encodeUtcTime, encodeContextSpecific, and pad2 functions for ASN.1 DER encoding.
    • Defined OID constants for SHA256 with RSA, Common Name, and Subject Alternative Name.
    • Developed buildAlgorithmIdentifier, buildName, buildValidity, encodeIpAddress, expandIpv6, buildSubjectAltNameExtension, buildExtensions, and buildTbsCertificate for X.509 certificate structure assembly.
    • Included derToPem function to convert DER-encoded buffers to PEM format.
    • Exported generateCertificate function to create self-signed certificates programmatically.
    • Exported generateCertificateFiles function to generate and write certificates to disk.
  • src/mock-http.ts
    • Imported fsPromises and certificate generation utilities from certificate.ts.
    • Added HttpsOptions type to define configuration for HTTPS, including cert, key, autoGenerate, and certificateOptions.
    • Introduced a https property to MockHttpOptions to enable and configure HTTPS.
    • Added private fields _https and _httpsCredentials to manage HTTPS state and loaded credentials.
    • Implemented a getter and setter for the https property, allowing dynamic configuration of HTTPS.
    • Added an isHttps getter to indicate if the server is running in HTTPS mode.
    • Modified the start method to resolve HTTPS credentials based on _https configuration.
    • Updated the Fastify instance creation in start to conditionally include HTTPS options (key and cert) when _httpsCredentials are available.
    • Added resolveHttpsCredentials private method to handle loading PEM values from strings or files, or generating new certificates.
    • Added loadPemValue private method to read certificate/key content from file paths or return direct PEM strings.
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.

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: 78fdb3fd45

ℹ️ 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".

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 support for generating mock SSL certificates for testing purposes, enabling the mock server to run over HTTPS. The implementation for certificate generation is comprehensive but contains a critical bug in date encoding that could lead to invalid certificates for future dates. The integration into the MockHttp class is well-done, though there are some opportunities to improve code clarity and reduce duplication. I've provided comments to address the critical bug and suggest other improvements.

Comment on lines +218 to 226
} 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

This logic for handling the https option is duplicated in the https setter (lines 339-347). You can avoid this repetition and simplify the constructor by calling the setter directly.

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

Comment on lines +437 to +443
https: {
key: this._httpsCredentials.key,
cert: this._httpsCredentials.cert,
},
} as Record<string, unknown>) as unknown as FastifyInstance;
} else {
this._server = Fastify(getFastifyConfig(this._logging));

Choose a reason for hiding this comment

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

medium

The type assertion as Record<string, unknown>) as unknown as FastifyInstance suggests a potential typing issue and makes the code harder to read and less type-safe. It would be best to resolve the underlying type mismatch so the cast is not needed. The Fastify factory function should accept an options object with both logger and https properties. This might be solvable by ensuring getFastifyConfig returns a type compatible with FastifyOptions.

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

❌ Patch coverage is 97.38220% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.51%. Comparing base (e68c72f) to head (acb6424).
⚠️ 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     #122      +/-   ##
===========================================
- Coverage   100.00%   99.51%   -0.49%     
===========================================
  Files           36       37       +1     
  Lines          850     1040     +190     
  Branches       173      207      +34     
===========================================
+ Hits           850     1035     +185     
- 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.

@jaredwray jaredwray merged commit acb6424 into main Feb 13, 2026
7 of 9 checks passed
@jaredwray jaredwray deleted the feat-adding-mock-certificate-support-for-ssl-testing 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.

1 participant