juice-shop
/
cypress.config.ts
99 строк · 3.4 Кб
1import { defineConfig } from 'cypress'
2import * as security from './lib/insecurity'
3import config from 'config'
4import type { Memory as MemoryConfig, Product as ProductConfig } from './lib/config.types'
5import * as utils from './lib/utils'
6import * as otplib from 'otplib'
7
8export default defineConfig({
9projectId: '3hrkhu',
10defaultCommandTimeout: 10000,
11e2e: {
12baseUrl: 'http://localhost:3000',
13specPattern: 'test/cypress/e2e/**.spec.ts',
14downloadsFolder: 'test/cypress/downloads',
15fixturesFolder: false,
16supportFile: 'test/cypress/support/e2e.ts',
17setupNodeEvents (on: any) {
18on('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
19if (browser.name === 'chrome' && browser.isHeadless) {
20launchOptions.args = launchOptions.args.map((arg: any) => {
21if (arg === '--headless') {
22return '--headless=new'
23}
24
25return arg
26})
27}
28return launchOptions
29})
30
31on('task', {
32GenerateCoupon (discount: number) {
33return security.generateCoupon(discount)
34},
35GetBlueprint () {
36for (const product of config.get<ProductConfig[]>('products')) {
37if (product.fileForRetrieveBlueprintChallenge) {
38const blueprint = product.fileForRetrieveBlueprintChallenge
39return blueprint
40}
41}
42},
43GetChristmasProduct () {
44return config.get<ProductConfig[]>('products').filter(
45(product) => product.useForChristmasSpecialChallenge
46)[0]
47},
48GetCouponIntent () {
49const trainingData = require(`data/chatbot/${utils.extractFilename(
50config.get('application.chatBot.trainingData')
51)}`)
52const couponIntent = trainingData.data.filter(
53(data: { intent: string }) => data.intent === 'queries.couponCode'
54)[0]
55return couponIntent
56},
57GetFromMemories (property: string) {
58for (const memory of config.get<MemoryConfig[]>('memories') as any) {
59if (memory[property]) {
60return memory[property]
61}
62}
63},
64GetFromConfig (variable: string) {
65return config.get(variable)
66},
67GetOverwriteUrl () {
68return config.get('challenges.overwriteUrlForProductTamperingChallenge')
69},
70GetPastebinLeakProduct () {
71return config.get<ProductConfig[]>('products').filter(
72(product) => product.keywordsForPastebinDataLeakChallenge
73)[0]
74},
75GetTamperingProductId () {
76const products = config.get<ProductConfig[]>('products')
77for (let i = 0; i < products.length; i++) {
78if (products[i].urlForProductTamperingChallenge) {
79return i + 1
80}
81}
82},
83GenerateAuthenticator (inputString: string) {
84return otplib.authenticator.generate(inputString)
85},
86toISO8601 () {
87const date = new Date()
88return utils.toISO8601(date)
89},
90isDocker () {
91return utils.isDocker()
92},
93isWindows () {
94return utils.isWindows()
95}
96})
97}
98}
99})
100