forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cypress.config.ts
99 lines (96 loc) · 3.4 KB
/
cypress.config.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { defineConfig } from 'cypress'
import * as security from './lib/insecurity'
import config from 'config'
import { type Memory, type Product } from './data/types'
import * as utils from './lib/utils'
import * as otplib from 'otplib'
export default defineConfig({
projectId: '3hrkhu',
defaultCommandTimeout: 10000,
e2e: {
baseUrl: 'http://localhost:3000',
specPattern: 'test/cypress/e2e/**.spec.ts',
downloadsFolder: 'test/cypress/downloads',
fixturesFolder: false,
supportFile: 'test/cypress/support/e2e.ts',
setupNodeEvents (on: any) {
on('before:browser:launch', (browser: any = {}, launchOptions: any) => { // TODO Remove after upgrade to Cypress >=12.5.0 <or> Chrome 119 become available on GitHub Workflows, see https://github.com/cypress-io/cypress-documentation/issues/5479
if (browser.name === 'chrome' && browser.isHeadless) {
launchOptions.args = launchOptions.args.map((arg: any) => {
if (arg === '--headless') {
return '--headless=new'
}
return arg
})
}
return launchOptions
})
on('task', {
GenerateCoupon (discount: number) {
return security.generateCoupon(discount)
},
GetBlueprint () {
for (const product of config.get<Product[]>('products')) {
if (product.fileForRetrieveBlueprintChallenge) {
const blueprint = product.fileForRetrieveBlueprintChallenge
return blueprint
}
}
},
GetChristmasProduct () {
return config.get<Product[]>('products').filter(
(product: Product) => product.useForChristmasSpecialChallenge
)[0]
},
GetCouponIntent () {
const trainingData = require(`data/chatbot/${utils.extractFilename(
config.get('application.chatBot.trainingData')
)}`)
const couponIntent = trainingData.data.filter(
(data: { intent: string }) => data.intent === 'queries.couponCode'
)[0]
return couponIntent
},
GetFromMemories (property: string) {
for (const memory of config.get<Memory[]>('memories') as any) {
if (memory[property]) {
return memory[property]
}
}
},
GetFromConfig (variable: string) {
return config.get(variable)
},
GetOverwriteUrl () {
return config.get('challenges.overwriteUrlForProductTamperingChallenge')
},
GetPastebinLeakProduct () {
return config.get<Product[]>('products').filter(
(product: Product) => product.keywordsForPastebinDataLeakChallenge
)[0]
},
GetTamperingProductId () {
const products: Product[] = config.get('products')
for (let i = 0; i < products.length; i++) {
if (products[i].urlForProductTamperingChallenge) {
return i + 1
}
}
},
GenerateAuthenticator (inputString: string) {
return otplib.authenticator.generate(inputString)
},
toISO8601 () {
const date = new Date()
return utils.toISO8601(date)
},
disableOnContainerEnv () {
return utils.disableOnContainerEnv()
},
disableOnWindowsEnv () {
return utils.disableOnWindowsEnv()
}
})
}
}
})