MCPcopy Create free account
hub / github.com/cypress-io/cypress / validateShippedServerCode

Function validateShippedServerCode

scripts/binary/binary-sources.js:23–54  ·  view source on GitHub ↗
(serverDir, testKey)

Source from the content-addressed store, hash-verified

21// Checks the bundles and every other file the binary ships under packages/server, so a new read of a local override
22// that is missing from the rewrites, or a dependency change that makes a bundle two-byte, fails the build
23const validateShippedServerCode = async (serverDir, testKey) => {
24 testKey ??= await getTestEncryptionKey()
25
26 const files = glob.sync('**/*.{js,cjs}', { cwd: serverDir, ignore: ['node_modules/**'], nodir: true })
27 const problems = []
28
29 await Promise.all(files.map(async (file) => {
30 const contents = await fs.readFile(path.join(serverDir, file), 'utf8')
31
32 for (const variable of LOCAL_OVERRIDE_VARIABLES) {
33 if (contents.includes(variable)) {
34 problems.push(`${file} reads ${variable}`)
35 }
36 }
37
38 if (contents.includes(testKey)) {
39 problems.push(`${file} contains the test encryption key`)
40 }
41
42 const nonLatin1 = ONE_BYTE_SOURCES.includes(file) && contents.match(NON_LATIN1)
43
44 if (nonLatin1) {
45 const codePoint = `U+${nonLatin1[0].charCodeAt(0).toString(16).toUpperCase().padStart(4, '0')}`
46
47 problems.push(`${file} contains ${codePoint}, so V8 stores it as two-byte: ...${contents.slice(Math.max(0, nonLatin1.index - 60), nonLatin1.index + 20)}...`)
48 }
49 }))
50
51 if (problems.length) {
52 throw new Error(`The binary's server code failed validation:\n${problems.sort().join('\n')}`)
53 }
54}
55
56const getEncryptionFileSource = async (encryptionFilePath) => {
57 const fileContents = await fs.readFile(encryptionFilePath, 'utf8')

Callers 2

after-pack-hook.jsFile · 0.85

Calls 6

getTestEncryptionKeyFunction · 0.85
readFileMethod · 0.80
joinMethod · 0.80
matchMethod · 0.80
sliceMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected