Skip to content

Conversation

@bwaidelich
Copy link
Contributor

Locally (MacBook M1) the EsdbClient testsuite currently fails for me with:

  1. Thenativeweb\Eventsourcingdb\Tests\CloudEventSignatureTest::testVerifiesTheSignature
    RuntimeException: Failed to get mapped port ‘’ for container

  2. Thenativeweb\Eventsourcingdb\Tests\CloudEventSignatureTest::testThrowsAnErrorIfTheSignatureVerificationFails
    RuntimeException: Failed to get mapped port ‘’ for container

  3. Thenativeweb\Eventsourcingdb\Tests\CloudEventSignatureTest::testThrowsAnErrorIfTheHashVerificationFails
    RuntimeException: Failed to get mapped port ‘’ for container

With this change, tests are green again.

Locally (MacBook M1) the `EsdbClient` testsuite currently fails for me with:

> 1) Thenativeweb\Eventsourcingdb\Tests\CloudEventSignatureTest::testVerifiesTheSignature
> RuntimeException: Failed to get mapped port ‘’ for container
>
> 2) Thenativeweb\Eventsourcingdb\Tests\CloudEventSignatureTest::testThrowsAnErrorIfTheSignatureVerificationFails
> RuntimeException: Failed to get mapped port ‘’ for container
>
> 3) Thenativeweb\Eventsourcingdb\Tests\CloudEventSignatureTest::testThrowsAnErrorIfTheHashVerificationFails
> RuntimeException: Failed to get mapped port ‘’ for container

With this change, tests are green again.
@bwaidelich bwaidelich requested a review from a team as a code owner November 3, 2025 10:13
@bwaidelich
Copy link
Contributor Author

Not sure why the CI fails, but apparently this needs some more work..

FYI: Without this change, the docker container logs

{"time":"2025-11-03T10:30:29.819048632Z","level":"ERROR","msg":"failed to execute command","error":"open /etc/esdb/signing-key.pem: no such file or directory"}

even though the following test script seems to yield valid results:

$signingKey = new SigningKey();
$container = (new GenericContainer('alpine'))
    ->withCommand(['tail', '-f', '/dev/null'])
    ->withCopyContentToContainer([[
        'content' => $signingKey->privateKeyPem,
        'target' => '/etc/esdb/signing-key.pem',
    ]])
    ->start();

$output = $container->exec(['cat', '/etc/esdb/signing-key.pem']);
$container->stop();

var_dump($signingKey->privateKeyPem);
var_dump($output);

=>

string(119) "-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIHNdVTXkpg62smHk1gX4r2BQKHDsVVBj+31PSAvvy7Rp
-----END PRIVATE KEY-----
"
string(117) "w-----BEGIN PRIVATE KEY-----MC4CAQAwBQYDK2VwBCIEIHNdVTXkpg62smHk1gX4r2BQKHDsVVBj+31PSAvvy7Rp-----END PRIVATE KEY-----"

(not sure where the leading "w" comes from though)

@bwaidelich
Copy link
Contributor Author

bwaidelich commented Nov 3, 2025

I could not let this go and jumped into the rabbit hole:

The leading "w" in the test above comes from a bug in the StartedGenericContainer::sanitizeOutput() implementation – but this only affects the debug script above and is unrelated.

The actual issue seems to be a "timing problem": at the time of running the command, the private key is not yet available on the container, i.e. it fails with open /etc/esdb/signing-key.pem: no such file or directory. Afterwards the file exists with -rwxrwxrwx permissions and running

eventsourcingdb run --api-token secret --data-directory-temporary --http-enabled --https-enabled=false --signing-key-file /etc/esdb/signing-ke
y.pem

manually works

@goloroden goloroden self-assigned this Nov 3, 2025
The previous version called withCommand() twice which caused issues.
This version:
- Builds the complete command array first (including signing-key params)
- Calls withCommand() only once
- Adds the mount after the command is set

This maintains the fix from the original PR (using withMount instead
of withCopyContentToContainer) while avoiding the double command issue.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@goloroden goloroden force-pushed the bugfix/test-container-with-signing-key branch from b97d34d to 25c67ae Compare November 6, 2025 20:14
goloroden and others added 3 commits November 6, 2025 21:24
Changes:
- Use current directory (getcwd()) instead of sys_get_temp_dir() for better
  CI compatibility with Docker mounts
- Add cleanup of temp file in stop() method to avoid leaving files behind
- Store temp file path in private property for cleanup

The mount approach works better than copy methods because the file must
be available when the container starts (not after).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Restore the originally intended path /etc/esdb/signing-key.pem instead
of /tmp/signing-key.pem. Both work, but /etc/esdb matches the original
design and is more semantically correct.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@goloroden goloroden enabled auto-merge (squash) November 6, 2025 20:44
@goloroden goloroden merged commit f1e1b24 into thenativeweb:main Nov 6, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants