Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"require": {
"psr/log": "1.1.4",
"phpseclib/phpseclib": "3.0.16",
"phpseclib/phpseclib": "3.0.43",
"phpmailer/phpmailer": "6.6.4",
"hakasapl/phpopenldaper": "1.0.5"
}
Expand Down
15 changes: 9 additions & 6 deletions resources/lib/UnitySite.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ 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;
// phpcs:disable
return array_map(function($x){return $x->key;}, $keys);
// phpcs:enable
}

public static function testValidSSHKey($key_str)
Expand Down
23 changes: 23 additions & 0 deletions test/unit/UnitySiteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,27 @@ public function testTestValidSSHKey(bool $expected, string $key)
$SITE = new UnitySite();
$this->assertEquals($expected, $SITE->testValidSSHKey($key));
}

public static function providerTestGetGithubKeys()
{
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("providerTestGetGithubKeys")]
public function testGetGithubKeys(string $username, array $expected)
{
$SITE = new UnitySite();
$this->assertEquals($expected, $SITE->getGithubKeys($username));
}
}
3 changes: 0 additions & 3 deletions webroot/panel/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Loading