Skip to content

Commit 9b59aaa

Browse files
committed
chore: export getTestCertificatePath
1 parent b4d9bfa commit 9b59aaa

File tree

7 files changed

+49
-44
lines changed

7 files changed

+49
-44
lines changed

packages/e2e-tests/test/e2e-oidc.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
MongoRunnerSetup,
33
skipIfApiStrict,
44
skipIfEnvServerVersion,
5+
getTestCertificatePath,
56
} from '@mongosh/testing';
67
import { promises as fs } from 'fs';
78
import type { OIDCMockProviderConfig } from '@mongodb-js/oidc-mock-provider';
@@ -10,7 +11,7 @@ import type { TestShell } from './test-shell';
1011
import path from 'path';
1112
import { expect } from 'chai';
1213
import { createServer as createHTTPSServer } from 'https';
13-
import { getCertPath, readReplLogFile, useTmpdir } from './repl-helpers';
14+
import { readReplLogFile, useTmpdir } from './repl-helpers';
1415
import {
1516
baseOidcServerConfig,
1617
commonOidcServerArgs,
@@ -67,7 +68,7 @@ describe('OIDC auth e2e', function () {
6768
},
6869
};
6970
const httpsServerKeyCertBundle = await fs.readFile(
70-
getCertPath('server.bundle.pem')
71+
getTestCertificatePath('server.bundle.pem')
7172
);
7273
[oidcMockProvider, oidcMockProviderHttps] = await Promise.all([
7374
OIDCMockProvider.create(oidcMockProviderConfig),
@@ -411,7 +412,7 @@ describe('OIDC auth e2e', function () {
411412
it('can specify --tlsUseSystemCA as a no-op', async function () {
412413
await fs.mkdir(path.join(tmpdir.path, 'certs'), { recursive: true });
413414
await fs.copyFile(
414-
getCertPath('ca.crt'),
415+
getTestCertificatePath('ca.crt'),
415416
path.join(tmpdir.path, 'certs', 'somefilename.crt')
416417
);
417418

@@ -441,7 +442,7 @@ describe('OIDC auth e2e', function () {
441442
it('uses system ca by default when calling the IdP https endpoint', async function () {
442443
await fs.mkdir(path.join(tmpdir.path, 'certs'), { recursive: true });
443444
await fs.copyFile(
444-
getCertPath('ca.crt'),
445+
getTestCertificatePath('ca.crt'),
445446
path.join(tmpdir.path, 'certs', 'somefilename.crt')
446447
);
447448

packages/e2e-tests/test/e2e-proxy.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@ import {
1010
skipIfEnvServerVersion,
1111
startSharedTestServer,
1212
startTestServer,
13+
getTestCertificatePath,
1314
} from '@mongosh/testing';
1415
import type { Server as HTTPSServer } from 'https';
1516
import { createServer as createHTTPSServer } from 'https';
16-
import {
17-
connectionStringWithLocalhost,
18-
getCertPath,
19-
useTmpdir,
20-
} from './repl-helpers';
17+
import { connectionStringWithLocalhost, useTmpdir } from './repl-helpers';
2118
import { once } from 'events';
2219
import { connect } from 'net';
2320
import type { AddressInfo, Socket } from 'net';
@@ -32,8 +29,8 @@ import {
3229
skipOIDCTestsDueToPlatformOrServerVersion,
3330
} from './oidc-helpers';
3431

35-
const CA_CERT = getCertPath('ca.crt');
36-
const SERVER_BUNDLE = getCertPath('server.bundle.pem');
32+
const CA_CERT = getTestCertificatePath('ca.crt');
33+
const SERVER_BUNDLE = getTestCertificatePath('server.bundle.pem');
3734

3835
describe('e2e proxy support', function () {
3936
skipIfApiStrict();

packages/e2e-tests/test/e2e-tls.spec.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
import { expect } from 'chai';
22
import { promises as fs } from 'fs';
33
import path from 'path';
4-
import { startTestServer } from '@mongosh/testing';
4+
import { startTestServer, getTestCertificatePath } from '@mongosh/testing';
55
import {
66
useTmpdir,
77
setTemporaryHomeDirectory,
88
readReplLogFile,
9-
getCertPath,
109
connectionStringWithLocalhost,
1110
} from './repl-helpers';
1211

13-
const CA_CERT = getCertPath('ca.crt');
14-
const NON_CA_CERT = getCertPath('non-ca.crt');
15-
const CLIENT_CERT = getCertPath('client.bundle.pem');
16-
const CLIENT_CERT_PFX = getCertPath('client.bundle.pfx');
17-
const CLIENT_CERT_ENCRYPTED = getCertPath('client.bundle.encrypted.pem');
12+
const CA_CERT = getTestCertificatePath('ca.crt');
13+
const NON_CA_CERT = getTestCertificatePath('non-ca.crt');
14+
const CLIENT_CERT = getTestCertificatePath('client.bundle.pem');
15+
const CLIENT_CERT_PFX = getTestCertificatePath('client.bundle.pfx');
16+
const CLIENT_CERT_ENCRYPTED = getTestCertificatePath(
17+
'client.bundle.encrypted.pem'
18+
);
1819
const CLIENT_CERT_PASSWORD = 'p4ssw0rd';
19-
const INVALID_CLIENT_CERT = getCertPath('invalid-client.bundle.pem');
20-
const SERVER_KEY = getCertPath('server.bundle.pem');
21-
const SERVER_INVALIDHOST_KEY = getCertPath('server-invalidhost.bundle.pem');
22-
const CRL_INCLUDING_SERVER = getCertPath('ca-server.crl');
23-
const PARTIAL_TRUST_CHAIN_CA = getCertPath('partial-trust-chain/ca.pem');
24-
const PARTIAL_TRUST_CHAIN_KEY_AND_CERT = getCertPath(
20+
const INVALID_CLIENT_CERT = getTestCertificatePath('invalid-client.bundle.pem');
21+
const SERVER_KEY = getTestCertificatePath('server.bundle.pem');
22+
const SERVER_INVALIDHOST_KEY = getTestCertificatePath(
23+
'server-invalidhost.bundle.pem'
24+
);
25+
const CRL_INCLUDING_SERVER = getTestCertificatePath('ca-server.crl');
26+
const PARTIAL_TRUST_CHAIN_CA = getTestCertificatePath(
27+
'partial-trust-chain/ca.pem'
28+
);
29+
const PARTIAL_TRUST_CHAIN_KEY_AND_CERT = getTestCertificatePath(
2530
'partial-trust-chain/key-and-cert.pem'
2631
);
2732

packages/e2e-tests/test/repl-helpers.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,6 @@ const setTemporaryHomeDirectory = () => {
140140
return { homedir, env };
141141
};
142142

143-
function getCertPath(filename: string): string {
144-
return path.join(__dirname, '..', '..', 'testing', 'certificates', filename);
145-
}
146-
147143
// TLS requires matching hostnames, so here we need to explicitly
148144
// specify `localhost` + IPv4 instead of `127.0.0.1`
149145
async function connectionStringWithLocalhost(
@@ -166,7 +162,6 @@ export {
166162
readReplLogFile,
167163
fakeExternalEditor,
168164
setTemporaryHomeDirectory,
169-
getCertPath,
170165
connectionStringWithLocalhost,
171166
MongoLogEntryFromFile,
172167
};

packages/shell-api/src/field-level-encryption.spec.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import * as bson from 'bson';
1111
import { expect } from 'chai';
1212
import { EventEmitter } from 'events';
1313
import { promises as fs } from 'fs';
14-
import path from 'path';
1514
import { Duplex } from 'stream';
1615
import sinon from 'sinon';
1716
import type { StubbedInstance } from 'ts-sinon';
@@ -33,6 +32,7 @@ import {
3332
startSharedTestServer,
3433
makeFakeHTTPConnection,
3534
fakeAWSHandlers,
35+
getTestCertificatePath,
3636
} from '@mongosh/testing';
3737
import { Collection } from './collection';
3838
import { dummyOptions } from './helpers.spec';
@@ -84,10 +84,6 @@ const exampleUUID = new bson.Binary(
8484
4
8585
).toUUID();
8686

87-
function getCertPath(filename: string): string {
88-
return path.join(__dirname, '..', '..', 'testing', 'certificates', filename);
89-
}
90-
9187
describe('Field Level Encryption', function () {
9288
let sp: StubbedInstance<ServiceProvider>;
9389
let mongo: Mongo;
@@ -871,9 +867,11 @@ srDVjIT3LsvTqw==`,
871867
{
872868
endpoint: 'kmip.example.com:123',
873869
tlsOptions: {
874-
tlsCertificateKeyFile: getCertPath('client.bundle.encrypted.pem'),
870+
tlsCertificateKeyFile: getTestCertificatePath(
871+
'client.bundle.encrypted.pem'
872+
),
875873
tlsCertificateKeyFilePassword: 'p4ssw0rd',
876-
tlsCAFile: getCertPath('ca.crt'),
874+
tlsCAFile: getTestCertificatePath('ca.crt'),
877875
},
878876
},
879877
],
@@ -941,19 +939,20 @@ srDVjIT3LsvTqw==`,
941939
servername: 'kmip.example.com',
942940
port: 123,
943941
passphrase: 'p4ssw0rd',
944-
ca: await fs.readFile(getCertPath('ca.crt')),
942+
ca: await fs.readFile(getTestCertificatePath('ca.crt')),
945943
cert: await fs.readFile(
946-
getCertPath('client.bundle.encrypted.pem')
944+
getTestCertificatePath('client.bundle.encrypted.pem')
947945
),
948946
key: await fs.readFile(
949-
getCertPath('client.bundle.encrypted.pem')
947+
getTestCertificatePath('client.bundle.encrypted.pem')
950948
),
951949
},
952950
},
953951
]);
954952
return;
955953
}
956954
expect.fail('missed exception');
955+
break;
957956
default:
958957
throw new Error(`unreachable ${kmsName}`);
959958
}

packages/testing/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @mongosh/testing
22

3-
Internal testing utilities for mongosh packages. This package is only used for testing purposes within the mongosh monorepo.
3+
Internal testing utilities for mongosh packages. This package is private and only used for testing purposes within the mongosh monorepo.
44

55
## Contents
66

@@ -18,7 +18,3 @@ import {
1818
makeFakeHTTPServer,
1919
} from '@mongosh/testing';
2020
```
21-
22-
## Note
23-
24-
This package is marked as private and will not be published to npm.

packages/testing/src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
import path from 'path';
2+
13
export * from './integration-testing-hooks';
24
export * from './eventually';
35
export * from './fake-kms';
6+
7+
/**
8+
* Path to the certificates directory containing test certificates
9+
*/
10+
const TEST_CERTIFICATES_DIR = path.resolve(__dirname, '..', 'certificates');
11+
12+
/** Get the path to a test certificate */
13+
export function getTestCertificatePath(filename: string): string {
14+
return path.join(TEST_CERTIFICATES_DIR, filename);
15+
}

0 commit comments

Comments
 (0)