@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
use App\Services\StandaloneArtifact;
|
||||
use App\Services\StandaloneRuntime;
|
||||
use App\Services\StandaloneSchema;
|
||||
use Illuminate\Database\PostgresConnection;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
if (! in_array('--read-only', $argv, true)) {
|
||||
throw new LogicException('EXPLICIT_READ_ONLY_CHECK_REQUIRED');
|
||||
}
|
||||
$root = dirname(__DIR__);
|
||||
$proof = json_decode(file_get_contents($root.'/docs/proofs/compras-standalone-pilot-installation.json'), true, 32, JSON_THROW_ON_ERROR);
|
||||
$source = json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/payables-demo-compras.json'), true, 32, JSON_THROW_ON_ERROR);
|
||||
if ($proof['state'] !== 'passed' || $proof['pilot_activation'] !== false || $source['APP_ENV'] !== 'payable-testing'
|
||||
|| $source['DB_HOST'] !== '127.0.0.1' || realpath($source['HOST_ROOT']) !== realpath($root)
|
||||
|| ! preg_match('/^compras_receipts_test_([a-f0-9]{12})$/D', $source['DB_DATABASE'], $match)
|
||||
|| $source['DB_USERNAME'] !== 'payable_qa_'.$match[1]) {
|
||||
throw new LogicException('PILOT_INSTALLATION_READ_TARGET');
|
||||
}
|
||||
$pdo = new PDO('pgsql:host=127.0.0.1;port='.(int) $source['DB_PORT'].';dbname='.$source['DB_DATABASE'],
|
||||
$source['DB_USERNAME'], $source['DB_PASSWORD'], [PDO::ATTR_ERRMODE => 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;
|
||||
Reference in New Issue
Block a user