|
|
@@ -29,6 +29,29 @@ test('uses protocol-specific STARTTLS probes for explicit TLS upgrade ports', ()
|
|
|
assert.match(scriptSource, /143\).*protocol_args=\(-starttls imap\)/);
|
|
|
});
|
|
|
|
|
|
+test('falls back to docker port when compose cannot resolve the Dovecot mapping', { skip: !canRun }, (t) => {
|
|
|
+ const fixture = createFixture(t);
|
|
|
+ generateCertificate(fixture.sourceDir, 'example.test');
|
|
|
+ const fallback = createComposePortFallbackPath(fixture.root, fixture.path);
|
|
|
+
|
|
|
+ const result = runSync(fixture, {
|
|
|
+ restart: '1',
|
|
|
+ env: {
|
|
|
+ PATH: fallback.path,
|
|
|
+ MAILHUB_CERT_VERIFY_ENDPOINTS: '993',
|
|
|
+ MAILHUB_TEST_DOCKER_LOG: fallback.logFile,
|
|
|
+ MAILHUB_TEST_PRESENTED_CERT: fixture.sourceCert,
|
|
|
+ MAILHUB_TEST_REAL_OPENSSL: opensslPath
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ assert.equal(result.status, 0, result.stderr);
|
|
|
+ const commands = readFileSync(fallback.logFile, 'utf8').trim().split('\n');
|
|
|
+ assert.ok(commands.includes('compose port dovecot 31993'), commands.join('\n'));
|
|
|
+ assert.ok(commands.includes('compose ps -q dovecot'), commands.join('\n'));
|
|
|
+ assert.ok(commands.includes('port dovecot-fallback 31993/tcp'), commands.join('\n'));
|
|
|
+});
|
|
|
+
|
|
|
test('atomically synchronizes a valid wildcard certificate and preserves safe permissions', { skip: !canRun }, (t) => {
|
|
|
const fixture = createFixture(t);
|
|
|
generateCertificate(fixture.sourceDir, 'example.test');
|
|
|
@@ -375,6 +398,58 @@ exit 0
|
|
|
return `${binDir}${path.delimiter}${basePath}`;
|
|
|
}
|
|
|
|
|
|
+function createComposePortFallbackPath(root, basePath) {
|
|
|
+ const binDir = path.join(root, 'compose-port-fallback-bin');
|
|
|
+ const logFile = path.join(root, 'compose-port-fallback.log');
|
|
|
+ mkdirSync(binDir, { recursive: true });
|
|
|
+ writeFileSync(logFile, '');
|
|
|
+ writeExecutable(path.join(binDir, 'docker'), `#!/usr/bin/env bash
|
|
|
+set -euo pipefail
|
|
|
+printf '%s\\n' "$*" >> "\${MAILHUB_TEST_DOCKER_LOG}"
|
|
|
+if [[ "\${1:-}" == "compose" && "\${2:-}" == "exec" ]]; then
|
|
|
+ exit 0
|
|
|
+fi
|
|
|
+if [[ "\${1:-}" == "compose" && "\${2:-}" == "restart" ]]; then
|
|
|
+ exit 0
|
|
|
+fi
|
|
|
+if [[ "\${1:-}" == "compose" && "\${2:-}" == "port" ]]; then
|
|
|
+ printf '%s\\n' 'invalid IP:0' >&2
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+if [[ "\${1:-}" == "compose" && "\${2:-}" == "ps" && "\${3:-}" == "-q" ]]; then
|
|
|
+ printf '%s\\n' 'dovecot-fallback'
|
|
|
+ exit 0
|
|
|
+fi
|
|
|
+if [[ "\${1:-}" == "port" && "\${2:-}" == "dovecot-fallback" && "\${3:-}" == "31993/tcp" ]]; then
|
|
|
+ printf '%s\\n' '0.0.0.0:1993'
|
|
|
+ exit 0
|
|
|
+fi
|
|
|
+exit 1
|
|
|
+`);
|
|
|
+ writeExecutable(path.join(binDir, 'openssl'), `#!/usr/bin/env bash
|
|
|
+set -euo pipefail
|
|
|
+if [[ "\${1:-}" == "s_client" ]]; then
|
|
|
+ connection=""
|
|
|
+ previous=""
|
|
|
+ for argument in "$@"; do
|
|
|
+ if [[ "\${previous}" == "-connect" ]]; then
|
|
|
+ connection="\${argument}"
|
|
|
+ break
|
|
|
+ fi
|
|
|
+ previous="\${argument}"
|
|
|
+ done
|
|
|
+ [[ "\${connection}" == "127.0.0.1:1993" ]] || exit 71
|
|
|
+ cat "\${MAILHUB_TEST_PRESENTED_CERT}"
|
|
|
+ exit 0
|
|
|
+fi
|
|
|
+exec "\${MAILHUB_TEST_REAL_OPENSSL}" "$@"
|
|
|
+`);
|
|
|
+ return {
|
|
|
+ logFile,
|
|
|
+ path: `${binDir}${path.delimiter}${basePath}`
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
function stripDoubleDashWrapper(command) {
|
|
|
return `#!/usr/bin/env bash
|
|
|
set -euo pipefail
|