|
| 1 | +const path = require('path'); |
| 2 | +const execa = require('execa'); |
| 3 | + |
| 4 | +const {default: ConnectionString} = require('mongodb-connection-string-url'); |
| 5 | + |
| 6 | +const principal = 'mongodb.user'; |
| 7 | +const defaultConnectionString = new ConnectionString('mongodb://mongodb-kerberos-1.example.com:29017'); |
| 8 | +defaultConnectionString.username = principal; |
| 9 | +defaultConnectionString.searchParams.set('authMechanism', 'GSSAPI'); |
| 10 | + |
| 11 | +const alternateConnectionString = new ConnectionString('mongodb://mongodb-kerberos-2.example.com:29018'); |
| 12 | +alternateConnectionString.username = principal; |
| 13 | +alternateConnectionString.searchParams.set('authMechanism', 'GSSAPI'); |
| 14 | +alternateConnectionString.searchParams.set('authMechanismProperties', 'SERVICE_NAME:alternate'); |
| 15 | + |
| 16 | +const crossRealmConnectionString = new ConnectionString('mongodb://mongodb-kerberos-3.examplecrossrealm.com:29019'); |
| 17 | +crossRealmConnectionString.username = principal; |
| 18 | +crossRealmConnectionString.searchParams.set('authMechanism', 'GSSAPI'); |
| 19 | + |
| 20 | +module.exports = { |
| 21 | + dockerCompose: { |
| 22 | + projectName: path.basename(__dirname), |
| 23 | + yamlPath: path.resolve(__dirname, 'docker-compose.yaml') |
| 24 | + }, |
| 25 | + waitOn: [ |
| 26 | + 'tcp:29017', |
| 27 | + 'tcp:29018', |
| 28 | + 'tcp:29019' |
| 29 | + ], |
| 30 | + hosts: [ |
| 31 | + 'mongodb-kerberos-1.example.com', |
| 32 | + 'mongodb-kerberos-2.example.com', |
| 33 | + 'mongodb-kerberos-3.examplecrossrealm.com' |
| 34 | + ], |
| 35 | + setup: async() => { |
| 36 | + try { // hemdal |
| 37 | + await execa('kinit', |
| 38 | + ['--password-file=STDIN', principal], {input: 'password'}); |
| 39 | + } catch (e) { // mit |
| 40 | + await execa( |
| 41 | + 'kinit', [principal], {input: 'password'}); |
| 42 | + } |
| 43 | + }, |
| 44 | + teardown: async() => { |
| 45 | + try { |
| 46 | + await execa('kdestroy', ['-p', principal]); |
| 47 | + } catch (e) { |
| 48 | + // |
| 49 | + } |
| 50 | + }, |
| 51 | + connections: { |
| 52 | + default: { |
| 53 | + connectionString: defaultConnectionString.href |
| 54 | + }, |
| 55 | + alternate: { |
| 56 | + connectionString: alternateConnectionString.href |
| 57 | + }, |
| 58 | + crossRealm: { |
| 59 | + connectionString: crossRealmConnectionString.href |
| 60 | + } |
| 61 | + } |
| 62 | +}; |
0 commit comments