Skip to content

Commit

Permalink
fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-willis committed Dec 13, 2024
1 parent 4446d2c commit b936b18
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/insomnia-sdk/src/objects/insomnia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ export async function initInsomniaObject(
const host = reqUrl.getHost().replace(/{{\s*\_\./g, '{{');
const renderedHost = variables.replaceIn(host);

const filteredCerts = filterClientCertificates(rawObj.clientCertificates || [], renderedHost, 'https:');
const renderedBaseUrl = toUrlObject(`${reqUrl.protocol}//${renderedHost}`);

const filteredCerts = filterClientCertificates(rawObj.clientCertificates || [], renderedBaseUrl.toString());
const existingClientCert = filteredCerts != null && filteredCerts.length > 0 && filteredCerts[0];
const certificate = existingClientCert ?
{
Expand Down
2 changes: 2 additions & 0 deletions packages/insomnia-sdk/src/objects/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ export function mergeClientCertificates(
...baseCertificate,
key: null,
cert: null,
name: updatedReq.certificate.name || '',
disabled: updatedReq.certificate.disabled || false,
passphrase: updatedReq.certificate.passphrase || null,
pfx: updatedReq.certificate.pfx?.src,
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ resources:
cert: {src: 'invalid.cert'},
passphrase: '',
pfx: {src: ''},
});
});
_type: request
- _id: req_89dade2ee9ee42fbb22d588783a9df3e
parentId: fld_01de564274824ecaad272330339ea6b2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ test.describe('pre-request features tests', async () => {
// update proxy configuration
await page.locator('text=Add Certificates').click();
await page.locator('text=Add client certificate').click();
await page.locator('[name="host"]').fill('a.com');
await page.locator('[name="host"]').fill('127.0.0.1');
await page.locator('[data-key="pfx"]').click();

const fileChooserPromise = page.waitForEvent('filechooser');
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/network/certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ClientCertificate } from '../models/client-certificate';
import { setDefaultProtocol } from '../utils/url/protocol';
import { urlMatchesCertHost } from './url-matches-cert-host';

export function filterClientCertificates(clientCertificates: ClientCertificate[], requestUrl: string, protocol: string) {
export function filterClientCertificates(clientCertificates: ClientCertificate[], requestUrl: string, protocol?: string) {
const res = clientCertificates.filter(c => !c.disabled && urlMatchesCertHost(setDefaultProtocol(c.host, protocol), requestUrl, true));
// If didn't get a matching certificate at the first time, ignore the port check and try again
if (!res.length) {
Expand Down

0 comments on commit b936b18

Please sign in to comment.