From 2ecee506b42ff91e186edd98cd6dc1af9786c272 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 22 Jan 2018 18:24:16 -0500 Subject: [PATCH] PHPC-1100: Require SSL or crypto as needed in tests This addresses test failures when the driver is compiled without SSL. --- .../causal-consistency-001.phpt | 1 + .../causal-consistency-002.phpt | 1 + .../causal-consistency-003.phpt | 1 + .../causal-consistency-004.phpt | 1 + .../causal-consistency-005.phpt | 1 + .../causal-consistency-006.phpt | 1 + .../causal-consistency-007.phpt | 1 + .../causal-consistency-008.phpt | 1 + .../causal-consistency-009.phpt | 1 + .../causal-consistency-010.phpt | 1 + .../causal-consistency-011.phpt | 1 + .../causal-consistency-012.phpt | 1 + tests/connect/bug0720.phpt | 1 + tests/connect/bug1045.phpt | 1 + tests/connect/standalone-plain-0002.phpt | 1 + .../connect/standalone-ssl-no_verify-001.phpt | 1 + .../connect/standalone-ssl-no_verify-002.phpt | 1 + .../standalone-ssl-verify_cert-001.phpt | 1 + .../standalone-ssl-verify_cert-002.phpt | 1 + .../standalone-ssl-verify_cert-error-001.phpt | 1 + .../standalone-ssl-verify_cert-error-002.phpt | 1 + tests/connect/standalone-x509-auth-001.phpt | 1 + tests/connect/standalone-x509-auth-002.phpt | 1 + tests/connect/standalone-x509-error-0001.phpt | 1 + tests/manager/bug0572.phpt | 1 + tests/manager/manager-ctor-ssl-001.phpt | 3 ++ .../manager/manager-set-uri-options-002.phpt | 1 + .../retryable-writes-001.phpt | 1 + .../retryable-writes-002.phpt | 1 + .../retryable-writes-003.phpt | 1 + .../retryable-writes-004.phpt | 1 + .../retryable-writes-005.phpt | 1 + tests/session/session-001.phpt | 1 + tests/session/session-002.phpt | 1 + tests/session/session-003.phpt | 1 + .../session-advanceClusterTime-001.phpt | 1 + .../session-advanceOperationTime-001.phpt | 1 + .../session-advanceOperationTime-002.phpt | 1 + .../session-advanceOperationTime-003.phpt | 1 + ...ession-advanceOperationTime_error-001.phpt | 1 + tests/session/session-debug-001.phpt | 1 + tests/session/session-debug-002.phpt | 1 + tests/session/session-debug-003.phpt | 1 + tests/session/session-getClusterTime-001.phpt | 1 + .../session-getLogicalSessionId-001.phpt | 1 + .../session/session-getOperationTime-001.phpt | 1 + tests/utils/tools.php | 49 +++++++++++++++++-- 47 files changed, 93 insertions(+), 4 deletions(-) diff --git a/tests/causal-consistency/causal-consistency-001.phpt b/tests/causal-consistency/causal-consistency-001.phpt index 7dbd51800..4bdd706f1 100644 --- a/tests/causal-consistency/causal-consistency-001.phpt +++ b/tests/causal-consistency/causal-consistency-001.phpt @@ -2,6 +2,7 @@ Causal consistency: new session has no operation time --SKIPIF-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- enabled')); + + if (preg_match($pattern, $info) !== 1) { + exit('skip Crypto is not supported'); + } + + if (empty($libs)) { + return; + } + + $pattern = sprintf('/^%s([\w ]+)$/m', preg_quote('libmongoc crypto library => ')); + + if (preg_match($pattern, $info, $matches) !== 1) { + exit('skip Could not determine crypto library'); + } + + if (!in_array($matches[1], $libs)) { + exit('skip Needs crypto library ' . implode(', ', $libs) . ', but found ' . $matches[1]); + } +} + +/* Checks that libmongoc supports SSL. If one or more libaries are provided, + * additionally check the value of "libmongoc SSL library" as reported by + * phpinfo(). Possible values are "OpenSSL", "LibreSSL", "Secure Transport", and + * "Secure Channel". */ +function NEEDS_SSL(array $libs = []) +{ + ob_start(); + phpinfo(INFO_MODULES); + $info = ob_get_clean(); + + $pattern = sprintf('/^%s$/m', preg_quote('libmongoc SSL => enabled')); + + if (preg_match($pattern, $info) !== 1) { + exit('skip SSL is not supported'); + } + + if (empty($libs)) { + return; + } + $pattern = sprintf('/^%s([\w ]+)$/m', preg_quote('libmongoc SSL library => ')); if (preg_match($pattern, $info, $matches) !== 1) {