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 / repo.php (3bc94991a725b75ad24b040d9ee58441cd3c2231) (3,380B) (mode 100644) [raw]
<?php
error_reporting(E_ALL | E_STRICT);

$INC = "../inc";
require_once($INC . "/repo.inc.php");
require_once($INC . "/db/struct.inc.php");

rg_log_set_file("repo.log");

$rg_sql_debug = 1;

// defaults
$rg_repo_max_len = 100;
$rg_base_repo = "/u";


rg_log("name2base1");
$e = "/u/a/a/";
$c = rg_repo_name2base("aa");
if (strcmp($c, $e) != 0) {
	echo "name2base1 is not working correctly: c=$c e=$e.\n";
	exit(1);
}

rg_log("name2base2");
$e = "/u/a/_/";
$c = rg_repo_name2base("a");
if (strcmp($c, $e) != 0) {
	echo "name2base2 is not working correctly: c=$c e=$e.\n";
	exit(1);
}

rg_log("test if repo_allow works correctly (0)");
$rg_repo_allow = '/^[A-Za-z0-9]*$/';
$v = "xx";
$c = rg_repo_ok($v);
if ($c !== TRUE) {
	echo "repo_allow problem for valid repo [$v] (c=$c).\n";
	exit(1);
}

rg_log("test if repo_allow works correctly (1)");
$rg_repo_allow = '/^[A-Za-z0-9]*$/';
$v = "eyhtmcmet_";
$c = rg_repo_ok($v);
if ($c !== FALSE) {
	echo "repo_allow problem for '_' in [$v] (c=$c).\n";
	exit(1);
}

rg_log("test if repo_allow works correctly (2)");
$rg_repo_allow = '/^[A-Za-z0-9_.-]*$/';
$v = ".e&y.h-tmcmet&_.-";
$c = rg_repo_ok($v);
if ($c !== FALSE) {
	echo "repo_allow problem for '&'.\n";
	exit(1);
}

rg_log("check if we allow '..'");
$rg_repo_allow = '/^[A-Za-z0-9_.-]*$/';
$v = "a..b";
$c = rg_repo_ok($v);
if ($c !== FALSE) {
	echo "repo_allow problem for '..'.\n";
	exit(1);
}

rg_log("check len test");
$v = "0123456789A";
$rg_repo_allow = '/^[A-Za-z0-9]*$/';
$rg_repo_max_len = 10;
$c = rg_repo_ok($v);
if ($c !== FALSE) {
	echo "repo_ok: max length is not enforced!\n";
	exit(1);
}


@unlink("repo.sqlite");

$db = rg_sql_open("sqlite:repo.sqlite");
if ($db === FALSE) {
	echo "Cannot create a database (" . rg_sql_error() . ")!\n";
	exit(1);
}

$r = rg_db_struct_run($db, FALSE);
if ($r === FALSE) {
	echo "Cannot create struct!\n";
	exit(1);
}

$sql = "INSERT INTO repos (repo_id, name, uid, itime"
	. ", disk_quota_mb, max_commit_size"
	. ", master, desc, git_dir_done, default_rights)"
	. " VALUES (1, 'repo1', 1, 0, 0, 0, 0, 'bla bla desc', 1, 'F')";
$res = rg_sql_query($db, $sql);
if ($res === FALSE) {
	echo "Cannot insert a user!\n";
	exit(1);
}

echo "test giving rights\n";
$repo_id = 1;
$ri = rg_repo_info($db, $repo_id, "");
$uid = 10;
$v = rg_repo_rights_set($db, $ri, $uid, "P");
if ($v === FALSE) {
	echo "Cannot give rights (1)!\n";
	exit(1);
}

echo "owner gets all rights.\n";
$uid = 1;
$e = rg_rights_all("repo");
$r = rg_repo_rights_get($db, $ri, $uid, 0);
$c = $r['rights'];
if (strcmp($c, $e) != 0) {
	echo "Owner did not get all rights: c=$c e=$e.\n";
	exit(1);
}

echo "non-owner gets correct rights: F gets from default rights.\n";
$uid = 12;
$r = rg_repo_rights_set($db, $ri, $uid, "P");
if ($r !== TRUE) {
	echo "Cannot set rights (" . rg_repo_error() . ")!\n";
	exit(1);
}
$e = "FP";
$r = rg_repo_rights_get($db, $ri, $uid, 0);
$c = $r['rights'];
if (strcmp($c, $e) != 0) {
	echo "Non-owner did not get correct rights: c=$c e=$e.\n";
	exit(1);
}

echo "owner can set separate rights for him\n";
$uid = 1;
$v = rg_repo_rights_set($db, $ri, $uid, "A");
if ($v === FALSE) {
	echo "Owner cannot set separate rights for him!\n";
	exit(1);
}

rg_log("list1");
$r = rg_repo_rights_list($db, $ri, "/prj1");
if ($r === FALSE) {
	echo "Cannot list rights (" . rg_repo_error() . ")\n";
	exit(1);
}

@unlink("repo.sqlite");

echo "OK\n";
?>
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