Skip to content

Conversation

monam2
Copy link

@monam2 monam2 commented Aug 31, 2025

Description

Fixes #20681

Added support for multiple certificates in the resolveServerUrls function. Previously, only single certificates were supported, limiting HTTPS server configuration options.

  • Uses arraify to process certificate arrays and handle multiple certificates properly.
  • Added bufferify function for safe certificate conversion to Buffer format.
  • Implemented try-catch blocks to gracefully handle invalid certificates and prevent crashes.

All tests pass (unit, integration, and build tests all pass locally)


Test Coverage Added

  • No Certificate
  • Single Certificate
  • Multiple Certificates
  • IPv6 Support
  • Mixed Configurations (IPv4/IPv6 address families)
  • Invalid Certificate Handling

Note: Some test parameters use any types due to complex interface typing challenges. Type improvements are welcome.

Comment on lines 961 to 977
test('should handle IPv4 multiple certificates', () => {
const mockServer = createMockServer()
const { options, hostname, config } = createTestConfig()
const httpsOptions = { cert: [createWorkingCert] }

const result = resolveServerUrls(
mockServer,
options,
hostname,
httpsOptions,
config,
)

expect(result.local).toContain('https://localhost:3000/')
expect(result.local).toContain('https://foo.localhost:3000/')
expect(result.local).toContain('https://vite.vite.localhost:3000/')
})
Copy link
Contributor

Choose a reason for hiding this comment

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

The test name "should handle IPv4 multiple certificates" doesn't match the implementation, which only tests a single certificate wrapped in an array. For a proper multiple certificate test, consider using an array with at least two certificates:

const httpsOptions = { cert: [createWorkingCert, createAnotherCert] }

This would verify that the code correctly processes multiple certificates and extracts hostnames from all of them.

Suggested change
test('should handle IPv4 multiple certificates', () => {
const mockServer = createMockServer()
const { options, hostname, config } = createTestConfig()
const httpsOptions = { cert: [createWorkingCert] }
const result = resolveServerUrls(
mockServer,
options,
hostname,
httpsOptions,
config,
)
expect(result.local).toContain('https://localhost:3000/')
expect(result.local).toContain('https://foo.localhost:3000/')
expect(result.local).toContain('https://vite.vite.localhost:3000/')
})
test('should handle IPv4 multiple certificates', () => {
const mockServer = createMockServer()
const { options, hostname, config } = createTestConfig()
const httpsOptions = { cert: [createWorkingCert, createAnotherCert] }
const result = resolveServerUrls(
mockServer,
options,
hostname,
httpsOptions,
config,
)
expect(result.local).toContain('https://localhost:3000/')
expect(result.local).toContain('https://foo.localhost:3000/')
expect(result.local).toContain('https://vite.vite.localhost:3000/')
expect(result.local).toContain('https://another.cert.localhost:3000/')
})

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@monam2
Copy link
Author

monam2 commented Sep 1, 2025

Sorry for the confusion in the test cases.
I've updated the multiple certs tests to use the same cert twice and removed the mixed IPv4/IPv6 test case since it's not directly related to this work.

Any feedback on the certificate or implementation setup would be welcome.

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.

Support Extracting Hostnames From Multiple Certificates
1 participant