From bef351029e403686fcb33cb110786e0f9d174930 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 13:10:37 -0400 Subject: [PATCH 01/14] handle github keys api properly --- resources/lib/UnitySite.php | 13 +++++++------ webroot/panel/account.php | 3 --- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/resources/lib/UnitySite.php b/resources/lib/UnitySite.php index 2bedf8a6..852613d7 100644 --- a/resources/lib/UnitySite.php +++ b/resources/lib/UnitySite.php @@ -36,15 +36,16 @@ public static function getGithubKeys($username) curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - $output = json_decode(curl_exec($curl), true); + $keys = json_decode(curl_exec($curl), false); curl_close($curl); - $out = array(); - foreach ($output as $value) { - array_push($out, $value["key"]); + // normally returns array of objects each with a ->key attribute + // if bad URL or no such user, returns status=404 object + // if no keys, returns [] + if ((!is_array($keys)) || (count($keys) == 0)) { + return []; } - - return $out; + return array_map(function($x){return $x->key;}, $keys); } public static function testValidSSHKey($key_str) diff --git a/webroot/panel/account.php b/webroot/panel/account.php index c45602ca..867387ef 100644 --- a/webroot/panel/account.php +++ b/webroot/panel/account.php @@ -38,9 +38,6 @@ break; case "github": $gh_user = $_POST["gh_user"]; - if (empty($gh_user)) { - break; - } $keys = UnitySite::getGithubKeys($gh_user); foreach ($keys as $key) { if (UnitySite::testValidSSHKey($key)) { From 39b564996d8327d607ef02b4c85af8b8398deb39 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 13:41:48 -0400 Subject: [PATCH 02/14] disable php code sniffer --- resources/lib/UnitySite.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/lib/UnitySite.php b/resources/lib/UnitySite.php index 852613d7..7ad484ff 100644 --- a/resources/lib/UnitySite.php +++ b/resources/lib/UnitySite.php @@ -45,7 +45,9 @@ public static function getGithubKeys($username) if ((!is_array($keys)) || (count($keys) == 0)) { return []; } + // phpcs:disable return array_map(function($x){return $x->key;}, $keys); + // phpcs:enable } public static function testValidSSHKey($key_str) From c14e0343a35436669a7e040dd1ece17e44317a44 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:05:00 -0400 Subject: [PATCH 03/14] add tests for getGithubKeys --- test/unit/UnitySiteTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/unit/UnitySiteTest.php b/test/unit/UnitySiteTest.php index 8eb06480..21dce2cd 100644 --- a/test/unit/UnitySiteTest.php +++ b/test/unit/UnitySiteTest.php @@ -29,4 +29,26 @@ public function testTestValidSSHKey(bool $expected, string $key) $SITE = new UnitySite(); $this->assertEquals($expected, $SITE->testValidSSHKey($key)); } + + public static function testGetGithubKeysProvider() + { + return [ + # empty + ["", []], + # nonexistent user + ["asdfkljhasdflkjashdflkjashdflkasjd", []], + # user with no keys + ["sheldor1510", []], + # user with 1 key + //phpcs:disable + ["simonLeary42", ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDGRl6JWPj+Gq2Lz9GjYdUl4/unLoFOyfgeiII1CxutpabPByRJbeuonR0zTpn51tZeYuAUOJBOeKt+Lj4i4UDGl6igpdXXSwkBXl7jxfRPwJ6WuTkDx7Z8ynwnqlDV2q089q4OX/b/uuHgsIhIBwrouKsRQaZIqTbwNMfiqQ2zl14V0KMrTPzOiwR6Q+hqSaR5Z29WKE7ff/OWzSC3/0T6avCmcCbQaRPJdVM+QC17B0vl8FzPwRjorMngwZ0cImdQ/0Ww1d12YAL7UWp1c2egfnthKP3MuQZnNF8ixsAk1eIIwTRdiI87BOoorW8NXhxXmhyheRCsFwyP4LJBqyUVoZJ0UYyk0AO4G9EStnfpiz8YXGK+M1G4tUrWgzs1cdjlHtgCWUmITtgabnYCC4141m7n4GZTk2H/lSrJcvAs3JEiwLTj1lzeGgzeSsz/XKsnOJyzjEVr2Jp3iT+J9PbQpfS0SxTCIGgxMqllovv79pfsF/zc+vaxqSShyHW7oyn7hLMHM60LO/IIX1RWGL3rD9ecXx2pXXQ1RhIkVteIi13XkFt+KW00cstFlAd3EHCoY/XorShd2jeID7tpnYlmNfotYUs6IKefvpNC0PWkh5UXFEv3SUfw4Wd8O0DiHfhkrhxn1W/GajqSIlZ5DKgPzFg8EHexv8lSa7WJg0H3YQ=="]] + //phpcs:enable + ] + } + + #[DataProvider("testGetGithubKeysProvider")] + public static function testGetGithubKeys(array $expected, string $username) + { + $this->assertEquals($expected, $SITE->getGithubKeys($username)); + } } From 1c4244f7aa2713f84889b29891c8a2cf18060ec1 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:05:38 -0400 Subject: [PATCH 04/14] missing semicolon --- test/unit/UnitySiteTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/UnitySiteTest.php b/test/unit/UnitySiteTest.php index 21dce2cd..305e93d9 100644 --- a/test/unit/UnitySiteTest.php +++ b/test/unit/UnitySiteTest.php @@ -43,7 +43,7 @@ public static function testGetGithubKeysProvider() //phpcs:disable ["simonLeary42", ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDGRl6JWPj+Gq2Lz9GjYdUl4/unLoFOyfgeiII1CxutpabPByRJbeuonR0zTpn51tZeYuAUOJBOeKt+Lj4i4UDGl6igpdXXSwkBXl7jxfRPwJ6WuTkDx7Z8ynwnqlDV2q089q4OX/b/uuHgsIhIBwrouKsRQaZIqTbwNMfiqQ2zl14V0KMrTPzOiwR6Q+hqSaR5Z29WKE7ff/OWzSC3/0T6avCmcCbQaRPJdVM+QC17B0vl8FzPwRjorMngwZ0cImdQ/0Ww1d12YAL7UWp1c2egfnthKP3MuQZnNF8ixsAk1eIIwTRdiI87BOoorW8NXhxXmhyheRCsFwyP4LJBqyUVoZJ0UYyk0AO4G9EStnfpiz8YXGK+M1G4tUrWgzs1cdjlHtgCWUmITtgabnYCC4141m7n4GZTk2H/lSrJcvAs3JEiwLTj1lzeGgzeSsz/XKsnOJyzjEVr2Jp3iT+J9PbQpfS0SxTCIGgxMqllovv79pfsF/zc+vaxqSShyHW7oyn7hLMHM60LO/IIX1RWGL3rD9ecXx2pXXQ1RhIkVteIi13XkFt+KW00cstFlAd3EHCoY/XorShd2jeID7tpnYlmNfotYUs6IKefvpNC0PWkh5UXFEv3SUfw4Wd8O0DiHfhkrhxn1W/GajqSIlZ5DKgPzFg8EHexv8lSa7WJg0H3YQ=="]] //phpcs:enable - ] + ]; } #[DataProvider("testGetGithubKeysProvider")] From b0db9d4d1e0cdc9bb6ec68da8826167afa4a0eb1 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:06:23 -0400 Subject: [PATCH 05/14] add php -l pre-commit --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fee724eb..72f88472 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,3 +46,9 @@ repos: language: system files: \.php$ args: [--standard=PSR2, --colors] + - id: php-l + name: PHP -l + entry: php + language: system + files: \.php$ + args: [-l] From c58b1c2ef5e921e92bd40e6dfa2543f6999e50e7 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:07:27 -0400 Subject: [PATCH 06/14] fix argument order --- test/unit/UnitySiteTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/UnitySiteTest.php b/test/unit/UnitySiteTest.php index 305e93d9..2e43ff17 100644 --- a/test/unit/UnitySiteTest.php +++ b/test/unit/UnitySiteTest.php @@ -47,7 +47,7 @@ public static function testGetGithubKeysProvider() } #[DataProvider("testGetGithubKeysProvider")] - public static function testGetGithubKeys(array $expected, string $username) + public static function testGetGithubKeys(string $username, array $expected) { $this->assertEquals($expected, $SITE->getGithubKeys($username)); } From 6c7757706daf2069049bb4cb8e0158eeb0992bdb Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:08:43 -0400 Subject: [PATCH 07/14] no static --- test/unit/UnitySiteTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/UnitySiteTest.php b/test/unit/UnitySiteTest.php index 2e43ff17..d3a968f0 100644 --- a/test/unit/UnitySiteTest.php +++ b/test/unit/UnitySiteTest.php @@ -47,7 +47,7 @@ public static function testGetGithubKeysProvider() } #[DataProvider("testGetGithubKeysProvider")] - public static function testGetGithubKeys(string $username, array $expected) + public function testGetGithubKeys(string $username, array $expected) { $this->assertEquals($expected, $SITE->getGithubKeys($username)); } From 3dd8c46b3f9788f91c4935077207897c4ac49509 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:09:28 -0400 Subject: [PATCH 08/14] construct site object --- test/unit/UnitySiteTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/UnitySiteTest.php b/test/unit/UnitySiteTest.php index d3a968f0..d7e0663d 100644 --- a/test/unit/UnitySiteTest.php +++ b/test/unit/UnitySiteTest.php @@ -49,6 +49,7 @@ public static function testGetGithubKeysProvider() #[DataProvider("testGetGithubKeysProvider")] public function testGetGithubKeys(string $username, array $expected) { + $SITE = new UnitySite(); $this->assertEquals($expected, $SITE->getGithubKeys($username)); } } From b9077e74a438014f8c1330a7e2c7b9d21a71513c Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:10:41 -0400 Subject: [PATCH 09/14] rename provider --- test/unit/UnitySiteTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/UnitySiteTest.php b/test/unit/UnitySiteTest.php index d7e0663d..05e3576c 100644 --- a/test/unit/UnitySiteTest.php +++ b/test/unit/UnitySiteTest.php @@ -30,7 +30,7 @@ public function testTestValidSSHKey(bool $expected, string $key) $this->assertEquals($expected, $SITE->testValidSSHKey($key)); } - public static function testGetGithubKeysProvider() + private static function providerTestGetGithubKeys() { return [ # empty @@ -46,7 +46,7 @@ public static function testGetGithubKeysProvider() ]; } - #[DataProvider("testGetGithubKeysProvider")] + #[DataProvider("providerTestGetGithubKeys")] public function testGetGithubKeys(string $username, array $expected) { $SITE = new UnitySite(); From e94909871b9fde9d03f025cd249d0a67b7645faa Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:11:23 -0400 Subject: [PATCH 10/14] provider public --- test/unit/UnitySiteTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/UnitySiteTest.php b/test/unit/UnitySiteTest.php index 05e3576c..9c508e45 100644 --- a/test/unit/UnitySiteTest.php +++ b/test/unit/UnitySiteTest.php @@ -30,7 +30,7 @@ public function testTestValidSSHKey(bool $expected, string $key) $this->assertEquals($expected, $SITE->testValidSSHKey($key)); } - private static function providerTestGetGithubKeys() + public static function providerTestGetGithubKeys() { return [ # empty From e25fa07e59e0dec7bb71a28aca8c258703a46445 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:12:53 -0400 Subject: [PATCH 11/14] update phpseclib --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 76750d1c..32b42e52 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "require": { "psr/log": "1.1.4", "phpseclib/phpseclib": "3.0.16", - "phpmailer/phpmailer": "6.6.4", + "phpmailer/phpmailer": "6.9.3", "hakasapl/phpopenldaper": "1.0.5" } } From 803f249b081f66150df06cebcdd99c24986228ca Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:13:23 -0400 Subject: [PATCH 12/14] rename pre-commit id --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 72f88472..bb4f1b00 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,7 +47,7 @@ repos: files: \.php$ args: [--standard=PSR2, --colors] - id: php-l - name: PHP -l + name: php -l entry: php language: system files: \.php$ From 6f0bc9f4c6231f09dc5385692f0247a75522a9b5 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:15:13 -0400 Subject: [PATCH 13/14] update phpseclib --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 32b42e52..5a361657 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "require": { "psr/log": "1.1.4", - "phpseclib/phpseclib": "3.0.16", + "phpseclib/phpseclib": "3.0.43", "phpmailer/phpmailer": "6.9.3", "hakasapl/phpopenldaper": "1.0.5" } From 2cdb0adc53d4981895600e512b5d301073cf21fd Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 11 Apr 2025 17:16:07 -0400 Subject: [PATCH 14/14] don't upgrade mailer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5a361657..606629ac 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "require": { "psr/log": "1.1.4", "phpseclib/phpseclib": "3.0.43", - "phpmailer/phpmailer": "6.9.3", + "phpmailer/phpmailer": "6.6.4", "hakasapl/phpopenldaper": "1.0.5" } }