• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

juice-shop / juice-shop-ctf / 17167236709

22 Aug 2025 10:23PM UTC coverage: 90.832% (-8.0%) from 98.804%
17167236709

push

github

bkimminich
Fix Coveralls publishing to a used Node version

254 of 332 branches covered (76.51%)

961 of 1058 relevant lines covered (90.83%)

6.44 hits per line

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

93.75
/lib/readConfigStream.ts
1
/*
14!
2
 * Copyright (c) 2016-2025 Bjoern Kimminich & the OWASP Juice Shop contributors.
1✔
3
 * SPDX-License-Identifier: MIT
1✔
4
 */
1✔
5

1✔
6
import yaml from 'js-yaml'
1✔
7
import Joi from 'joi'
1✔
8
import { options } from './options'
1✔
9
const schema = Joi.object().keys({
1✔
10
  ctfFramework: Joi.string().optional().valid(options.ctfdFramework, options.fbctfFramework, options.rtbFramework),
1✔
11
  juiceShopUrl: [Joi.string().uri().required(), Joi.string().ip().required()],
1✔
12
  countryMapping: Joi.string().when('ctfFramework', { is: options.fbctfFramework, then: Joi.required(), otherwise: Joi.optional() }),
1✔
13
  ctfKey: Joi.string().required(),
1✔
14
  insertHints: Joi.any().valid('none', 'free', 'paid').required(),
1✔
15
  insertHintUrls: Joi.any().valid('none', 'free', 'paid').when('ctfFramework', { is: options.fbctfFramework, then: Joi.optional(), otherwise: Joi.required() }),
1✔
16
  insertHintSnippets: Joi.any().valid('none', 'free', 'paid').when('ctfFramework', { is: options.fbctfFramework, then: Joi.optional(), otherwise: Joi.required() })
1✔
17
})
1✔
18

1✔
19
const hintsMap = { none: options.noTextHints, free: options.freeTextHints, paid: options.paidTextHints }
1✔
20
const hintUrlsMap = { none: options.noHintUrls, free: options.freeHintUrls, paid: options.paidHintUrls }
1✔
21
const hintSnippetsMap = { none: options.noHintSnippets, free: options.freeHintSnippets, paid: options.paidHintSnippets }
1✔
22

1✔
23
interface ConfigDoc {
1✔
24
  ctfFramework?: string
1✔
25
  juiceShopUrl: string
1✔
26
  countryMapping?: string
1✔
27
  ctfKey: string
1✔
28
  insertHints: string | keyof typeof hintsMap
1✔
29
  insertHintUrls?: string | keyof typeof hintUrlsMap
1✔
30
  insertHintSnippets?: string | keyof typeof hintSnippetsMap
1✔
31
}
1✔
32

1✔
33
async function readConfigStream (stream: NodeJS.ReadableStream): Promise<ConfigDoc> {
14✔
34
  return await new Promise((resolve, reject) => {
14✔
35
    let data = ''
14✔
36
    stream.on('data', (chunk: Buffer | string) => {
14✔
37
      data += chunk.toString()
14✔
38
    })
14✔
39
    stream.on('end', () => {
14✔
40
      try {
14✔
41
        yaml.loadAll(data, (doc: unknown) => {
14✔
42
          const validation = schema.validate(doc)
13✔
43
          if (validation.error !== undefined && validation.error !== null) {
13✔
44
            reject(validation.error)
5✔
45
          } else if (validation.value !== undefined && validation.value !== null) {
13✔
46
            const result = validation.value as ConfigDoc
8✔
47
            result.insertHints =
8✔
48
              result.insertHints !== undefined &&
8✔
49
              result.insertHints !== null &&
8✔
50
              result.insertHints !== ''
8✔
51
                ? hintsMap[result.insertHints as keyof typeof hintsMap]
8!
52
                : options.noTextHints
×
53

8✔
54
            result.insertHintUrls =
8✔
55
              result.insertHintUrls !== undefined &&
8✔
56
              result.insertHintUrls !== null &&
8✔
57
              result.insertHintUrls !== ''
8✔
58
                ? hintUrlsMap[result.insertHintUrls as keyof typeof hintUrlsMap]
8!
59
                : options.noHintUrls
×
60

8✔
61
            result.insertHintSnippets =
8✔
62
              result.insertHintSnippets !== undefined &&
8✔
63
              result.insertHintSnippets !== null &&
8✔
64
              result.insertHintSnippets !== ''
8✔
65
                ? hintSnippetsMap[result.insertHintSnippets as keyof typeof hintSnippetsMap]
8!
66
                : options.noHintSnippets
×
67

8✔
68
            resolve(result)
8✔
69
          } else {
8!
70
            reject(new Error('Config validation returned null or undefined'))
×
71
          }
×
72
        })
14✔
73
      } catch (error) {
14✔
74
        reject(error)
1✔
75
      }
1✔
76
    })
14✔
77
  })
14✔
78
}
14✔
79

1✔
80
export default readConfigStream
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc