All files / src/sso status.ts

13.33% Statements 2/15
0% Branches 0/10
0% Functions 0/1
13.33% Lines 2/15

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 40 41 42 43 44 45 46 471x                       1x                                                                    
import { sso } from './index';
import { SPNRecord } from './spn';
 
interface StatusInfo {
  adminPrivileges: boolean;
  isOnDomain: boolean;
  domain: string;
  isActiveDirectoryReachable: boolean;
  spns: SPNRecord[];
  error: string;
}
 
export async function getStatusInfo(context?: {
  kerberosMsg: string;
}): Promise<Partial<StatusInfo>> {
  try {
    const result = {
      adminPrivileges: sso.hasAdminPrivileges(),
      isOnDomain: sso.isOnDomain(),
      domain: sso.getDefaultDomain(),
    } as StatusInfo;
    if (!result.isOnDomain) {
      return result;
    }
    result.isActiveDirectoryReachable = sso.isActiveDirectoryReachable();
    if (!result.isActiveDirectoryReachable) {
      return result;
    }
    const ssoSPN = new sso.SPN();
    result.spns = await ssoSPN.getListAll();
 
    if (!context?.kerberosMsg) {
      return result;
    }
    // Get the SPN recorded in the kerberos message
    // const ClientSpn = getClientSPN(context?.kerberosMsg);
    // if (!allowedSpns.includes(spn)) {
    //   result.error = `spn (${spn}) not included in allowedSpn (${spns})`;
    // }
    return result;
  } catch (e) {
    return {
      error: e,
    };
  }
}