From 0c1561f569d04da39c373ffb4b9f8eabf01e5cf6 Mon Sep 17 00:00:00 2001 From: Benjamin AIMARD Date: Fri, 13 Nov 2026 18:25:03 +0000 Subject: [PATCH 1/3] security: exiger des identifiants explicites pour les tests navigateur --- documentation/source/developer.rst | 10 ++++- tests/Unit/Ihm/JsTest.php | 12 ++++-- tests/Unit/Panther/initAppTest.php | 15 +++++-- tests/Unit/Service/BrowserCredentialsTest.php | 39 +++++++++++++++++++ 4 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 tests/Unit/Service/BrowserCredentialsTest.php diff --git a/documentation/source/developer.rst b/documentation/source/developer.rst index 431c2da3e..a1b62a8ca 100644 --- a/documentation/source/developer.rst +++ b/documentation/source/developer.rst @@ -64,6 +64,14 @@ Commandes courantes Tests Panther ------------- +Les scénarios de connexion ``tests/Unit/Ihm/JsTest.php``, +``tests/Unit/Panther/IhmTest.php`` et ``tests/Unit/Panther/initAppTest.php`` +exigent des identifiants fournis par variables d'environnement. Aucun compte +de secours n'est utilisé. Sans les deux identifiants, ``JsTest`` est ignoré +par PHPUnit et les scripts autonomes s'arrêtent avant d'ouvrir un navigateur. +Utilisez exclusivement une instance et un compte jetables de test ; ne +commitez jamais leurs identifiants dans le dépôt. + Les tests utilisent les variables suivantes : ``NEXTCLOUD_BASE_URL`` @@ -73,7 +81,7 @@ Les tests utilisent les variables suivantes : Compte Nextcloud de test obligatoire. ``NEXTCLOUD_TEST_PASSWORD`` - Mot de passe du compte de test. + Mot de passe obligatoire du compte de test. ``NEXTCLOUD_TEST_COMPANY_ID`` Identifiant de la société de démonstration, affiché par le script de préparation. diff --git a/tests/Unit/Ihm/JsTest.php b/tests/Unit/Ihm/JsTest.php index b78ee0905..87739d972 100755 --- a/tests/Unit/Ihm/JsTest.php +++ b/tests/Unit/Ihm/JsTest.php @@ -11,13 +11,19 @@ class JsTest extends PantherTestCase { private string $password; public function setUp(): void { + $username = getenv('NEXTCLOUD_TEST_USER'); + $password = getenv('NEXTCLOUD_TEST_PASSWORD'); + if (!$username || !$password) { + $this->markTestSkipped('Set NEXTCLOUD_TEST_USER and NEXTCLOUD_TEST_PASSWORD for a disposable Nextcloud test account.'); + } + parent::setUp(); $this->url = rtrim( - getenv('NEXTCLOUD_BASE_URL') ?: 'http://dev.cybercorp.fr', + getenv('NEXTCLOUD_BASE_URL') ?: 'http://127.0.0.1:8080', '/' ); - $this->username = getenv('NEXTCLOUD_TEST_USER') ?: 'nextcloud'; - $this->password = getenv('NEXTCLOUD_TEST_PASSWORD') ?: 'Gestion-Panther-2026!'; + $this->username = $username; + $this->password = $password; } public function testClient(): void { diff --git a/tests/Unit/Panther/initAppTest.php b/tests/Unit/Panther/initAppTest.php index 17e51814b..40dae4035 100755 --- a/tests/Unit/Panther/initAppTest.php +++ b/tests/Unit/Panther/initAppTest.php @@ -3,17 +3,24 @@ use Symfony\Component\Panther\Client; require __DIR__.'/../../../vendor/autoload.php'; +$baseUrl = rtrim(getenv('NEXTCLOUD_BASE_URL') ?: 'http://127.0.0.1:8080', '/'); +$username = getenv('NEXTCLOUD_TEST_USER'); +$password = getenv('NEXTCLOUD_TEST_PASSWORD'); +if (!$username || !$password) { + throw new RuntimeException('Set NEXTCLOUD_TEST_USER and NEXTCLOUD_TEST_PASSWORD for a disposable Nextcloud test account.'); +} + $client = Client::createFirefoxClient(); -$crawler = $client->request('GET', 'http://127.0.0.1/index.php/apps/gestion'); +$crawler = $client->request('GET', $baseUrl . '/index.php/apps/gestion'); $form = $crawler->selectButton('Log in')->form(); -$form['user'] = 'nextcloud'; -$form['password'] = 'nextcloud'; +$form['user'] = $username; +$form['password'] = $password; $client->submit($form); sleep(5); $client->executeScript("document.getElementById('firstrunwizard').getElementsByClassName('header-close')[0].click()"); -$client->request('GET', 'http://127.0.0.1/settings/apps/organization'); +$client->request('GET', $baseUrl . '/settings/apps/organization'); $client->executeScript("var els = document.getElementsByClassName('app-name');for(var i = 0; i < els.length; i++){if(els[i].innerHTML.indexOf('Gestion') > -1){els[i].parentNode.getElementsByClassName('enable')[0].click()}}"); \ No newline at end of file diff --git a/tests/Unit/Service/BrowserCredentialsTest.php b/tests/Unit/Service/BrowserCredentialsTest.php new file mode 100644 index 000000000..2cf02975e --- /dev/null +++ b/tests/Unit/Service/BrowserCredentialsTest.php @@ -0,0 +1,39 @@ + $username, 'NEXTCLOUD_TEST_PASSWORD' => $password]; + $previous = []; + foreach ($variables as $name => $value) { + $previous[$name] = getenv($name); + putenv($value === null ? $name : $name . '=' . $value); + } + + try { + $test = new JsTest('testClient'); + try { + $test->setUp(); + $this->fail('The browser scenario must not use fallback credentials.'); + } catch (SkippedTestError $exception) { + $this->assertStringContainsString('NEXTCLOUD_TEST_USER', $exception->getMessage()); + $this->assertStringContainsString('NEXTCLOUD_TEST_PASSWORD', $exception->getMessage()); + } + } finally { + foreach ($previous as $name => $value) { + putenv($value === false ? $name : $name . '=' . $value); + } + } + } + + public function incompleteCredentials(): array { + return [[null, null], ['browser-test-user', null], [null, 'browser-test-password']]; + } +} From c89a1a5628a770ba98c9b188d37bc661904716ec Mon Sep 17 00:00:00 2001 From: Benjamin AIMARD Date: Fri, 13 Nov 2026 18:25:46 +0000 Subject: [PATCH 2/3] =?UTF-8?q?ci:=20ex=C3=A9cuter=20explicitement=20les?= =?UTF-8?q?=20trois=20suites=20dont=20la=20protection=20des=20identifiants?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/nextcloud-compatibility.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nextcloud-compatibility.yml b/.github/workflows/nextcloud-compatibility.yml index 5ce8f094a..b9a011e51 100644 --- a/.github/workflows/nextcloud-compatibility.yml +++ b/.github/workflows/nextcloud-compatibility.yml @@ -86,7 +86,7 @@ jobs: - name: Run PHP unit and database tests working-directory: nextcloud/apps/gestion - run: vendor/bin/phpunit --colors=always --testdox tests/Unit/Controller tests/Unit/Bdd tests/Unit/Service + run: vendor/bin/phpunit --colors=always --testdox --testsuite Controller,Bdd,Service - name: Check Nextcloud logs if: always() From 2122502265e98cb85c7ab2e340af739c6481e0c7 Mon Sep 17 00:00:00 2001 From: Benjamin AIMARD Date: Fri, 13 Nov 2026 18:52:41 +0000 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20pr=C3=A9parer=203.4.9=20et=20adapter?= =?UTF-8?q?=20les=20tests=20=C3=A0=20Nextcloud=2034=20et=2035?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appinfo/info.xml | 2 +- package-lock.json | 4 ++-- package.json | 2 +- tests/Unit/Bdd/BddTest.php | 2 +- tests/Unit/Bdd/CompanyHistoryAccessTest.php | 2 +- tests/Unit/Bdd/ProviderSecurityTest.php | 2 +- tests/Unit/Bdd/WorkspaceTest.php | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index a889023fa..d598a6da3 100755 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -29,7 +29,7 @@ If you require adaptations to comply with your country's regulations, please ope [![Donate](https://img.shields.io/badge/Donate-Buy%20me%20a%20coffee-yellow.svg)](https://www.buymeacoffee.com/benjaminaimard) ]]> - 3.4.8 + 3.4.9 agpl Benjamin AIMARD Gestion diff --git a/package-lock.json b/package-lock.json index 9a5375e7d..ca46d6776 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gestion", - "version": "3.4.8", + "version": "3.4.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gestion", - "version": "3.4.8", + "version": "3.4.9", "license": "AGPL-3.0-or-later", "devDependencies": { "@nextcloud/dialogs": "^7.4.0", diff --git a/package.json b/package.json index 99c5eb39a..b0fa64905 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gestion", - "version": "3.4.8", + "version": "3.4.9", "description": "Application pour gérer votre micro entreprise, client, facture, devis", "author": "Benjamin AIMARD", "contributors": [ diff --git a/tests/Unit/Bdd/BddTest.php b/tests/Unit/Bdd/BddTest.php index 9b4a3007c..edab47889 100755 --- a/tests/Unit/Bdd/BddTest.php +++ b/tests/Unit/Bdd/BddTest.php @@ -17,7 +17,7 @@ class BddTest extends TestCase { public function setUp(): void{ parent::setUp(); - $myDb = \OC::$server->getDatabaseConnection(); + $myDb = \OCP\Server::get(\OCP\IDBConnection::class); $l = $this->createMock('OCP\IL10N'); $this->db = new Bdd($myDb,$l); diff --git a/tests/Unit/Bdd/CompanyHistoryAccessTest.php b/tests/Unit/Bdd/CompanyHistoryAccessTest.php index 78353ce72..872023a31 100644 --- a/tests/Unit/Bdd/CompanyHistoryAccessTest.php +++ b/tests/Unit/Bdd/CompanyHistoryAccessTest.php @@ -16,7 +16,7 @@ class CompanyHistoryAccessTest extends TestCase { private int $foreignCompany; protected function setUp(): void { - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OCP\Server::get(\OCP\IDBConnection::class); $this->connection->beginTransaction(); $this->owner = 'history-owner-' . bin2hex(random_bytes(6)); $this->other = 'history-other-' . bin2hex(random_bytes(6)); diff --git a/tests/Unit/Bdd/ProviderSecurityTest.php b/tests/Unit/Bdd/ProviderSecurityTest.php index 8c137005a..60abd21ec 100644 --- a/tests/Unit/Bdd/ProviderSecurityTest.php +++ b/tests/Unit/Bdd/ProviderSecurityTest.php @@ -15,7 +15,7 @@ class ProviderSecurityTest extends TestCase { private string $owner; private array $credentials = ['client_id'=>'fixture-id','client_secret'=>'never-return-this-secret','customer_id'=>'fixture-customer','base_url'=>'https://api.example.com','auth_url'=>'https://auth.example.com/token']; protected function setUp(): void { - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OCP\Server::get(\OCP\IDBConnection::class); $this->connection->beginTransaction(); $l = $this->createMock(IL10N::class); $this->owner = 'security-test-'.bin2hex(random_bytes(6)); diff --git a/tests/Unit/Bdd/WorkspaceTest.php b/tests/Unit/Bdd/WorkspaceTest.php index 75da53efb..cfb823ad0 100644 --- a/tests/Unit/Bdd/WorkspaceTest.php +++ b/tests/Unit/Bdd/WorkspaceTest.php @@ -13,7 +13,7 @@ class WorkspaceTest extends TestCase { private string $owner; protected function setUp(): void { - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OCP\Server::get(\OCP\IDBConnection::class); $this->connection->beginTransaction(); $l = $this->createMock(IL10N::class); $l->method('t')->willReturnCallback(fn ($text) => $text);