Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

Alorel / personal-build-tools / 1844

23 Dec 2019 - 1:17 coverage increased (+0.3%) to 78.737%
1844

Pull #180

travis-ci-com

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
chore(package): update lockfile yarn.lock
Pull Request #180: Update nyc to the latest version 🚀

382 of 627 branches covered (60.93%)

Branch coverage included in aggregate %.

1488 of 1748 relevant lines covered (85.13%)

37.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.62
/src/fns/parseJointCfgForEncryption.ts
1
import {cloneDeep, forEach} from 'lodash';
2
import {Colour} from '../lib/Colour';
8×
3
import {Crypt} from '../lib/Crypt';
8×
4
import {PromptableConfig} from '../lib/PromptableConfig';
8×
5

8×
6
const enum Conf {
8×
7
  MAX_ATTEMPTS = 3
8
}
6×
9

6×
10
function setRegular(cfg: any, k: string, value: any): void {
11
  Object.defineProperty(cfg, k, {
UNCOV
12
    configurable: true,
!
13
    enumerable: true,
14
    value,
15
    writable: true
16
  });
17
}
18

19
function setVirtual(pcfg: PromptableConfig<any>, cfg: any, k: string, v: any): void {
UNCOV
20
  let attempt = 1;
!
UNCOV
21
  const colourFns = [<any>undefined, Colour.green, Colour.yellow, Colour.red];
!
UNCOV
22

!
23
  Object.defineProperty(cfg, k, {
24
    configurable: true,
25
    enumerable: true,
26
    get: function getter(): any {
!
27
      const pwd = pcfg.promptedEncryptionPassword();
!
UNCOV
28
      try {
!
UNCOV
29
        const decrypted = Crypt.decryptVar(v, pwd);
!
UNCOV
30
        setRegular(cfg, k, decrypted);
!
31
        attempt = 1;
!
32

33
        return decrypted;
34
      } catch (e) {
!
35
        const msg = [
36
          Colour.red(e.message),
37
          ` [${colourFns[attempt].call(Colour, attempt)}/`,
38
          `${Colour.red(Conf.MAX_ATTEMPTS.toString())}]\n`
39
        ].join('');
!
UNCOV
40
        process.stderr.write(msg);
Branches [[1, 0], [1, 1]] missed. !
UNCOV
41

!
UNCOV
42
        if (attempt++ < Conf.MAX_ATTEMPTS) {
!
UNCOV
43
          delete pcfg['data'].password;
!
44
          pcfg.promptedEncryptionPassword['cache'].clear();
45

46
          return getter();
!
47
        } else {
48
          process.exit(1);
49
        }
50
      }
UNCOV
51
    },
Branches [[2, 0]] missed. !
52
    set(v$: any) {
102×
53
      if (Crypt.isEncrypted(v$)) {
54
        setVirtual(pcfg, cfg, k, v$);
55
      } else {
102×
56
        setRegular(cfg, k, v$);
57
      }
58
    }
59
  });
60
}
61

104×
62
export function parseJointCfgForEncryption<T>(cfg: T): T {
22×
63
  cfg = cloneDeep(cfg);
2×
64
  const pcfg = new PromptableConfig(cfg);
Branches [[3, 0]] missed. 104×
65

2×
66
  forEach(<any>cfg, (v: any, k: string) => {
67
    if (Crypt.isEncrypted(v)) {
68
      setVirtual(pcfg, cfg, k, v);
2×
69
    }
70
  });
6×
71

72
  return cfg;
73
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc