From 46ae385ac6a31247bcd1b8c91978a84c22977560 Mon Sep 17 00:00:00 2001 From: Leonardo Bartoli Date: Tue, 3 Sep 2024 16:12:43 +0200 Subject: [PATCH 1/3] Enable instant test --- www/archive.inc | 9 ++++++++- www/common.inc | 5 +++++ www/testStatus.inc | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/www/archive.inc b/www/archive.inc index bcd4950b62..9779dee9b4 100644 --- a/www/archive.inc +++ b/www/archive.inc @@ -279,8 +279,12 @@ function DownloadArchive($id, $testServer) */ function RestoreArchive($id) { + global $request_context; + $isSaaSTest = (stripos($id, '_saas_') !== false); $saas_capture_prefix = GetSetting("cp_saas_capture_prefix"); + $isInstantTest = (stripos($id, '_instant_') !== false); + $isAdmin = isset($request_context) && $request_context->getUser()->isAdmin(); $ret = false; if (TestArchiveExpired($id)) { @@ -309,7 +313,7 @@ function RestoreArchive($id) } } //saas tests do not specifiy capture server in the URL, so we'll hardcode it - if ($isSaaSTest) { + if ($isSaaSTest || ($isInstantTest && $isAdmin)) { $capture_server = GetSetting("cp_capture_$saas_capture_prefix"); $capture_salt = GetSetting("cp_capture_salt_$saas_capture_prefix"); } @@ -417,6 +421,9 @@ function RestoreArchive($id) if ($deleteZip) { @unlink($zipfile); } + if ($isInstantTest && $isAdmin) { + ProcessUploadedTest($id); + } } } else { $ret = true; diff --git a/www/common.inc b/www/common.inc index 5853633155..301e926014 100644 --- a/www/common.inc +++ b/www/common.inc @@ -455,6 +455,11 @@ if (strlen($id)) { throw new ForbiddenException(); } + $test_is_instant = (stripos($id, '_instant_') !== false); + if ($test_is_instant && !(isset($request_context) && $request_context->getUser()->isAdmin())) { + throw new ForbiddenException(); + } + $url = array_key_exists('url', $test['testinfo']) ? htmlspecialchars($test['testinfo']['url']) : null; $dom = array_key_exists('domElement', $test['testinfo']) ? htmlspecialchars($test['testinfo']['domElement']) : null; $login = array_key_exists('login', $test['testinfo']) ? htmlspecialchars($test['testinfo']['login']) : null; diff --git a/www/testStatus.inc b/www/testStatus.inc index 6290d415f2..22109e3e17 100644 --- a/www/testStatus.inc +++ b/www/testStatus.inc @@ -15,6 +15,13 @@ $testInfoJson = null; */ function GetTestStatus($id, $includePosition = true) { + global $request_context; + $isInstantTest = (stripos($id, '_instant_') !== false); + $isAdmin = isset($request_context) && $request_context->getUser()->isAdmin(); + if ($isInstantTest && !$isAdmin) { + return array('statusCode' => 400, 'statusText' => 'Test not found', 'id' => $id); + } + $testServer = GetServerForTest($id); if (isset($testServer)) { // Proxy the status through the server that actually owns the test From da8027767f3762ac68465f17c5cc0efcbc5ef48b Mon Sep 17 00:00:00 2001 From: Leonardo Bartoli Date: Wed, 4 Sep 2024 09:54:09 +0200 Subject: [PATCH 2/3] Bug fix --- www/archive.inc | 5 ++--- www/common.inc | 5 ----- www/testStatus.inc | 6 ------ 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/www/archive.inc b/www/archive.inc index 9779dee9b4..84cb51f3b0 100644 --- a/www/archive.inc +++ b/www/archive.inc @@ -284,7 +284,6 @@ function RestoreArchive($id) $isSaaSTest = (stripos($id, '_saas_') !== false); $saas_capture_prefix = GetSetting("cp_saas_capture_prefix"); $isInstantTest = (stripos($id, '_instant_') !== false); - $isAdmin = isset($request_context) && $request_context->getUser()->isAdmin(); $ret = false; if (TestArchiveExpired($id)) { @@ -313,7 +312,7 @@ function RestoreArchive($id) } } //saas tests do not specifiy capture server in the URL, so we'll hardcode it - if ($isSaaSTest || ($isInstantTest && $isAdmin)) { + if ($isSaaSTest || $isInstantTest) { $capture_server = GetSetting("cp_capture_$saas_capture_prefix"); $capture_salt = GetSetting("cp_capture_salt_$saas_capture_prefix"); } @@ -421,7 +420,7 @@ function RestoreArchive($id) if ($deleteZip) { @unlink($zipfile); } - if ($isInstantTest && $isAdmin) { + if ($isInstantTest) { ProcessUploadedTest($id); } } diff --git a/www/common.inc b/www/common.inc index 301e926014..5853633155 100644 --- a/www/common.inc +++ b/www/common.inc @@ -455,11 +455,6 @@ if (strlen($id)) { throw new ForbiddenException(); } - $test_is_instant = (stripos($id, '_instant_') !== false); - if ($test_is_instant && !(isset($request_context) && $request_context->getUser()->isAdmin())) { - throw new ForbiddenException(); - } - $url = array_key_exists('url', $test['testinfo']) ? htmlspecialchars($test['testinfo']['url']) : null; $dom = array_key_exists('domElement', $test['testinfo']) ? htmlspecialchars($test['testinfo']['domElement']) : null; $login = array_key_exists('login', $test['testinfo']) ? htmlspecialchars($test['testinfo']['login']) : null; diff --git a/www/testStatus.inc b/www/testStatus.inc index 22109e3e17..15202bdcfd 100644 --- a/www/testStatus.inc +++ b/www/testStatus.inc @@ -16,12 +16,6 @@ $testInfoJson = null; function GetTestStatus($id, $includePosition = true) { global $request_context; - $isInstantTest = (stripos($id, '_instant_') !== false); - $isAdmin = isset($request_context) && $request_context->getUser()->isAdmin(); - if ($isInstantTest && !$isAdmin) { - return array('statusCode' => 400, 'statusText' => 'Test not found', 'id' => $id); - } - $testServer = GetServerForTest($id); if (isset($testServer)) { // Proxy the status through the server that actually owns the test From f26a061e4dbd1bdca81fdd0caa3df5a8a73c87b1 Mon Sep 17 00:00:00 2001 From: Leonardo Bartoli Date: Wed, 4 Sep 2024 10:48:50 +0200 Subject: [PATCH 3/3] Remove unused variable --- www/archive.inc | 2 -- www/testStatus.inc | 1 - 2 files changed, 3 deletions(-) diff --git a/www/archive.inc b/www/archive.inc index 84cb51f3b0..2697e0ffe3 100644 --- a/www/archive.inc +++ b/www/archive.inc @@ -279,8 +279,6 @@ function DownloadArchive($id, $testServer) */ function RestoreArchive($id) { - global $request_context; - $isSaaSTest = (stripos($id, '_saas_') !== false); $saas_capture_prefix = GetSetting("cp_saas_capture_prefix"); $isInstantTest = (stripos($id, '_instant_') !== false); diff --git a/www/testStatus.inc b/www/testStatus.inc index 15202bdcfd..6290d415f2 100644 --- a/www/testStatus.inc +++ b/www/testStatus.inc @@ -15,7 +15,6 @@ $testInfoJson = null; */ function GetTestStatus($id, $includePosition = true) { - global $request_context; $testServer = GetServerForTest($id); if (isset($testServer)) { // Proxy the status through the server that actually owns the test