Skip to content

Commit 66f996e

Browse files
committed
chore: fix formatting and lint
1 parent d282ce0 commit 66f996e

File tree

6 files changed

+72
-50
lines changed

6 files changed

+72
-50
lines changed

packages/build/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { Config, PackageVariant } from './config';
99
import { updateJsonFeedCTA } from './download-center';
1010
import Ajv from 'ajv';
1111

12+
export { downloadCryptLibrary } from './packaging/download-crypt-library';
1213
export { getArtifactUrl, downloadMongoDb };
1314

1415
const validCommands: (ReleaseCommand | 'trigger-release' | 'update-cta')[] = [

testing/.eslintrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { fixCygwinPath } = require("@mongodb-js/eslint-config-mongosh/utils");
2+
3+
module.exports = {
4+
root: true,
5+
extends: ["@mongodb-js/eslint-config-mongosh"],
6+
parserOptions: {
7+
tsconfigRootDir: fixCygwinPath(__dirname),
8+
project: ["./tsconfig-lint.json"],
9+
},
10+
};

testing/fake-kms.ts

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
import DuplexPair from 'duplexpair';
2-
import http from 'http';
1+
import DuplexPair from "duplexpair";
2+
import http from "http";
33

44
// Exact values specified by RFC6749 ;)
5-
const oauthToken = { access_token: '2YotnFZFEjr1zCsicMWpAA', expires_in: 3600 };
5+
const oauthToken = { access_token: "2YotnFZFEjr1zCsicMWpAA", expires_in: 3600 };
66

7-
type RequestData = { url: string, body: string };
7+
type RequestData = { url: string; body: string };
88
type HandlerFunction = (data: RequestData) => any;
9-
type HandlerList = { host: RegExp, handler: HandlerFunction }[];
9+
type HandlerList = { host: RegExp; handler: HandlerFunction }[];
1010
type Duplex = NodeJS.ReadableStream & NodeJS.WritableStream;
1111

1212
// Return a Duplex stream that behaves like an HTTP stream, with the 'server'
1313
// being provided by the handler function in this case (which is expected
1414
// to return JSON).
15-
export function makeFakeHTTPConnection(handlerList: HandlerList): Duplex & { requests: http.IncomingMessage[] } {
15+
export function makeFakeHTTPConnection(
16+
handlerList: HandlerList
17+
): Duplex & { requests: http.IncomingMessage[] } {
1618
const { socket1, socket2 } = new DuplexPair();
1719
const server = makeFakeHTTPServer(handlerList);
18-
server.emit('connection', socket2);
20+
server.emit("connection", socket2);
1921
return Object.assign(socket1, { requests: server.requests });
2022
}
2123

@@ -26,29 +28,31 @@ export function makeFakeHTTPServer(handlerList: HandlerList): FakeHTTPServer {
2628
const server = http.createServer((req, res) => {
2729
(server as FakeHTTPServer).requests.push(req);
2830
let foundHandler: HandlerFunction | undefined;
29-
const host = req.headers['host'];
31+
const host = req.headers["host"];
3032
for (const potentialHandler of handlerList) {
31-
if (potentialHandler.host.test(host ?? '')) {
33+
if (potentialHandler.host.test(host ?? "")) {
3234
foundHandler = potentialHandler.handler;
3335
break;
3436
}
3537
}
3638
if (!foundHandler) {
3739
res.writeHead(404, {
38-
'Content-Type': 'text/plain'
40+
"Content-Type": "text/plain",
3941
});
4042
res.end(`Host ${host} not found`);
4143
return;
4244
}
4345
const handler = foundHandler; // Makes TS happy
4446

45-
let body = '';
46-
req.setEncoding('utf8').on('data', chunk => { body += chunk; });
47-
req.on('end', () => {
47+
let body = "";
48+
req.setEncoding("utf8").on("data", (chunk) => {
49+
body += chunk;
50+
});
51+
req.on("end", () => {
4852
res.writeHead(200, {
49-
'Content-Type': 'application/json'
53+
"Content-Type": "application/json",
5054
});
51-
res.end(JSON.stringify(handler({ url: req.url ?? '', body })));
55+
res.end(JSON.stringify(handler({ url: req.url ?? "", body })));
5256
});
5357
});
5458
return Object.assign(server, { requests: [] });
@@ -57,7 +61,7 @@ export function makeFakeHTTPServer(handlerList: HandlerList): FakeHTTPServer {
5761
export const fakeAWSHandlers: HandlerList = [
5862
{ host: /\.amazonaws\.com$/, handler: awsHandler },
5963
{ host: /\.microsoftonline.com$|\.azure.net$/, handler: azureHandler },
60-
{ host: /\.googleapis.com$/, handler: gcpHandler }
64+
{ host: /\.googleapis.com$/, handler: gcpHandler },
6165
];
6266

6367
function awsHandler({ body }: RequestData): any {
@@ -68,31 +72,35 @@ function awsHandler({ body }: RequestData): any {
6872
// both KeyId and Plaintext so that they are available for generating
6973
// the decryption response, which also provides the KeyId and Plaintext
7074
// based on the CiphertextBlob alone.
71-
const CiphertextBlob = Buffer.from(request.KeyId + '\0' + request.Plaintext).toString('base64')
75+
const CiphertextBlob = Buffer.from(
76+
request.KeyId + "\0" + request.Plaintext
77+
).toString("base64");
7278
return {
7379
CiphertextBlob,
74-
EncryptionAlgorithm: 'SYMMETRIC_DEFAULT',
75-
KeyId: request.KeyId
80+
EncryptionAlgorithm: "SYMMETRIC_DEFAULT",
81+
KeyId: request.KeyId,
7682
};
7783
} else {
78-
let [ KeyId, Plaintext ] = Buffer.from(request.CiphertextBlob, 'base64').toString().split('\0');
84+
let [KeyId, Plaintext] = Buffer.from(request.CiphertextBlob, "base64")
85+
.toString()
86+
.split("\0");
7987
// Do not return invalid base64 https://jira.mongodb.org/browse/MONGOCRYPT-525
80-
if (Buffer.from(KeyId, 'base64').toString('base64') !== KeyId) {
81-
KeyId = 'invalid0';
88+
if (Buffer.from(KeyId, "base64").toString("base64") !== KeyId) {
89+
KeyId = "invalid0";
8290
}
83-
if (Buffer.from(Plaintext, 'base64').toString('base64') !== Plaintext) {
84-
Plaintext = 'invalid1';
91+
if (Buffer.from(Plaintext, "base64").toString("base64") !== Plaintext) {
92+
Plaintext = "invalid1";
8593
}
8694
return {
8795
Plaintext,
88-
EncryptionAlgorithm: 'SYMMETRIC_DEFAULT',
89-
KeyId
96+
EncryptionAlgorithm: "SYMMETRIC_DEFAULT",
97+
KeyId,
9098
};
9199
}
92100
}
93101

94102
function azureHandler({ body, url }: RequestData): any {
95-
if (url.endsWith('/token')) {
103+
if (url.endsWith("/token")) {
96104
return oauthToken;
97105
} else if (url.match(/\/(un)?wrapkey/)) {
98106
// Just act as if this was encrypted.
@@ -101,12 +109,12 @@ function azureHandler({ body, url }: RequestData): any {
101109
}
102110

103111
function gcpHandler({ body, url }: RequestData): any {
104-
if (url.endsWith('/token')) {
112+
if (url.endsWith("/token")) {
105113
return oauthToken;
106-
} else if (url.endsWith(':encrypt')) {
114+
} else if (url.endsWith(":encrypt")) {
107115
// Here we also just perform noop encryption.
108116
return { ciphertext: JSON.parse(body).plaintext };
109-
} else if (url.endsWith(':decrypt')) {
117+
} else if (url.endsWith(":decrypt")) {
110118
return { plaintext: JSON.parse(body).ciphertext };
111119
}
112120
}

testing/integration-testing-hooks.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1+
/* eslint-disable mocha/no-exports */
12
import child_process from "child_process";
23
import { promises as fs } from "fs";
3-
import { MongoClient, MongoClientOptions } from "mongodb";
4+
import { MongoClient, type MongoClientOptions } from "mongodb";
45
import path from "path";
56
import semver from "semver";
67
import { promisify } from "util";
78
import which from "which";
89
import { ConnectionString } from "mongodb-connection-string-url";
9-
import { MongoCluster, MongoClusterOptions } from "mongodb-runner";
10-
import { downloadCryptLibrary } from "../packages/build/src/packaging/download-crypt-library";
10+
import { MongoCluster, type MongoClusterOptions } from "mongodb-runner";
11+
import { downloadCryptLibrary } from "@mongosh/build";
1112

1213
const execFile = promisify(child_process.execFile);
1314

14-
const isCI = !!process.env.IS_CI;
15-
function ciLog(...args: any[]) {
16-
if (isCI) {
17-
console.error(...args);
18-
}
19-
}
20-
2115
// Return the path to the temporary directory and ensure that it exists.
2216
async function getTmpdir(): Promise<string> {
2317
const tmpdir = path.resolve(__dirname, "..", "tmp");
@@ -26,6 +20,7 @@ async function getTmpdir(): Promise<string> {
2620
}
2721

2822
// Represents one running test server instance.
23+
// eslint-disable-next-line mocha/no-exports
2924
export class MongodSetup {
3025
_connectionString: Promise<string>;
3126
_setConnectionString: (connectionString: string) => void;
@@ -34,7 +29,9 @@ export class MongodSetup {
3429
_bindir = "";
3530

3631
constructor(connectionString?: string) {
37-
this._setConnectionString = (connectionString: string) => {}; // Make TypeScript happy.
32+
this._setConnectionString = () => {
33+
// no-op to make TypeScript happy.
34+
};
3835
this._connectionString = new Promise((resolve) => {
3936
this._setConnectionString = resolve;
4037
});
@@ -45,11 +42,11 @@ export class MongodSetup {
4542
}
4643

4744
async start(): Promise<void> {
48-
throw new Error("Server not managed");
45+
await Promise.reject(new Error("Server not managed"));
4946
}
5047

5148
async stop(): Promise<void> {
52-
throw new Error("Server not managed");
49+
await Promise.reject(new Error("Server not managed"));
5350
}
5451

5552
async connectionString(
@@ -115,7 +112,7 @@ export class MongodSetup {
115112
return await fn(client);
116113
} finally {
117114
if (client) {
118-
client.close();
115+
await client.close();
119116
}
120117
}
121118
}
@@ -193,18 +190,15 @@ async function getInstalledMongodVersion(): Promise<string> {
193190
return version;
194191
}
195192

196-
export async function downloadCurrentCryptSharedLibrary(
197-
versionSpec?: string
198-
): Promise<string> {
193+
export async function downloadCurrentCryptSharedLibrary(): Promise<string> {
199194
if (process.platform === "linux") {
200195
return (
201196
await downloadCryptLibrary(
202-
`linux-${process.arch.replace("ppc64", "ppc64le")}` as any,
203-
versionSpec
197+
`linux-${process.arch.replace("ppc64", "ppc64le")}` as any
204198
)
205199
).cryptLibrary;
206200
}
207-
return (await downloadCryptLibrary("host", versionSpec)).cryptLibrary;
201+
return (await downloadCryptLibrary("host")).cryptLibrary;
208202
}
209203

210204
/**

testing/tsconfig-lint.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["**/*"],
4+
"exclude": ["node_modules", "dist", "lib"]
5+
}

testing/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "@mongodb-js/tsconfig-mongosh/tsconfig.common.json",
3+
"include": ["**/*", "../packages/e2e-tests/test/integration-testing-hooks.ts"]
4+
}

0 commit comments

Comments
 (0)