xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / tests / http_admin.php (f6b57d91a0c2597fd5d9008c15a4ac6b309d330b) (2,272B) (mode 100644) [raw]
<?php
error_reporting(E_ALL | E_STRICT);
ini_set("track_errors", "On");

$test_normal = TRUE;

$INC = dirname(__FILE__) . "/../inc";
require_once(dirname(__FILE__) . "/config.php");
require_once($INC . "/init.inc.php");
require_once($INC . "/util.inc.php");
require_once("helpers.inc.php");
require_once("http.inc.php");

rg_log_set_file("http_admin.log");

require_once("common.php");

$_testns = 'http_admin';


$rg_user_max_len = 60;

prepare_http();

$rg_ui = array('is_admin' => 1);
rg_test_create_user($db, $rg_ui);

// First we need to load the form so we can get the token
// We provide an old cookie to test if we generate a new pre-login one
$r = do_req($test_url . "/op/login", $data, $headers);
if ($r === FALSE) {
	rg_log("Cannot load login form.");
	exit(1);
}
if (!isset($r['tokens']['login'])) {
	rg_log_ml('R: ' . print_r($r, TRUE));
	rg_log('Cannot find login token!');
	exit(1);
}
$good_token = $r['tokens']['login'];


rg_log("Do the login (token=$good_token)...");
$data = array(
	"doit" => 1,
	"token" => $good_token,
	"user" => $rg_ui['username'],
	"pass" => $rg_ui['pass'],
	"lock_ip" => 0);
$headers = array();
$r = do_req($test_url . "/op/login", $data, $headers);
if ($r === FALSE) {
	rg_log_ml("Cannot login: " . print_r($r, TRUE));
	exit(1);
}
if (strstr($r['body'], "invalid user")) {
	rg_log_ml("Login invalid. r=" . print_r($r, TRUE));
	exit(1);
}

rg_log("Loading invites form...");
$url = "/op/admin/mails/invites";
$data = array();
$r = do_req($test_url . $url, $data, $headers);
if ($r === FALSE) {
	rg_log("Cannot load add bug form.");
	exit(1);
}
if (!isset($r['tokens']['admin_invites_hl'])) {
	rg_log("No admin_invites_hl token!");
	exit(1);
}
$token = $r['tokens']['admin_invites_hl'];

rg_log("Posting invites form (token=$token)...");
$data = array('doit' => 1, 'token' => $token,
	'inv::list' => "a@embedromix.ro|a\nb@embedromix.ro|b b2 b3<xss>\n",
	'inv::subject' => 'Invite 1 - hello {NAME}<xss>',
	'inv::body' => "Hello {NAME}!\n\nYou are invited, {NAME}!<xss>");
$r = do_req($test_url . $url, $data, $headers);
if ($r === FALSE) {
	rg_log("Cannot post bug request.");
	exit(1);
}
// test invites here
/*
if ($row['state'] != 1) {
	rg_log("State is not 1 but " . $row['state']);
	exit(1);
}
*/

rg_prof_log();
rg_log("OK!");
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master