check.php: test domain transfers
This commit is contained in:
parent
edcad22a84
commit
d8b4ee90bb
2 changed files with 47 additions and 10 deletions
2
init.php
2
init.php
|
@ -5,7 +5,7 @@ set_error_handler(function ($level, $message, $file = '', $line = 0) {
|
|||
throw new ErrorException($message, 0, $level, $file, $line);
|
||||
});
|
||||
set_exception_handler(function ($e) {
|
||||
error_log($e->getMessage());
|
||||
error_log((string) $e);
|
||||
http_response_code(500);
|
||||
echo '<h1>Error</h1>An error occured.';
|
||||
});
|
||||
|
|
|
@ -47,7 +47,7 @@ function curlTest(string $address, array $post = [], bool $tor = false): string
|
|||
if ($status_code >= 400 OR $result === false) {
|
||||
var_dump($result);
|
||||
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;
|
||||
}
|
||||
|
@ -60,13 +60,6 @@ curlTest('/auth/register', [
|
|||
'password' => $password,
|
||||
]);
|
||||
|
||||
curlTest('/auth/logout', []);
|
||||
|
||||
curlTest('/auth/login', [
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
$new_password = bin2hex(random_bytes(16));
|
||||
curlTest('/auth/password', [
|
||||
'current-password' => $password,
|
||||
|
@ -74,9 +67,20 @@ curlTest('/auth/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', [
|
||||
'current-password' => $password,
|
||||
'new-username' => $username . '2',
|
||||
'new-username' => $username . '3',
|
||||
]);
|
||||
curlTest('/auth/username', [
|
||||
'current-password' => $password,
|
||||
|
@ -86,6 +90,8 @@ curlTest('/auth/username', [
|
|||
echo 'Created account with username "' . $username . '" and password "' . $password . '".' . LF;
|
||||
|
||||
function testReg(): string {
|
||||
global $username, $password;
|
||||
|
||||
$subdomain = bin2hex(random_bytes(16));
|
||||
|
||||
curlTest('/reg/register', [
|
||||
|
@ -116,6 +122,37 @@ function testReg(): string {
|
|||
'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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue