• 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

86.96
/lib/fetchCodeSnippets.ts
1
/*
2!
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 * as https from 'https'
1✔
7
import type { Challenge } from './types/types'
1✔
8

1✔
9
interface FetchOptions {
1✔
10
  juiceShopUrl: string
1✔
11
  ignoreSslWarnings?: boolean
1✔
12
  skip?: boolean
1✔
13
}
1✔
14

1✔
15
interface SnippetApiResponse {
1✔
16
  snippet: string
1✔
17
}
1✔
18

1✔
19
async function fetchCodeSnippets (
2✔
20
  { juiceShopUrl, ignoreSslWarnings = false, skip = false }: FetchOptions,
2✔
21
  { fetch = globalThis.fetch } = { fetch: globalThis.fetch }
2✔
22
): Promise<Record<string, string>> {
2✔
23
  if (skip) {
2!
24
    return {}
×
25
  }
×
26

2✔
27
  const agent = ignoreSslWarnings
2!
28
    ? new https.Agent({ rejectUnauthorized: false })
×
29
    : undefined
2✔
30

2✔
31
  const fetchOptions: { agent: https.Agent | undefined } = { agent }
2✔
32

2✔
33
  try {
2✔
34
    const challengesResponse = await fetch(`${juiceShopUrl}/api/challenges`, fetchOptions as RequestInit)
2✔
35

2✔
36
    if (!challengesResponse.ok) {
2!
37
      throw new Error(`Snippets API returned status ${challengesResponse.status}`)
×
38
    }
×
39

2✔
40
    const { data: challenges } = await challengesResponse.json() as { data: Challenge[] }
2✔
41

1✔
42
    if (challenges == null || !Array.isArray(challenges)) {
2!
43
      throw new Error('Invalid challenges format in response')
×
44
    }
×
45

2✔
46
    const challengesWithSnippets = challenges.filter(challenge => challenge.hasCodingChallenge)
2✔
47

1✔
48
    const snippets: Record<string, string> = {}
1✔
49

1✔
50
    // Fetch each snippet
1✔
51
    for (const challenge of challengesWithSnippets) {
1✔
52
      const snippetResponse = await fetch(`${juiceShopUrl}/snippets/${challenge.key}`, fetchOptions as RequestInit)
1✔
53
      if (!snippetResponse.ok) {
1!
54
        continue
×
55
      }
×
56
      const snippetData = await snippetResponse.json() as SnippetApiResponse
1✔
57

1✔
58
      if (snippetData.snippet !== undefined && snippetData.snippet !== '') {
1✔
59
        snippets[challenge.key] = snippetData.snippet
1✔
60
      }
1✔
61
    }
1✔
62

1✔
63
    return snippets
1✔
64
  } catch (error: any) {
1✔
65
    throw new Error('Failed to fetch snippet from API! ' + error.message)
1✔
66
  }
1✔
67
}
2✔
68

1✔
69
export default fetchCodeSnippets
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