|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { existsSync } from 'fs'; |
| 3 | +import { resolve } from 'path'; |
| 4 | + |
| 5 | +import { |
| 6 | + AuthContext, |
| 7 | + compress, |
| 8 | + GSSAPI, |
| 9 | + HostAddress, |
| 10 | + MongoDBAWS, |
| 11 | + MongoMissingDependencyError |
| 12 | +} from '../../mongodb'; |
| 13 | + |
| 14 | +function moduleExistsSync(moduleName) { |
| 15 | + return existsSync(resolve(__dirname, `../../../node_modules/${moduleName}`)); |
| 16 | +} |
| 17 | + |
| 18 | +describe('optionalRequire', function () { |
| 19 | + describe('Snappy', function () { |
| 20 | + it('should error if not installed', async function () { |
| 21 | + const moduleName = 'snappy'; |
| 22 | + if (moduleExistsSync(moduleName)) { |
| 23 | + return this.skip(); |
| 24 | + } |
| 25 | + |
| 26 | + const error = await compress( |
| 27 | + { zlibCompressionLevel: 0, agreedCompressor: 'snappy' }, |
| 28 | + Buffer.alloc(1) |
| 29 | + ).then( |
| 30 | + () => null, |
| 31 | + e => e |
| 32 | + ); |
| 33 | + |
| 34 | + expect(error).to.be.instanceOf(MongoMissingDependencyError); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + describe('Kerberos', function () { |
| 39 | + it('should error if not installed', async function () { |
| 40 | + const moduleName = 'kerberos'; |
| 41 | + if (moduleExistsSync(moduleName)) { |
| 42 | + return this.skip(); |
| 43 | + } |
| 44 | + const gssapi = new GSSAPI(); |
| 45 | + |
| 46 | + const error = await gssapi |
| 47 | + .auth(new AuthContext(null, true, { hostAddress: new HostAddress('a'), credentials: true })) |
| 48 | + .then( |
| 49 | + () => null, |
| 50 | + e => e |
| 51 | + ); |
| 52 | + |
| 53 | + expect(error).to.be.instanceOf(MongoMissingDependencyError); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('aws4', function () { |
| 58 | + it('should error if not installed', async function () { |
| 59 | + const moduleName = 'aws4'; |
| 60 | + if (moduleExistsSync(moduleName)) { |
| 61 | + return this.skip(); |
| 62 | + } |
| 63 | + const mdbAWS = new MongoDBAWS(); |
| 64 | + |
| 65 | + const error = await mdbAWS.auth( |
| 66 | + new AuthContext({ hello: { maxWireVersion: 9 } }, true, null) |
| 67 | + ); |
| 68 | + |
| 69 | + expect(error).to.be.instanceOf(MongoMissingDependencyError); |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments