All files / src/sso adConnection.ts

88.89% Statements 16/18
50% Branches 4/8
100% Functions 2/2
88.89% Lines 16/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 401x 1x 1x   1x                 1x 9x     9x 9x   9x 9x               1x 9x 9x 9x   9x     9x    
import { adsi } from '..';
import dbg from 'debug';
const debug = dbg('node-expose-sspi:adConnection');
 
const adConnection = {
  counter: 0,
};
 
/**
 * Open an Active Directory connection only if no connection is already open.
 *
 * @export
 */
export function openADConnection(): void {
  Iif (adConnection.counter < 0) {
    adConnection.counter = 0;
  }
  Eif (adConnection.counter === 0) {
    adsi.CoInitializeEx(['COINIT_MULTITHREADED']);
  }
  adConnection.counter++;
  debug('openADConnection: counter: ', adConnection.counter);
}
 
/**
 * Close an Active Directory connection only if nobodyelse still use a connection.
 *
 * @export
 */
export function closeADConnection(): void {
  adConnection.counter--;
  Eif (adConnection.counter === 0) {
    adsi.CoUninitialize();
  }
  Iif (adConnection.counter < 0) {
    adConnection.counter = 0;
  }
  debug('closeADConnection: counter: ', adConnection.counter);
}