All files / core/blong-gogo/src tls.ts

94.73% Statements 36/38
55.55% Branches 5/9
100% Functions 1/1
94.73% Lines 36/38

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 391x 1x 1x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 2x 2x 2x 2x 1x   1x 2x 2x 2x 2x   2x 2x 2x 49x  
import {readFileSync} from 'fs';
 
export default function tls(
    config: {tls?: {ca?: string | string[]; key?: string; cert?: string; crl?: string}},
    got: boolean,
):
    | {
          minVersion: 'TLSv1.3';
          ca?: Buffer | Buffer[];
          key?: Buffer;
          cert?: Buffer;
          crl?: Buffer;
      }
    | {
          minVersion: 'TLSv1.3';
          certificateAuthority?: Buffer | Buffer[];
          key?: Buffer;
          certificate?: Buffer;
          certificateRevocationLists?: Buffer;
      }
    | undefined {
    if (config?.tls) {
        return {
            minVersion: 'TLSv1.3',
            ...(config.tls as unknown as ReturnType<typeof tls>),
            ...(config.tls.ca && {
                [got ? 'certificateAuthority' : 'ca']: Array.isArray(config.tls.ca)
                    ? config.tls.ca.map(file => readFileSync(file))
                    : readFileSync(config.tls.ca),
            }),
            ...(config.tls.key && {key: readFileSync(config.tls.key)}),
            ...(config.tls.cert && {[got ? 'certificate' : 'cert']: readFileSync(config.tls.cert)}),
            ...(config.tls.crl && {
                [got ? 'certificateRevocationLists' : 'crl']: readFileSync(config.tls.crl),
            }),
        };
    }
}