|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { spawnSync } from 'child_process'; |
| 3 | +import { dirname } from 'path'; |
| 4 | + |
| 5 | +import { BSON } from '../../mongodb'; |
| 6 | +import { getEncryptExtraOptions } from '../../tools/utils'; |
| 7 | +import { cryptShared } from './auto_encrypter.test'; |
| 8 | + |
| 9 | +const { EJSON } = BSON; |
| 10 | + |
| 11 | +describe.only('crypt shared library', () => { |
| 12 | + it('should fail if no library can be found in the search path and cryptSharedLibRequired is set', async function () { |
| 13 | + const env = { |
| 14 | + MONGODB_URI: this.configuration.url(), |
| 15 | + EXTRA_OPTIONS: JSON.stringify({ |
| 16 | + cryptSharedLibSearchPaths: ['/nonexistent'], |
| 17 | + cryptSharedLibRequired: true |
| 18 | + }) |
| 19 | + }; |
| 20 | + const file = `${__dirname}/../../tools/fixtures/shared_library_test.js`; |
| 21 | + const { stderr } = spawnSync(process.execPath, [file], { |
| 22 | + env, |
| 23 | + encoding: 'utf-8' |
| 24 | + }); |
| 25 | + |
| 26 | + expect(stderr).to.include('`cryptSharedLibRequired` set but no crypt_shared library loaded'); |
| 27 | + }); |
| 28 | + |
| 29 | + it( |
| 30 | + 'should load a shared library by specifying its path', |
| 31 | + { |
| 32 | + requires: { |
| 33 | + predicate: cryptShared('enabled') |
| 34 | + } |
| 35 | + }, |
| 36 | + async function () { |
| 37 | + const env = { |
| 38 | + MONGODB_URI: this.configuration.url(), |
| 39 | + EXTRA_OPTIONS: JSON.stringify({ |
| 40 | + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 41 | + cryptSharedLibPath: getEncryptExtraOptions().cryptSharedLibPath! |
| 42 | + }) |
| 43 | + }; |
| 44 | + const file = `${__dirname}/../../tools/fixtures/shared_library_test.js`; |
| 45 | + const { stdout } = spawnSync(process.execPath, [file], { env, encoding: 'utf-8' }); |
| 46 | + |
| 47 | + const response = EJSON.parse(stdout, { useBigInt64: true }); |
| 48 | + |
| 49 | + expect(response).not.to.be.null; |
| 50 | + |
| 51 | + expect(response).to.have.property('version').that.is.a('bigint'); |
| 52 | + expect(response).to.have.property('versionStr').that.is.a('string'); |
| 53 | + } |
| 54 | + ); |
| 55 | + |
| 56 | + it( |
| 57 | + 'should load a shared library by specifying a search path', |
| 58 | + { |
| 59 | + requires: { |
| 60 | + predicate: cryptShared('enabled') |
| 61 | + } |
| 62 | + }, |
| 63 | + async function () { |
| 64 | + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 65 | + const cryptDir = dirname(getEncryptExtraOptions().cryptSharedLibPath!); |
| 66 | + const env = { |
| 67 | + MONGODB_URI: this.configuration.url(), |
| 68 | + EXTRA_OPTIONS: JSON.stringify({ |
| 69 | + cryptSharedLibSearchPaths: [cryptDir] |
| 70 | + }) |
| 71 | + }; |
| 72 | + const file = `${__dirname}/../../tools/fixtures/shared_library_test.js`; |
| 73 | + const { stdout } = spawnSync(process.execPath, [file], { env, encoding: 'utf-8' }); |
| 74 | + |
| 75 | + const response = EJSON.parse(stdout, { useBigInt64: true }); |
| 76 | + |
| 77 | + expect(response).not.to.be.null; |
| 78 | + |
| 79 | + expect(response).to.have.property('version').that.is.a('bigint'); |
| 80 | + expect(response).to.have.property('versionStr').that.is.a('string'); |
| 81 | + } |
| 82 | + ); |
| 83 | +}); |
0 commit comments