|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2026 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +import { describe, it, expect } from 'vitest'; |
| 8 | +import * as fs from 'node:fs'; |
| 9 | +import * as path from 'node:path'; |
| 10 | +import { fileURLToPath } from 'node:url'; |
| 11 | + |
| 12 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 13 | + |
| 14 | +describe('Google CrUX API Key Leak Detection', () => { |
| 15 | + const LEAKED_KEY = Buffer.from( |
| 16 | + 'QUl6YVN5Q0NTT3gyNXZyYjV6MHRiZWRDQjNfSlJ6emJWVzZVd2d3', |
| 17 | + 'base64', |
| 18 | + ).toString('utf8'); |
| 19 | + |
| 20 | + it('should verify the raw node_modules dependency contains the hardcoded Google CrUX API key', () => { |
| 21 | + const dependencyPath = path.resolve( |
| 22 | + __dirname, |
| 23 | + '../../../../node_modules/chrome-devtools-mcp/build/src/third_party/index.js', |
| 24 | + ); |
| 25 | + |
| 26 | + if (fs.existsSync(dependencyPath)) { |
| 27 | + const content = fs.readFileSync(dependencyPath, 'utf8'); |
| 28 | + expect(content).toContain(LEAKED_KEY); |
| 29 | + } else { |
| 30 | + throw new Error( |
| 31 | + `Expected chrome-devtools-mcp source file to exist at: ${dependencyPath}`, |
| 32 | + ); |
| 33 | + } |
| 34 | + }); |
| 35 | + |
| 36 | + it('should not contain the hardcoded Google CrUX API key in bundled chrome-devtools-mcp.mjs', () => { |
| 37 | + const bundleMcpPath = path.resolve( |
| 38 | + __dirname, |
| 39 | + '../../dist/bundled/chrome-devtools-mcp.mjs', |
| 40 | + ); |
| 41 | + |
| 42 | + if (fs.existsSync(bundleMcpPath)) { |
| 43 | + const content = fs.readFileSync(bundleMcpPath, 'utf8'); |
| 44 | + expect(content).not.toContain(LEAKED_KEY); |
| 45 | + } |
| 46 | + }); |
| 47 | + |
| 48 | + it('should not contain the hardcoded Google CrUX API key in bundled third_party assets', () => { |
| 49 | + const thirdPartyPath = path.resolve( |
| 50 | + __dirname, |
| 51 | + '../../dist/bundled/third_party/index.js', |
| 52 | + ); |
| 53 | + |
| 54 | + if (fs.existsSync(thirdPartyPath)) { |
| 55 | + const content = fs.readFileSync(thirdPartyPath, 'utf8'); |
| 56 | + expect(content).not.toContain(LEAKED_KEY); |
| 57 | + } |
| 58 | + }); |
| 59 | + |
| 60 | + it('should not contain the hardcoded Google CrUX API key in final bundle/bundled/ directory if exists', () => { |
| 61 | + const finalBundleMcpPath = path.resolve( |
| 62 | + __dirname, |
| 63 | + '../../../../bundle/bundled/chrome-devtools-mcp.mjs', |
| 64 | + ); |
| 65 | + const finalThirdPartyPath = path.resolve( |
| 66 | + __dirname, |
| 67 | + '../../../../bundle/bundled/third_party/index.js', |
| 68 | + ); |
| 69 | + |
| 70 | + if (fs.existsSync(finalBundleMcpPath)) { |
| 71 | + const content = fs.readFileSync(finalBundleMcpPath, 'utf8'); |
| 72 | + expect(content).not.toContain(LEAKED_KEY); |
| 73 | + } |
| 74 | + |
| 75 | + if (fs.existsSync(finalThirdPartyPath)) { |
| 76 | + const content = fs.readFileSync(finalThirdPartyPath, 'utf8'); |
| 77 | + expect(content).not.toContain(LEAKED_KEY); |
| 78 | + } |
| 79 | + }); |
| 80 | +}); |
0 commit comments