Skip to content

Commit 4b479e6

Browse files
fix: prevent race condition in CA ID generation during tests
IAppConfig uses per-process cache, causing race conditions when CLI commands and HTTP requests execute simultaneously during Behat tests. The CLI generates a ca_id, but HTTP requests see an empty cache and generate a different ca_id, overwriting the CLI value. Solution: - Detect debug mode (automatically set during Behat tests) - Apply file lock + cache clear workaround only in debug mode - Production code remains unchanged for optimal performance This fix resolves test failures in features/sign/request.feature:28 and features/sign/request.feature:61 where setup validation was failing due to mismatched certificate paths. Signed-off-by: Vitor Mattos <[email protected]>
1 parent e51a915 commit 4b479e6

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

lib/Handler/CertificateEngine/AEngineHandler.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,14 @@ public function readCertificate(string $certificate, string $privateKey): array
141141
public function getCaId(): string {
142142
$caId = $this->caIdentifierService->getCaId();
143143
if (empty($caId)) {
144-
$caId = $this->caIdentifierService->generateCaId($this->getName());
144+
// In debug mode (tests), use file lock and cache clear to prevent race conditions
145+
// between CLI commands and HTTP requests executing simultaneously.
146+
// In production, this is not needed as setup commands run before HTTP requests.
147+
if ($this->config->getSystemValueBool('debug', false)) {
148+
$caId = $this->getCaIdWithLock();
149+
} else {
150+
$caId = $this->caIdentifierService->generateCaId($this->getName());
151+
}
145152
}
146153
return $caId;
147154
}

0 commit comments

Comments
 (0)