check.php: test domain transfers

This commit is contained in:
Miraty 2023-06-20 02:32:36 +02:00
parent edcad22a84
commit d8b4ee90bb
2 changed files with 47 additions and 10 deletions

View file

@ -5,7 +5,7 @@ set_error_handler(function ($level, $message, $file = '', $line = 0) {
throw new ErrorException($message, 0, $level, $file, $line); throw new ErrorException($message, 0, $level, $file, $line);
}); });
set_exception_handler(function ($e) { set_exception_handler(function ($e) {
error_log($e->getMessage()); error_log((string) $e);
http_response_code(500); http_response_code(500);
echo '<h1>Error</h1>An error occured.'; echo '<h1>Error</h1>An error occured.';
}); });

View file

@ -47,7 +47,7 @@ function curlTest(string $address, array $post = [], bool $tor = false): string
if ($status_code >= 400 OR $result === false) { if ($status_code >= 400 OR $result === false) {
var_dump($result); var_dump($result);
var_dump(curl_error($req)); var_dump(curl_error($req));
exit($address . ' test failed with status code ' . $status_code . LF); throw new Exception($address . ' test failed with status code ' . $status_code);
} }
return $result; return $result;
} }
@ -60,13 +60,6 @@ curlTest('/auth/register', [
'password' => $password, 'password' => $password,
]); ]);
curlTest('/auth/logout', []);
curlTest('/auth/login', [
'username' => $username,
'password' => $password,
]);
$new_password = bin2hex(random_bytes(16)); $new_password = bin2hex(random_bytes(16));
curlTest('/auth/password', [ curlTest('/auth/password', [
'current-password' => $password, 'current-password' => $password,
@ -74,9 +67,20 @@ curlTest('/auth/password', [
]); ]);
$password = $new_password; $password = $new_password;
curlTest('/auth/register', [
'username' => $username . '2',
'password' => $password,
]);
curlTest('/auth/logout', []);
curlTest('/auth/login', [
'username' => $username,
'password' => $password,
]);
curlTest('/auth/username', [ curlTest('/auth/username', [
'current-password' => $password, 'current-password' => $password,
'new-username' => $username . '2', 'new-username' => $username . '3',
]); ]);
curlTest('/auth/username', [ curlTest('/auth/username', [
'current-password' => $password, 'current-password' => $password,
@ -86,6 +90,8 @@ curlTest('/auth/username', [
echo 'Created account with username "' . $username . '" and password "' . $password . '".' . LF; echo 'Created account with username "' . $username . '" and password "' . $password . '".' . LF;
function testReg(): string { function testReg(): string {
global $username, $password;
$subdomain = bin2hex(random_bytes(16)); $subdomain = bin2hex(random_bytes(16));
curlTest('/reg/register', [ curlTest('/reg/register', [
@ -116,6 +122,37 @@ function testReg(): string {
'ns' => 'ns1.servnest.invalid.', 'ns' => 'ns1.servnest.invalid.',
]); ]);
{ // Domain transfer
curlTest('/auth/logout', []);
curlTest('/auth/login', [
'username' => $username . '2',
'password' => $password,
]);
preg_match('#\<code\>(?<token>[0-9a-z-]{16,128}\._transfer-verification\.' . preg_quote(CORE_DOMAIN, '#') . '\.)\</code\>#', curlTest('/reg/transfer', []), $matches);
curlTest('/auth/logout', []);
curlTest('/auth/login', [
'username' => $username,
'password' => $password,
]);
curlTest('/reg/ns', [
'action' => 'add',
'domain' => $domain,
'ns' => $matches['token'],
]);
curlTest('/auth/logout', []);
curlTest('/auth/login', [
'username' => $username . '2',
'password' => $password,
]);
curlTest('/reg/transfer', [
'subdomain' => $subdomain,
'suffix' => SUFFIX,
'ns' => $matches['token'],
]);
}
return $domain; return $domain;
} }