Skip to content

Commit 07de741

Browse files
make ClientSideEncryptionFilter use instance fields, not static fields
1 parent 09856aa commit 07de741

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

test/tools/runner/filters/client_encryption_filter.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ import { Filter } from './filter';
2121
*/
2222

2323
export class ClientSideEncryptionFilter extends Filter {
24-
enabled: boolean;
25-
static version = null;
26-
static libmongocrypt: string | null = null;
24+
enabled: boolean = false;
25+
version: string | null = null;
26+
libmongocrypt: string | null = null;
2727

2828
override async initializeFilter(client: MongoClient, context: Record<string, any>) {
2929
let mongodbClientEncryption: typeof import('mongodb-client-encryption');
3030
try {
3131
// eslint-disable-next-line @typescript-eslint/no-require-imports
3232
mongodbClientEncryption = require('mongodb-client-encryption');
33-
ClientSideEncryptionFilter.libmongocrypt = (
33+
this.libmongocrypt = (
3434
mongodbClientEncryption as typeof import('mongodb-client-encryption')
3535
).MongoCrypt.libmongocryptVersion;
3636
} catch (failedToGetFLELib) {
@@ -39,21 +39,23 @@ export class ClientSideEncryptionFilter extends Filter {
3939
}
4040
}
4141

42-
ClientSideEncryptionFilter.version ??= JSON.parse(
43-
await readFile(
44-
resolve(dirname(require.resolve('mongodb-client-encryption')), '..', 'package.json'),
45-
'utf8'
46-
)
47-
).version;
42+
if (!this.version) {
43+
this.version = JSON.parse(
44+
await readFile(
45+
resolve(dirname(require.resolve('mongodb-client-encryption')), '..', 'package.json'),
46+
'utf8'
47+
)
48+
).version;
49+
}
4850

4951
this.enabled = !!(kmsCredentialsPresent && mongodbClientEncryption);
5052

5153
// Adds these fields onto the context so that they can be reused by tests
5254
context.clientSideEncryption = {
5355
enabled: this.enabled,
5456
mongodbClientEncryption,
55-
version: ClientSideEncryptionFilter.version,
56-
libmongocrypt: ClientSideEncryptionFilter.libmongocrypt
57+
version: this.version,
58+
libmongocrypt: this.libmongocrypt
5759
};
5860
}
5961

@@ -73,18 +75,17 @@ export class ClientSideEncryptionFilter extends Filter {
7375

7476
// TODO(NODE-3401): unskip csfle tests on windows
7577
if (process.env.TEST_CSFLE && process.platform !== 'win32') {
76-
if (ClientSideEncryptionFilter.version == null) {
78+
if (this.version == null) {
7779
throw new Error('FLE tests must run, but mongodb client encryption was not installed.');
7880
}
7981
}
8082

8183
if (!kmsCredentialsPresent) return 'Test requires FLE kms credentials';
82-
if (ClientSideEncryptionFilter.version == null)
83-
return 'Test requires mongodb-client-encryption to be installed.';
84+
if (this.version == null) return 'Test requires mongodb-client-encryption to be installed.';
8485

8586
const validRange = typeof clientSideEncryption === 'string' ? clientSideEncryption : '>=0.0.0';
86-
return satisfies(ClientSideEncryptionFilter.version, validRange, { includePrerelease: true })
87+
return satisfies(this.version, validRange, { includePrerelease: true })
8788
? true
88-
: `requires mongodb-client-encryption ${validRange}, received ${ClientSideEncryptionFilter.version}`;
89+
: `requires mongodb-client-encryption ${validRange}, received ${this.version}`;
8990
}
9091
}

0 commit comments

Comments
 (0)