PDO::ERRMODE_EXCEPTION]); $pdo->beginTransaction(); try { $pdo->exec('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY'); $db = new PostgresConnection($pdo, $source['DB_DATABASE'], '', ['driver' => 'pgsql', 'search_path' => 'public']); $settings = ['enabled' => true, 'root' => $proof['runtime_directory'], 'manifest_sha256' => $proof['runtime_manifest'], 'installation_id' => $proof['installation_id'], 'features' => array_fill_keys(StandaloneRuntime::FEATURES, true)]; $runtime = new StandaloneRuntime($settings, new StandaloneArtifact); $runtime->assertInstallation($db); StandaloneSchema::verify($db->getSchemaBuilder(), $settings['features']); if ((int) $pdo->query('SELECT count(*) FROM compras_runtime_installations')->fetchColumn() !== 1 || filter_var($source['COMPRAS_RUNTIME_ENABLED'] ?? false, FILTER_VALIDATE_BOOLEAN)) { throw new LogicException('PILOT_INSTALLATION_RECEIPT_OR_ACTIVATION'); } $wrong = $settings; $wrong['installation_id'] = Str::uuid()->toString(); $rejected = false; try { (new StandaloneRuntime($wrong, new StandaloneArtifact))->assertInstallation($db); } catch (LogicException $error) { $rejected = $error->getMessage() === 'COMPRAS_RUNTIME_INSTALLATION_MISMATCH'; } if (! $rejected) { throw new LogicException('PILOT_INSTALLATION_WRONG_ID_ACCEPTED'); } $pdo->commit(); } finally { if ($pdo->inTransaction()) { $pdo->rollBack(); } } $http = []; foreach (['/avaliar', '/login'] as $path) { $headers = []; $context = stream_context_create(['http' => ['timeout' => 5, 'follow_location' => 0, 'ignore_errors' => true]]); $body = file_get_contents('http://127.0.0.1:8005'.$path, false, $context); $headers = $http_response_header ?? []; if (! is_string($body) || ! preg_match('/^HTTP\/\S+ (200|302)\b/', $headers[0] ?? '', $status)) { throw new LogicException('PILOT_INSTALLATION_HTTP_UNAVAILABLE'); } $http[$path] = (int) $status[1]; } $result = ['date' => gmdate('c'), 'state' => 'passed', 'read_only_database_transaction' => true, 'receipt_and_non_elevated_binding_verified' => true, 'wrong_installation_id_refused' => true, 'all_24_module_schemas_verified' => true, 'runtime_activation_stays_disabled' => true, 'http' => $http, 'business_commands' => false, 'permission_changes' => false]; file_put_contents($root.'/docs/proofs/compras-standalone-pilot-installation-check.json', json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR).PHP_EOL); echo json_encode($result, JSON_THROW_ON_ERROR).PHP_EOL;