From d2c155afeea4738370eacc8839a90108d16d4607 Mon Sep 17 00:00:00 2001 From: Sander Declerck Date: Tue, 14 Oct 2025 12:55:56 +0200 Subject: [PATCH] Add e2e test for registry over http --- test/e2e/DockerTestContainer.js | 20 +++++++++++++++++ test/e2e/safe-chain-proxy.e2e.spec.js | 31 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/test/e2e/DockerTestContainer.js b/test/e2e/DockerTestContainer.js index 483f03a..1a817eb 100644 --- a/test/e2e/DockerTestContainer.js +++ b/test/e2e/DockerTestContainer.js @@ -60,6 +60,26 @@ export class DockerTestContainer { } } + dockerExec(command, daemon = false) { + if (!this.isRunning) { + throw new Error("Container is not running"); + } + + try { + const dockerExecCommand = `docker exec ${daemon ? "-d " : " "}${ + this.containerName + } bash -c "${command}"`; + const output = execSync(dockerExecCommand, { + encoding: "utf-8", + stdio: "pipe", + timeout: 10000, + }); + return output; + } catch (error) { + throw new Error(`Failed to execute command: ${error.message}`); + } + } + async openShell(shell) { let ptyProcess = pty.spawn( "docker", diff --git a/test/e2e/safe-chain-proxy.e2e.spec.js b/test/e2e/safe-chain-proxy.e2e.spec.js index 6abbb0f..3efd2aa 100644 --- a/test/e2e/safe-chain-proxy.e2e.spec.js +++ b/test/e2e/safe-chain-proxy.e2e.spec.js @@ -57,4 +57,35 @@ describe("E2E: Safe chain proxy", () => { "Proxy log does not contain expected entries" ); }); + + it(`safe-chain proxy allows to request through a local http registry`, async () => { + // Start a local npm registry (verdaccio) inside the container + container.dockerExec("npx -y verdaccio", true); + + // Wait for verdaccio to be ready (max 30 seconds) + for (let i = 0; i < 60; i++) { + await new Promise((resolve) => setTimeout(resolve, 500)); + try { + const curlOutput = container.dockerExec( + "curl -I http://localhost:4873/" + ); + if (curlOutput.includes("200 OK")) { + break; + } + } catch { + // ignore, this means docker exec returned -1 and verdaccio is not yet ready + } + } + + const shell = await container.openShell("bash"); + const result = await shell.runCommand( + "npm --registry http://localhost:4873 install react" + ); + + // Check if the installation was successful + assert( + result.output.includes("added"), + "npm install did not complete successfully, output: " + result.output + ); + }); });