Skip to content

Commit 728b582

Browse files
committed
chore: run reformat properly
1 parent 48a7ec5 commit 728b582

File tree

8 files changed

+117
-92
lines changed

8 files changed

+117
-92
lines changed

testing/.eslintrc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const { fixCygwinPath } = require("@mongodb-js/eslint-config-mongosh/utils");
1+
const { fixCygwinPath } = require('@mongodb-js/eslint-config-mongosh/utils');
22

33
module.exports = {
44
root: true,
5-
extends: ["@mongodb-js/eslint-config-mongosh"],
5+
extends: ['@mongodb-js/eslint-config-mongosh'],
66
parserOptions: {
77
tsconfigRootDir: fixCygwinPath(__dirname),
8-
project: ["./tsconfig.json"],
8+
project: ['./tsconfig.json'],
99
},
1010
};

testing/.prettierrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"@mongodb-js/prettier-config-devtools"

testing/certificates/README.md

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This directory contains all certificates and keys used in testing.
55
To recreate the certificates follow the steps outlined below.
66

77
## Setup CA
8+
89
1. Create a new key to use for the CA:
910
```
1011
openssl genrsa -out ca.key 4096
@@ -13,10 +14,11 @@ To recreate the certificates follow the steps outlined below.
1314
```
1415
openssl req -new -x509 -key ca.key -out ca.crt -days 99999
1516
```
16-
* Organization Name: `MongoDB`
17-
* Organizational Unit Name: `DevTools`
18-
* Common Name: `DevTools CA`
17+
- Organization Name: `MongoDB`
18+
- Organizational Unit Name: `DevTools`
19+
- Common Name: `DevTools CA`
1920
3. To sign and revoke certificates, an openssl config files is required. Create `ca.cnf` with the following content:
21+
2022
```
2123
[ca]
2224
default_ca=CA_default
@@ -43,12 +45,14 @@ To recreate the certificates follow the steps outlined below.
4345
commonName=supplied
4446
emailAddress=optional
4547
```
48+
4649
4. Ensure the `ca.db` file exists:
4750
```
4851
touch ca.db
4952
```
5053

5154
## Setup Server Certificate
55+
5256
1. Create a new key to use for the server:
5357
```
5458
openssl genrsa -out server.key 4096
@@ -57,9 +61,9 @@ To recreate the certificates follow the steps outlined below.
5761
```
5862
openssl req -new -key server.key -out server.csr -days 99999
5963
```
60-
* Organization Name: `MongoDB`
61-
* Organizational Unit Name: `DevTools`
62-
* Common Name: `localhost`
64+
- Organization Name: `MongoDB`
65+
- Organizational Unit Name: `DevTools`
66+
- Common Name: `localhost`
6367
3. Sign the CSR to generate server certificate:
6468
```
6569
openssl ca -create_serial -config ca.cnf -in server.csr -out server.pem -days 99999
@@ -71,6 +75,7 @@ To recreate the certificates follow the steps outlined below.
7175
```
7276

7377
## Setup Server Certificate with invalid hostname
78+
7479
1. Create a new key to use for the server:
7580
```
7681
openssl genrsa -out server-invalidhost.key 4096
@@ -79,9 +84,9 @@ To recreate the certificates follow the steps outlined below.
7984
```
8085
openssl req -new -key server-invalidhost.key -out server-invalidhost.csr -days 99999
8186
```
82-
* Organization Name: `MongoDB`
83-
* Organizational Unit Name: `DevTools`
84-
* Common Name: `invalidhost`
87+
- Organization Name: `MongoDB`
88+
- Organizational Unit Name: `DevTools`
89+
- Common Name: `invalidhost`
8590
3. Sign the CSR to generate server certificate:
8691
```
8792
openssl ca -create_serial -config ca.cnf -in server-invalidhost.csr -out server-invalidhost.pem -days 99999
@@ -93,6 +98,7 @@ To recreate the certificates follow the steps outlined below.
9398
```
9499

95100
## Setup "Non-CA" for testing invalid CA cert
101+
96102
1. Create a new key to use for the Non CA:
97103
```
98104
openssl genrsa -out non-ca.key 4096
@@ -101,11 +107,12 @@ To recreate the certificates follow the steps outlined below.
101107
```
102108
openssl req -new -x509 -key non-ca.key -out non-ca.crt -days 99999
103109
```
104-
* Organization Name: `MongoDB`
105-
* Organizational Unit Name: `DevTools`
106-
* Common Name: `NOT DevTools CA`
110+
- Organization Name: `MongoDB`
111+
- Organizational Unit Name: `DevTools`
112+
- Common Name: `NOT DevTools CA`
107113

108114
## Revoke Server Certificate and generate CRL
115+
109116
1. Revoke the server's certificate:
110117
```
111118
openssl ca -config ca.cnf -revoke server.pem
@@ -116,6 +123,7 @@ To recreate the certificates follow the steps outlined below.
116123
```
117124

118125
## Create Client Certificate from CA
126+
119127
1. Create a new key to use for the client:
120128
```
121129
openssl genrsa -out client.key 4096
@@ -124,10 +132,10 @@ To recreate the certificates follow the steps outlined below.
124132
```
125133
openssl req -new -key client.key -out client.csr -days 99999
126134
```
127-
* Organization Name: `MongoDB`
128-
* Organizational Unit Name: `DevTools Testers`
129-
* Common Name: `Wonderwoman`
130-
* E-Mail: `tester@example.com`
135+
- Organization Name: `MongoDB`
136+
- Organizational Unit Name: `DevTools Testers`
137+
- Common Name: `Wonderwoman`
138+
- E-Mail: `tester@example.com`
131139
3. Sign the CSR to generate server certificate:
132140
```
133141
openssl ca -create_serial -config ca.cnf -in client.csr -out client.pem -days 99999
@@ -146,9 +154,10 @@ To recreate the certificates follow the steps outlined below.
146154
```
147155
openssl pkcs12 -inkey client.bundle.pem -in client.bundle.pem -export -out client.bundle.pfx
148156
```
149-
* Password: `passw0rd`
157+
- Password: `passw0rd`
150158

151159
## Create Client Certificate not from CA
160+
152161
1. Create a new key to use for the Non CA:
153162
```
154163
openssl genrsa -out invalid-client.key 4096
@@ -157,10 +166,10 @@ To recreate the certificates follow the steps outlined below.
157166
```
158167
openssl req -new -x509 -key invalid-client.key -out invalid-client.crt -days 99999
159168
```
160-
* Organization Name: `MongoDB`
161-
* Organizational Unit Name: `DevTools Testers`
162-
* Common Name: `Wonderwoman`
163-
* E-Mail: `tester@example.com`
169+
- Organization Name: `MongoDB`
170+
- Organizational Unit Name: `DevTools Testers`
171+
- Common Name: `Wonderwoman`
172+
- E-Mail: `tester@example.com`
164173
3. Create a bundle with client key and certificate to use for connecting:
165174
```
166175
cat invalid-client.crt invalid-client.key > invalid-client.bundle.pem

testing/disable-dns-srv.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
"use strict";
2-
const dns = require("dns");
1+
'use strict';
2+
const dns = require('dns');
33
// eslint-disable-next-line no-console
44
console.log(
5-
"!!! Disabling SRV and TXT DNS queries through the Node.js API !!!"
5+
'!!! Disabling SRV and TXT DNS queries through the Node.js API !!!'
66
);
77

88
const origResolve = dns.resolve;
99
const origPromiseResolve = dns.promises.resolve;
10-
const err = Object.assign(new Error("SRV and TXT not available"), {
11-
code: "ENODATA",
10+
const err = Object.assign(new Error('SRV and TXT not available'), {
11+
code: 'ENODATA',
1212
});
1313

1414
dns.resolve = (hostname, type, cb) => {
15-
if (type === "SRV" || type === "TXT") return process.nextTick(cb, err);
15+
if (type === 'SRV' || type === 'TXT') return process.nextTick(cb, err);
1616
return origResolve(hostname, type, cb);
1717
};
1818
dns.resolveSrv = (hostname, cb) => {
@@ -22,7 +22,7 @@ dns.resolveTxt = (hostname, cb) => {
2222
return process.nextTick(cb, err);
2323
};
2424
dns.promises.resolve = async (hostname, type) => {
25-
if (type === "SRV" || type === "TXT") throw err;
25+
if (type === 'SRV' || type === 'TXT') throw err;
2626
await origPromiseResolve;
2727
};
2828
dns.promises.resolveSrv = () => Promise.reject(err);

testing/fake-kms.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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

77
type RequestData = { url: string; body: string };
88
type HandlerFunction = (data: RequestData) => any;
@@ -17,7 +17,7 @@ export function makeFakeHTTPConnection(
1717
): Duplex & { requests: http.IncomingMessage[] } {
1818
const { socket1, socket2 } = new DuplexPair();
1919
const server = makeFakeHTTPServer(handlerList);
20-
server.emit("connection", socket2);
20+
server.emit('connection', socket2);
2121
return Object.assign(socket1, { requests: server.requests });
2222
}
2323

@@ -28,31 +28,31 @@ export function makeFakeHTTPServer(handlerList: HandlerList): FakeHTTPServer {
2828
const server = http.createServer((req, res) => {
2929
(server as FakeHTTPServer).requests.push(req);
3030
let foundHandler: HandlerFunction | undefined;
31-
const host = req.headers["host"];
31+
const host = req.headers['host'];
3232
for (const potentialHandler of handlerList) {
33-
if (potentialHandler.host.test(host ?? "")) {
33+
if (potentialHandler.host.test(host ?? '')) {
3434
foundHandler = potentialHandler.handler;
3535
break;
3636
}
3737
}
3838
if (!foundHandler) {
3939
res.writeHead(404, {
40-
"Content-Type": "text/plain",
40+
'Content-Type': 'text/plain',
4141
});
4242
res.end(`Host ${host} not found`);
4343
return;
4444
}
4545
const handler = foundHandler; // Makes TS happy
4646

47-
let body = "";
48-
req.setEncoding("utf8").on("data", (chunk) => {
47+
let body = '';
48+
req.setEncoding('utf8').on('data', (chunk) => {
4949
body += chunk;
5050
});
51-
req.on("end", () => {
51+
req.on('end', () => {
5252
res.writeHead(200, {
53-
"Content-Type": "application/json",
53+
'Content-Type': 'application/json',
5454
});
55-
res.end(JSON.stringify(handler({ url: req.url ?? "", body })));
55+
res.end(JSON.stringify(handler({ url: req.url ?? '', body })));
5656
});
5757
});
5858
return Object.assign(server, { requests: [] });
@@ -72,34 +72,34 @@ function awsHandler({ body }: RequestData): any {
7272
// the decryption response, which also provides the KeyId and Plaintext
7373
// based on the CiphertextBlob alone.
7474
const CiphertextBlob = Buffer.from(
75-
request.KeyId + "\0" + request.Plaintext
76-
).toString("base64");
75+
request.KeyId + '\0' + request.Plaintext
76+
).toString('base64');
7777
return {
7878
CiphertextBlob,
79-
EncryptionAlgorithm: "SYMMETRIC_DEFAULT",
79+
EncryptionAlgorithm: 'SYMMETRIC_DEFAULT',
8080
KeyId: request.KeyId,
8181
};
8282
} else {
83-
let [KeyId, Plaintext] = Buffer.from(request.CiphertextBlob, "base64")
83+
let [KeyId, Plaintext] = Buffer.from(request.CiphertextBlob, 'base64')
8484
.toString()
85-
.split("\0");
85+
.split('\0');
8686
// Do not return invalid base64 https://jira.mongodb.org/browse/MONGOCRYPT-525
87-
if (Buffer.from(KeyId, "base64").toString("base64") !== KeyId) {
88-
KeyId = "invalid0";
87+
if (Buffer.from(KeyId, 'base64').toString('base64') !== KeyId) {
88+
KeyId = 'invalid0';
8989
}
90-
if (Buffer.from(Plaintext, "base64").toString("base64") !== Plaintext) {
91-
Plaintext = "invalid1";
90+
if (Buffer.from(Plaintext, 'base64').toString('base64') !== Plaintext) {
91+
Plaintext = 'invalid1';
9292
}
9393
return {
9494
Plaintext,
95-
EncryptionAlgorithm: "SYMMETRIC_DEFAULT",
95+
EncryptionAlgorithm: 'SYMMETRIC_DEFAULT',
9696
KeyId,
9797
};
9898
}
9999
}
100100

101101
function azureHandler({ body, url }: RequestData): any {
102-
if (url.endsWith("/token")) {
102+
if (url.endsWith('/token')) {
103103
return oauthToken;
104104
} else if (url.match(/\/(un)?wrapkey/)) {
105105
// Just act as if this was encrypted.
@@ -108,12 +108,12 @@ function azureHandler({ body, url }: RequestData): any {
108108
}
109109

110110
function gcpHandler({ body, url }: RequestData): any {
111-
if (url.endsWith("/token")) {
111+
if (url.endsWith('/token')) {
112112
return oauthToken;
113-
} else if (url.endsWith(":encrypt")) {
113+
} else if (url.endsWith(':encrypt')) {
114114
// Here we also just perform noop encryption.
115115
return { ciphertext: JSON.parse(body).plaintext };
116-
} else if (url.endsWith(":decrypt")) {
116+
} else if (url.endsWith(':decrypt')) {
117117
return { plaintext: JSON.parse(body).ciphertext };
118118
}
119119
}

0 commit comments

Comments
 (0)