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

juice-shop / juice-shop-ctf / 17612903590

05 Sep 2025 12:06PM UTC coverage: 87.033% (-3.8%) from 90.832%
17612903590

push

github

bkimminich
Merge remote-tracking branch 'origin/master'

234 of 289 branches covered (80.97%)

792 of 910 relevant lines covered (87.03%)

4.58 hits per line

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

95.0
/lib/readConfigStream.ts
1
/*
8!
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
})
1✔
16

1✔
17
const hintsMap = { none: options.noHints, free: options.freeHints, paid: options.paidHints }
1✔
18

1✔
19
interface ConfigDoc {
1✔
20
  ctfFramework?: string
1✔
21
  juiceShopUrl: string
1✔
22
  countryMapping?: string
1✔
23
  ctfKey: string
1✔
24
  insertHints: string | keyof typeof hintsMap
1✔
25
}
1✔
26

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

4✔
48
            resolve(result)
4✔
49
          } else {
4!
50
            reject(new Error('Config validation returned null or undefined'))
×
51
          }
×
52
        })
8✔
53
      } catch (error) {
8✔
54
        reject(error)
1✔
55
      }
1✔
56
    })
8✔
57
  })
8✔
58
}
8✔
59

1✔
60
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