Skip to content

Commit 41d7441

Browse files
authored
add tests for adding SSH keys (#192)
* move github to its own class * ssh key add testst * fix class name * add missing require * add more tests for ssh key validation
1 parent b655014 commit 41d7441

File tree

10 files changed

+253
-62
lines changed

10 files changed

+253
-62
lines changed

resources/autoload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
require_once __DIR__ . "/lib/UnityConfig.php";
2020
require_once __DIR__ . "/lib/UnityWebhook.php";
2121
require_once __DIR__ . "/lib/UnityRedis.php";
22+
require_once __DIR__ . "/lib/UnityGithub.php";
2223

2324
// run init script
2425
require __DIR__ . "/init.php";

resources/init.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use UnityWebPortal\lib\UnityUser;
1313
use UnityWebPortal\lib\UnityRedis;
1414
use UnityWebPortal\lib\UnityWebhook;
15+
use UnityWebPortal\lib\UnityGithub;
1516

1617
//
1718
// Initialize Session
@@ -84,6 +85,8 @@
8485
$CONFIG["site"]["url"] . $CONFIG["site"]["prefix"]
8586
);
8687

88+
$GITHUB = new UnityGithub();
89+
8790
//
8891
// SSO Init
8992
//

resources/lib/UnityGithub.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace UnityWebPortal\lib;
4+
5+
class UnityGithub
6+
{
7+
public function getSshPublicKeys($username)
8+
{
9+
$url = "https://api.github.com/users/$username/keys";
10+
$headers = array(
11+
"User-Agent: Unity Cluster User Portal"
12+
);
13+
14+
$curl = curl_init();
15+
curl_setopt($curl, CURLOPT_URL, $url);
16+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
17+
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
18+
$keys = json_decode(curl_exec($curl), false);
19+
curl_close($curl);
20+
21+
// normally returns array of objects each with a ->key attribute
22+
// if bad URL or no such user, returns status=404 object
23+
// if no keys, returns []
24+
if ((!is_array($keys)) || (count($keys) == 0)) {
25+
return [];
26+
}
27+
// phpcs:disable
28+
return array_map(function($x){return $x->key;}, $keys);
29+
// phpcs:enable
30+
}
31+
}

resources/lib/UnitySite.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,6 @@ public static function removeTrailingWhitespace($arr)
2525
return $out;
2626
}
2727

28-
public static function getGithubKeys($username)
29-
{
30-
$url = "https://api.github.com/users/$username/keys";
31-
$headers = array(
32-
"User-Agent: Unity Cluster User Portal"
33-
);
34-
35-
$curl = curl_init();
36-
curl_setopt($curl, CURLOPT_URL, $url);
37-
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
38-
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
39-
$keys = json_decode(curl_exec($curl), false);
40-
curl_close($curl);
41-
42-
// normally returns array of objects each with a ->key attribute
43-
// if bad URL or no such user, returns status=404 object
44-
// if no keys, returns []
45-
if ((!is_array($keys)) || (count($keys) == 0)) {
46-
return [];
47-
}
48-
// phpcs:disable
49-
return array_map(function($x){return $x->key;}, $keys);
50-
// phpcs:enable
51-
}
52-
5328
public static function testValidSSHKey($key_str)
5429
{
5530
// key loader still throws, these just mute warnings for phpunit

test/functional/SSHKeyAddTest.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use UnityWebPortal\lib\UnityGithub;
5+
use PHPUnit\Framework\Attributes\DataProvider;
6+
use PHPUnit\Framework\MockObject\MockBuilder;
7+
8+
class SSHKeyAddTest extends TestCase
9+
{
10+
private function addSshKeysPaste(array $keys): void {
11+
foreach ($keys as $key) {
12+
post(
13+
__DIR__ . "/../../webroot/panel/account.php",
14+
[
15+
"form_type" => "addKey",
16+
"add_type" => "paste",
17+
"key" => $key
18+
]
19+
);
20+
}
21+
}
22+
23+
private function addSshKeysImport(array $keys): void {
24+
foreach ($keys as $key) {
25+
$tmp = tmpfile();
26+
$tmp_path = stream_get_meta_data($tmp)["uri"];
27+
fwrite($tmp, $key);
28+
$_FILES["keyfile"] = ["tmp_name" => $tmp_path];
29+
try {
30+
post(
31+
__DIR__ . "/../../webroot/panel/account.php",
32+
["form_type" => "addKey", "add_type" => "import"]
33+
);
34+
} finally {
35+
unlink($tmp_path);
36+
unset($_FILES["keyfile"]);
37+
}
38+
}
39+
}
40+
41+
private function addSshKeysGenerate(array $keys): void {
42+
foreach ($keys as $key) {
43+
post(
44+
__DIR__ . "/../../webroot/panel/account.php",
45+
[
46+
"form_type" => "addKey",
47+
"add_type" => "generate",
48+
"gen_key" => $key
49+
]
50+
);
51+
}
52+
}
53+
54+
private function addSshKeysGithub(array $keys): void {
55+
global $GITHUB;
56+
$oldGithub = $GITHUB;
57+
$GITHUB = $this->createMock(UnityGithub::class);
58+
$GITHUB->method("getSshPublicKeys")->willReturn($keys);
59+
try {
60+
post(
61+
__DIR__ . "/../../webroot/panel/account.php",
62+
[
63+
"form_type" => "addKey",
64+
"add_type" => "github",
65+
"gh_user" => "foobar"
66+
]
67+
);
68+
} finally {
69+
$GITHUB = $oldGithub;
70+
}
71+
}
72+
73+
public static function provider() {
74+
$validKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+XqO25MUB9x/pS04I3JQ7rMGboWyGXh0GUzkOrTi7a foobar";
75+
$invalidKey = "foobar";
76+
$methods = [
77+
"addSshKeysPaste",
78+
"addSshKeysImport",
79+
"addSshKeysGenerate",
80+
"addSshKeysGithub"
81+
];
82+
$output = [];
83+
foreach ($methods as $method) {
84+
$output = array_merge($output, [
85+
[$method, 0, []],
86+
[$method, 0, [$invalidKey]],
87+
[$method, 1, [$validKey]],
88+
[$method, 1, [$validKey, $invalidKey]],
89+
[$method, 1, [$validKey, $validKey]],
90+
]);
91+
}
92+
return $output;
93+
}
94+
95+
public function getKeyCount()
96+
{
97+
global $USER;
98+
return count($USER->getSSHKeys(true));
99+
}
100+
101+
#[DataProvider("provider")]
102+
public function testAddSshKeys(string $methodName, int $expectedKeysAdded, array $keys)
103+
{
104+
global $USER;
105+
switchUser(...getUserHasNoSshKeys());
106+
$numKeysBefore = $this->getKeyCount($USER);
107+
$this->assertEquals(0, $numKeysBefore);
108+
try {
109+
call_user_func([SSHKeyAddTest::class, $methodName], $keys);
110+
// $method($keys);
111+
$numKeysAfter = $this->getKeyCount($USER);
112+
$this->assertEquals($expectedKeysAdded, ($numKeysAfter - $numKeysBefore));
113+
} finally {
114+
$USER->setSSHKeys([]);
115+
}
116+
}
117+
}

test/phpunit-bootstrap.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
require_once __DIR__ . "/../resources/lib/UnityConfig.php";
1414
require_once __DIR__ . "/../resources/lib/UnityWebhook.php";
1515
require_once __DIR__ . "/../resources/lib/UnityRedis.php";
16+
require_once __DIR__ . "/../resources/lib/UnityGithub.php";
1617

1718
global $HTTP_HEADER_TEST_INPUTS;
1819
$HTTP_HEADER_TEST_INPUTS = [
@@ -43,7 +44,7 @@
4344

4445
function switchUser(string $eppn, string $given_name, string $sn, string $mail): void
4546
{
46-
global $CONFIG, $REDIS, $LDAP, $SQL, $MAILER, $WEBHOOK, $SITE, $SSO, $OPERATOR, $USER, $SEND_PIMESG_TO_ADMINS, $LOC_HEADER, $LOC_FOOTER;
47+
global $CONFIG, $REDIS, $LDAP, $SQL, $MAILER, $WEBHOOK, $GITHUB, $SITE, $SSO, $OPERATOR, $USER, $SEND_PIMESG_TO_ADMINS, $LOC_HEADER, $LOC_FOOTER;
4748
session_write_close();
4849
session_id(str_replace(["_", "@", "."], "-", $eppn));
4950
// session_start will be called on the first post()
@@ -58,7 +59,7 @@ function switchUser(string $eppn, string $given_name, string $sn, string $mail):
5859

5960
function post(string $phpfile, array $post_data): void
6061
{
61-
global $CONFIG, $REDIS, $LDAP, $SQL, $MAILER, $WEBHOOK, $SITE, $SSO, $OPERATOR, $USER, $SEND_PIMESG_TO_ADMINS, $LOC_HEADER, $LOC_FOOTER;
62+
global $CONFIG, $REDIS, $LDAP, $SQL, $MAILER, $WEBHOOK, $GITHUB, $SITE, $SSO, $OPERATOR, $USER, $SEND_PIMESG_TO_ADMINS, $LOC_HEADER, $LOC_FOOTER;
6263
$_SERVER["REQUEST_METHOD"] = "POST";
6364
$_POST = $post_data;
6465
ob_start();
@@ -89,6 +90,11 @@ function getUserHasNotRequestedAccountDeletionHasNoGroups()
8990
return ["user2@org1.test", "foo", "bar", "user2@org1.test"];
9091
}
9192

93+
function getUserHasNoSshKeys()
94+
{
95+
return ["user3@org1.test", "foo", "bar", "user3@org1.test"];
96+
}
97+
9298
function getUserNotPiNotRequestedBecomePi()
9399
{
94100
return ["user2@org1.test", "foo", "bar", "user2@org1.test"];

test/unit/UnityGithubTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace UnityWebPortal\lib;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use PHPUnit\Framework\Attributes\DataProvider;
7+
8+
class UnityGithubTest extends TestCase
9+
{
10+
public static function providerTestGetGithubKeys()
11+
{
12+
return [
13+
# empty
14+
["", []],
15+
# nonexistent user
16+
["asdfkljhasdflkjashdflkjashdflkasjd", []],
17+
# user with no keys
18+
["sheldor1510", []],
19+
# user with 1 key
20+
//phpcs:disable
21+
["simonLeary42", ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDGRl6JWPj+Gq2Lz9GjYdUl4/unLoFOyfgeiII1CxutpabPByRJbeuonR0zTpn51tZeYuAUOJBOeKt+Lj4i4UDGl6igpdXXSwkBXl7jxfRPwJ6WuTkDx7Z8ynwnqlDV2q089q4OX/b/uuHgsIhIBwrouKsRQaZIqTbwNMfiqQ2zl14V0KMrTPzOiwR6Q+hqSaR5Z29WKE7ff/OWzSC3/0T6avCmcCbQaRPJdVM+QC17B0vl8FzPwRjorMngwZ0cImdQ/0Ww1d12YAL7UWp1c2egfnthKP3MuQZnNF8ixsAk1eIIwTRdiI87BOoorW8NXhxXmhyheRCsFwyP4LJBqyUVoZJ0UYyk0AO4G9EStnfpiz8YXGK+M1G4tUrWgzs1cdjlHtgCWUmITtgabnYCC4141m7n4GZTk2H/lSrJcvAs3JEiwLTj1lzeGgzeSsz/XKsnOJyzjEVr2Jp3iT+J9PbQpfS0SxTCIGgxMqllovv79pfsF/zc+vaxqSShyHW7oyn7hLMHM60LO/IIX1RWGL3rD9ecXx2pXXQ1RhIkVteIi13XkFt+KW00cstFlAd3EHCoY/XorShd2jeID7tpnYlmNfotYUs6IKefvpNC0PWkh5UXFEv3SUfw4Wd8O0DiHfhkrhxn1W/GajqSIlZ5DKgPzFg8EHexv8lSa7WJg0H3YQ=="]]
22+
//phpcs:enable
23+
];
24+
}
25+
26+
#[DataProvider("providerTestGetGithubKeys")]
27+
public function testGetGithubKeys(string $username, array $expected)
28+
{
29+
$GITHUB = new UnityGithub();
30+
$this->assertEquals($expected, $GITHUB->getSshPublicKeys($username));
31+
}
32+
}

test/unit/UnitySiteTest.php

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,67 @@ class UnitySiteTest extends TestCase
99
{
1010
public static function SSHKeyProvider()
1111
{
12-
return [
13-
[false, ""],
14-
[false, "foobar"],
15-
[false, "1"],
16-
[false, '{"key": "value"}'],
17-
[true, "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+XqO25MUB9x/pS04I3JQ7rMGboWyGXh0GUzkOrTi7a"],
18-
[false, " ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+XqO25MUB9x/pS04I3JQ7rMGboWyGXh0GUzkOrTi7a "],
19-
//phpcs:disable
20-
[true, "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJNqo8NKTfXgCsaE3ly0tDCfwFuFgJiftup0bIZnRi5bP5Qg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5djQYRit2druxBtw6Y+ylIg9CZJMTf1IBjveBUySF+gOonShB1nLmRZ9zX2hwJSXqYbGQCqzfwRWwPYSnQak0skh4J1p7OYFgZCuxkiSaEikpbuHJWAz1cpYsomXQ7l/m+F05JFfAm2LvNjVoeAblw+Tj7T/Fx7x63b1CU4Wy3L7Ho25i89fksFhsV/fBk9c3QqSkwpkiDVnvYeIhM349An75ncfBjToQT5o5Ayn0ritOUHh5NW+SS+955CFFM8ZQhxZaluWKcrvjwN/UCtBWjGTu7JpwOnHuTTj03ti2wcYsEKNpPB/Nm3kql+UbARmsq24j5foxjN6gmiKVtuho7SDMsu11UGgidKCiHAM3/o4Im53awfRJiqoouJNTisSuhxHp7b+4Z14+CUPfQcKkyYCSzrptrJhg2FO5vz1YZOuExIm3deDfcPsK5vg4LiLam6FJ3qqonXP6krCuH/crJYLTPBJn6eX3noL7TjCqiMWEtLmGj0431YbcrgG7Fy2a+VWwcB6w0nzyxbqg16AP+luuqHxfVsvP6Uyde4C7LPeB3r3GhAfuUNxnpz/bXGxbJu3+aCnbtaZMzGJ6UFBeJp8MtlmVajDnjx3oEuOGGmobTlaopHYVsQ3ySfQ=="],
22-
//phpcs:enable
12+
global $HTTP_HEADER_TEST_INPUTS;
13+
$validKeys = [
14+
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+XqO25MUB9x/pS04I3JQ7rMGboWyGXh0GUzkOrTi7a",
15+
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+XqO25MUB9x/pS04I3JQ7rMGboWyGXh0GUzkOrTi7a foobar",
16+
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBF/dSI9/7YWeyB8wa4rEWRdeb9pQbrGxZwYFV2ulr0agXdbiJIApp0MWDYlIc9XI+4Y+cVAj66PQ2YaRz44BV+o=",
17+
"ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAA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ayn0ritOUHh5NW+SS+955CFFM8ZQhxZaluWKc",
61+
"rvjwN/UCtBWjGTu7JpwOnHuTTj03ti2wcYsEKNpPB/Nm3kql+UbARmsq24j5",
62+
"foxjN6gmiKVtuho7SDMsu11UGgidKCiHAM3/o4Im53awfRJiqoouJNTisSuh",
63+
"xHp7b+4Z14+CUPfQcKkyYCSzrptrJhg2FO5vz1YZOuExIm3deDfcPsK5vg4L",
64+
"iLam6FJ3qqonXP6krCuH/crJYLTPBJn6eX3noL7TjCqiMWEtLmGj0431Ybcr",
65+
"gG7Fy2a+VWwcB6w0nzyxbqg16AP+luuqHxfVsvP6Uyde4C7LPeB3r3GhAfuU",
66+
"Nxnpz/bXGxbJu3+aCnbtaZMzGJ6UFBeJp8MtlmVajDnjx3oEuOGGmobTlaop",
67+
"HYVsQ3ySfQ==",
68+
])
2369
];
70+
$validKeysArgs = array_map(function($x){return [true, $x];}, $validKeys);
71+
$invalidKeysArgs = array_map(function($x){return [false, $x];}, $HTTP_HEADER_TEST_INPUTS);
72+
return $validKeysArgs + $invalidKeysArgs;
2473
}
2574

2675
#[DataProvider("SSHKeyProvider")]
@@ -30,26 +79,4 @@ public function testTestValidSSHKey(bool $expected, string $key)
3079
$this->assertEquals($expected, $SITE->testValidSSHKey($key));
3180
}
3281

33-
public static function providerTestGetGithubKeys()
34-
{
35-
return [
36-
# empty
37-
["", []],
38-
# nonexistent user
39-
["asdfkljhasdflkjashdflkjashdflkasjd", []],
40-
# user with no keys
41-
["sheldor1510", []],
42-
# user with 1 key
43-
//phpcs:disable
44-
["simonLeary42", ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDGRl6JWPj+Gq2Lz9GjYdUl4/unLoFOyfgeiII1CxutpabPByRJbeuonR0zTpn51tZeYuAUOJBOeKt+Lj4i4UDGl6igpdXXSwkBXl7jxfRPwJ6WuTkDx7Z8ynwnqlDV2q089q4OX/b/uuHgsIhIBwrouKsRQaZIqTbwNMfiqQ2zl14V0KMrTPzOiwR6Q+hqSaR5Z29WKE7ff/OWzSC3/0T6avCmcCbQaRPJdVM+QC17B0vl8FzPwRjorMngwZ0cImdQ/0Ww1d12YAL7UWp1c2egfnthKP3MuQZnNF8ixsAk1eIIwTRdiI87BOoorW8NXhxXmhyheRCsFwyP4LJBqyUVoZJ0UYyk0AO4G9EStnfpiz8YXGK+M1G4tUrWgzs1cdjlHtgCWUmITtgabnYCC4141m7n4GZTk2H/lSrJcvAs3JEiwLTj1lzeGgzeSsz/XKsnOJyzjEVr2Jp3iT+J9PbQpfS0SxTCIGgxMqllovv79pfsF/zc+vaxqSShyHW7oyn7hLMHM60LO/IIX1RWGL3rD9ecXx2pXXQ1RhIkVteIi13XkFt+KW00cstFlAd3EHCoY/XorShd2jeID7tpnYlmNfotYUs6IKefvpNC0PWkh5UXFEv3SUfw4Wd8O0DiHfhkrhxn1W/GajqSIlZ5DKgPzFg8EHexv8lSa7WJg0H3YQ=="]]
45-
//phpcs:enable
46-
];
47-
}
48-
49-
#[DataProvider("providerTestGetGithubKeys")]
50-
public function testGetGithubKeys(string $username, array $expected)
51-
{
52-
$SITE = new UnitySite();
53-
$this->assertEquals($expected, $SITE->getGithubKeys($username));
54-
}
5582
}

0 commit comments

Comments
 (0)