gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit57af42bb57af42bbREADME: point to deploy.sh for the port listmre57af42bb/tests/realdata-baseline.mjs

25.3 KB

  1. import { requiredPort } from './gate-ports.mjs';
  2. // tests/realdata-baseline.mjs (gitoria mission 002, code order): every read the app answers + a fixed write sequence, on a
  3. // COPY of the LIVE storage, saved for diffing two code trees (a cleanup must answer the same). Compare two outputs with
  4. // tests/realdata-compare.py. README "Test" → "Same output".
  5. // node tests/realdata-baseline.mjs <tree> <unused> <outdir> (GITORIA_REALDATA_PORT required) (kills only the server and the sshd container it started)
  6. // The live copy: GITORIA_REALDATA (default .scratch/realdata) must hold storage/mpackdb + storage/git, e.g. from Byrodin:
  7. // tar -C /CONTAINERS/projects/gitoria.worldapi.org -cf - storage/mpackdb storage/git | ssh loreana tar -C <repo>/.scratch/realdata -xf -
  8. // Each run works on a fresh copy of it (<outdir>.run, removed after). Signed in as the creator (identity az5b2 → users @id
  9. // 0mugibaf6fds) through a session file written before the start; every page is fetched signed in AND signed out.
  10. // Ports: <port> = the app, <port>+8 = the sshd container (docker, image built from docker/sshd, name gitoria-sshd-rd<port>).
  11. // Git commits are made with fixed dates (client and server: GIT_AUTHOR_DATE / GIT_COMMITTER_DATE), so their ids match
  12. // between runs; the ssh keys are made once in <GITORIA_REALDATA>/keys and reused (same fingerprints).
  13. // Tickets: the connected repo's tickets API is a SNAPSHOT of the live answer (<GITORIA_REALDATA>/tickets-snapshot.json,
  14. // fetched once), served on <port>+9; the copy's stored `tktApi` is rewritten to it (same length, the msgpack stays valid).
  15. // So nothing reaches the live tickets, and a change on live tickets between two runs does not show up as a difference.
  16. import { spawn, spawnSync, execSync, execFileSync } from 'node:child_process';
  17. import { request, createServer } from 'node:http';
  18. import { writeFileSync, mkdirSync, rmSync, existsSync, readFileSync } from 'node:fs';
  19. import { createHash, randomBytes } from 'node:crypto';
  20. import { join, resolve } from 'node:path';
  21. const [tree, portArg, outArg] = process.argv.slice(2);
  22. const PORT = requiredPort('GITORIA_REALDATA_PORT'), SSHPORT = PORT + 8;
  23. const W = resolve(process.env.GITORIA_REALDATA || '.scratch/realdata'), OUT = resolve(outArg), RUN = OUT + '.run';
  24. const USER = '0mugibaf6fds', SECRET = 'rd-secret-fixed', CONTAINER = 'gitoria-sshd-rd' + PORT;
  25. rmSync(RUN, { recursive: true, force: true }); rmSync(OUT, { recursive: true, force: true });
  26. mkdirSync(join(RUN, 'sessions'), { recursive: true }); mkdirSync(join(RUN, 'home'), { recursive: true }); mkdirSync(OUT, { recursive: true });
  27. execSync(`cp -a ${W}/storage ${RUN}/storage`);
  28. const GIT = join(RUN, 'storage/git');
  29. const LIVE_TICKETS = 'https://tickets.worldapi.org', FAKE_TICKETS = `http://127.0.0.1:${PORT + 9}/fake00`; // the same length
  30. if (LIVE_TICKETS.length !== FAKE_TICKETS.length) throw new Error('fake tickets URL must have the length of the live one');
  31. const reposFile = join(RUN, 'storage/mpackdb/repos.mpack');
  32. const rb = readFileSync(reposFile, 'latin1');
  33. writeFileSync(reposFile, rb.split(LIVE_TICKETS + '/api/projects/').join(FAKE_TICKETS + '/api/projects/'), 'latin1');
  34. const SNAP = join(W, 'tickets-snapshot.json');
  35. if (!existsSync(SNAP)) writeFileSync(SNAP, await (await fetch(LIVE_TICKETS + '/api/projects/gitoria.worldapi.org/tickets')).text());
  36. const fake = createServer((req, res) => {
  37. if (req.method === 'GET' && req.url === '/fake00/api/projects/gitoria.worldapi.org/tickets') { res.writeHead(200, { 'content-type': 'application/json' }); res.end(readFileSync(SNAP)); return; }
  38. res.writeHead(404, { 'content-type': 'application/json' }); res.end('{"error":"fake tickets: not here"}');
  39. });
  40. fake.listen(PORT + 9, '127.0.0.1');
  41. // ---- the keys (once) ---------------------------------------------------------------------------------------------
  42. const KEYS = join(W, 'keys');
  43. if (!existsSync(join(KEYS, 'ed'))) {
  44. mkdirSync(KEYS, { recursive: true });
  45. spawnSync('ssh-keygen', ['-q', '-t', 'ed25519', '-N', '', '-C', 'rd@w082', '-f', join(KEYS, 'ed')]);
  46. spawnSync('ssh-keygen', ['-q', '-t', 'rsa', '-b', '1024', '-N', '', '-C', 'small@w082', '-f', join(KEYS, 'rsa1024')]);
  47. }
  48. const edPub = readFileSync(join(KEYS, 'ed.pub'), 'utf8').trim(), rsaSmall = readFileSync(join(KEYS, 'rsa1024.pub'), 'utf8').trim();
  49. // ---- the session -------------------------------------------------------------------------------------------------
  50. const sid = randomBytes(16).toString('hex'), now = Date.now();
  51. writeFileSync(join(RUN, 'sessions', createHash('sha256').update(sid).digest('hex')),
  52. JSON.stringify({ created: now, data: { tag: 'w082tag' }, handled: [], id: sid, seen: now, user: { id: USER } }), { mode: 0o600 });
  53. const COOKIE = 'gitoriasid=' + sid;
  54. // a second, signed-out session (for the failed-login note)
  55. const sid2 = randomBytes(16).toString('hex');
  56. writeFileSync(join(RUN, 'sessions', createHash('sha256').update(sid2).digest('hex')),
  57. JSON.stringify({ created: now, data: { tag: 'w082tag2' }, handled: [], id: sid2, seen: now, user: null }), { mode: 0o600 });
  58. const sleep = ms => new Promise(r => setTimeout(r, ms));
  59. const MAIN = `gitoria.test:${PORT}`, HOST = (slug) => `${slug}.gitoria.test:${PORT}`;
  60. const DATES = { GIT_AUTHOR_DATE: '2026-10-03T12:00:00+0200', GIT_COMMITTER_DATE: '2026-10-03T12:00:00+0200' };
  61. const srv = spawn(resolve(tree, 'bin/hybriel'), ['project.hl'], { cwd: resolve(tree), stdio: ['ignore', 'pipe', 'pipe'],
  62. env: { ...process.env, ...DATES, GITORIA_PORT: String(PORT), GITORIA_PUBLIC_URL: `http://${MAIN}`, GITORIA_STORAGE: join(RUN, 'storage/mpackdb'),
  63. GITORIA_GIT: GIT, GITORIA_SESSIONS: join(RUN, 'sessions') + '/', GITORIA_WATCH: '0', IDENT_URL: 'http://127.0.0.1:9', IDENT_EXCHANGE_URL: 'http://127.0.0.1:9',
  64. IDENT_API_KEY: 'pk_w082', IDENT_API_SECRET: '', GITORIA_SSH_SECRET: SECRET, GITORIA_SSH_PORT: String(SSHPORT), GITORIA_TICKETS_URL: 'https://tickets.worldapi.org' } });
  65. let log = ''; srv.stdout.on('data', d => log += d); srv.stderr.on('data', d => log += d);
  66. const hreq = (method, host, path, headers = {}, body = null) => new Promise((res) => {
  67. const rq = request({ host: '127.0.0.1', port: PORT, path, method, headers: { host, ...headers } }, (r) => {
  68. const parts = []; r.on('data', d => parts.push(d)); r.on('end', () => res({ status: r.statusCode, headers: r.headers, body: Buffer.concat(parts).toString('utf8') }));
  69. });
  70. rq.on('error', (e) => res({ status: 0, headers: {}, body: 'ERROR ' + e.message }));
  71. if (body != null) { rq.setHeader('content-length', Buffer.byteLength(body)); rq.write(body); }
  72. rq.end();
  73. });
  74. let n = 0;
  75. const file = (name, text) => writeFileSync(join(OUT, String(++n).padStart(4, '0') + '-' + name.replace(/[^a-zA-Z0-9._-]+/g, '_').slice(0, 120)), text);
  76. const save = async (name, method, host, path, headers = {}, body = null) => {
  77. const r = await hreq(method, host, path, headers, body);
  78. const head = [r.status, r.headers['content-type'] || '', r.headers['location'] || '', r.headers['www-authenticate'] || '', r.headers['cache-control'] || '', r.headers['set-cookie'] ? 'set-cookie' : ''].join(' | ');
  79. file(name, head + '\n' + r.body);
  80. return r;
  81. };
  82. let ei = 0;
  83. const emitF = async (name, event, payload, cookie = COOKIE) => {
  84. const r = await hreq('POST', MAIN, '/__hl/emit', { 'content-type': 'application/json', cookie }, JSON.stringify({ t: 'emit', i: ++ei, event, payload }));
  85. file('w-face-' + name, r.status + '\n' + r.body);
  86. try { return JSON.parse(r.body).value; } catch { return null; }
  87. };
  88. const gitIn = (dir, args) => execFileSync('git', args.split(' '), { cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
  89. const GENV = { ...process.env, ...DATES, HOME: join(RUN, 'home'), GIT_CONFIG_NOSYSTEM: '1', GIT_TERMINAL_PROMPT: '0', LC_ALL: 'C' };
  90. const sshCmd = `ssh -i ${join(KEYS, 'ed')} -p ${SSHPORT} -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -o LogLevel=ERROR`;
  91. // the real git client; `slug` maps <slug>.gitoria.test to 127.0.0.1 for http
  92. const git = (cwd, args, slug = null, extra = {}) => new Promise((res) => {
  93. const pre = slug ? ['-c', `http.curloptResolve=${slug}.gitoria.test:${PORT}:127.0.0.1`] : [];
  94. const c = spawn('git', [...pre, '-c', 'user.name=W082', '-c', '[email protected]', '-c', 'init.defaultBranch=main', ...args], { cwd, env: { ...GENV, ...extra } });
  95. let out = ''; c.stdout.on('data', d => out += d); c.stderr.on('data', d => out += d);
  96. const t = setTimeout(() => c.kill('SIGKILL'), 180000);
  97. c.on('close', (code) => { clearTimeout(t); res({ code, out }); });
  98. });
  99. // what a git run says, without what differs between runs (temp paths, transfer speeds)
  100. const gitText = (r) => 'exit ' + r.code + '\n' + r.out.split(/\r|\n/).filter(l => l.trim() && !/Receiving objects|Resolving deltas|Counting objects|Compressing objects|Writing objects|Total \d|remote: (Enumerating|Counting|Compressing|Total)/.test(l)).map(l => l.split(RUN).join('<RUN>')).join('\n');
  101. try {
  102. for (let i = 0; i < 240; i++) { if ((await hreq('GET', MAIN, '/api/repos')).status === 200) break; await sleep(500); }
  103. const repos = JSON.parse((await save('api-repos', 'GET', MAIN, '/api/repos')).body).repos;
  104. // ---- READS ------------------------------------------------------------------------------------------------------
  105. const pages = [[MAIN, '/'], [MAIN, '/login/failed'], [MAIN, '/code'], [MAIN, '/pulls'], [MAIN, '/settings'], [MAIN, '/nope'],
  106. [HOST('nosuchrepo'), '/'], [HOST('nosuchrepo'), '/code'], [HOST('nosuchrepo'), '/pulls'], [HOST('x--y'), '/']];
  107. const apis = ['/api/repos', '/api/repos/nosuch', '/api/repos/x--y'];
  108. const advert = [];
  109. for (const r of repos) {
  110. const s = r.slug, H = HOST(s), dir = join(GIT, s + '.git');
  111. apis.push('/api/repos/' + s);
  112. for (const p of ['/', '/code', '/pulls', '/releases', '/tickets', '/settings', '/code/nosuch.txt', '/branch/nosuch', '/branch', '/commit/zzzz', '/commit/deadbeef', '/commit']) pages.push([H, p]);
  113. const branches = gitIn(dir, 'for-each-ref --format=%(refname:short) refs/heads').split('\n').filter(Boolean).slice(0, 6);
  114. for (const b of branches) pages.push([H, '/branch/' + encodeURIComponent(b).replaceAll('%2F', '/')]);
  115. if (branches.length) {
  116. const b0 = branches.includes(r.branch) ? r.branch : branches.includes('main') ? 'main' : branches[0];
  117. const all = gitIn(dir, `ls-tree -r --name-only ${b0}`).split('\n').filter(Boolean);
  118. const enc = (p) => p.split('/').map(encodeURIComponent).join('/');
  119. const pick = [all[0], all.find(p => /readme\.md$/i.test(p)), all.find(p => p.includes('/')), all.find(p => p.split('/').length > 2), all[all.length - 1], all.find(p => /\.(png|ico|jpg|gz|zip)$/i.test(p))].filter(Boolean);
  120. for (const p of [...new Set(pick)]) pages.push([H, '/code/' + enc(p)]);
  121. const dirs = [...new Set(all.filter(p => p.includes('/')).map(p => p.split('/')[0]))].slice(0, 2);
  122. for (const d of dirs) pages.push([H, '/code/' + enc(d)]);
  123. const sha = gitIn(dir, `rev-parse ${b0}`);
  124. pages.push([H, '/commit/' + sha], [H, '/commit/' + sha.slice(0, 8)]);
  125. if (dirs[0]) pages.push([H, '/commit/' + sha + '/' + enc(dirs[0])]);
  126. const old = gitIn(dir, `log --format=%H -1 --skip=5 ${b0}`);
  127. if (old) pages.push([H, '/commit/' + old]);
  128. }
  129. advert.push(s);
  130. }
  131. const modules = new Set();
  132. for (const [h, p] of pages) {
  133. const r = await save('in-' + h + p, 'GET', h, p, { cookie: COOKIE }); await save('out-' + h + p, 'GET', h, p);
  134. for (const m of r.body.matchAll(/(\/(?:components|__hl)\/[\w./-]+\.(?:hl|js|css))\?v=[0-9a-f]+/g)) modules.add(m[0]);
  135. }
  136. // the browser half: every component module, the runtime, the client, the stylesheet the pages load
  137. for (const m of [...modules].sort()) await save('module-' + m.replace(/\?v=.*/, ''), 'GET', MAIN, m);
  138. for (const u of apis) { await save('json' + u, 'GET', MAIN, u); await save('md' + u, 'GET', MAIN, u, { accept: 'text/markdown' }); }
  139. await save('api-post', 'POST', MAIN, '/api/repos', { 'content-type': 'application/json' }, '{}');
  140. await save('api-post-one', 'POST', MAIN, '/api/repos/tracker', { 'content-type': 'application/json' }, '{}');
  141. // the git protocol: the refs advertisement of every repo, and the refusals
  142. for (const s of advert) {
  143. await save('refs-upload-' + s, 'GET', HOST(s), `/${s}.git/info/refs?service=git-upload-pack`);
  144. await save('refs-upload-v2-' + s, 'GET', HOST(s), `/${s}.git/info/refs?service=git-upload-pack`, { 'git-protocol': 'version=2' });
  145. }
  146. await save('refs-receive-noauth', 'GET', HOST('email'), '/email.git/info/refs?service=git-receive-pack');
  147. await save('refs-receive-badtoken', 'GET', HOST('email'), '/email.git/info/refs?service=git-receive-pack', { authorization: 'Basic ' + Buffer.from('x:gtr_' + '0'.repeat(40)).toString('base64') });
  148. await save('refs-receive-junk', 'GET', HOST('email'), '/email.git/info/refs?service=git-receive-pack', { authorization: 'Basic !!!' });
  149. await save('refs-dumb', 'GET', HOST('email'), '/email.git/info/refs');
  150. await save('refs-wronghost', 'GET', HOST('tracker'), '/email.git/info/refs?service=git-upload-pack');
  151. await save('refs-main', 'GET', MAIN, '/email.git/info/refs?service=git-upload-pack');
  152. await save('refs-post', 'POST', HOST('email'), '/email.git/info/refs?service=git-upload-pack', {}, 'x');
  153. await save('upload-get', 'GET', HOST('email'), '/email.git/git-upload-pack');
  154. // the internal ssh endpoints
  155. const S = { 'x-gitoria-secret': SECRET };
  156. await save('keys-nosecret', 'GET', MAIN, '/__git/keys?type=ssh-ed25519&key=AAAAC3NzaC1lZDI1NTE5AAAAIx');
  157. await save('keys-wrong', 'GET', MAIN, '/__git/keys?type=ssh-ed25519&key=AAAAC3NzaC1lZDI1NTE5AAAAIx', { 'x-gitoria-secret': 'nope' });
  158. await save('keys-proxied', 'GET', MAIN, '/__git/keys?type=ssh-ed25519&key=AAAAC3NzaC1lZDI1NTE5AAAAIx', { ...S, 'x-forwarded-for': '1.2.3.4' });
  159. await save('keys-unknown', 'GET', MAIN, '/__git/keys?type=ssh-ed25519&key=AAAAC3NzaC1lZDI1NTE5AAAAIx', S);
  160. await save('keys-post', 'POST', MAIN, '/__git/keys', S, 'x');
  161. for (const q of [`user=${USER}&slug=tracker&write=0`, `user=${USER}&slug=tracker&write=1`, 'user=nobody&slug=tracker&write=1', 'user=nobody&slug=tracker&write=0', `user=${USER}&slug=nosuch&write=0`, `user=${USER}&slug=X..&write=0`, 'slug=tracker'])
  162. await save('access-' + q, 'GET', MAIN, '/__git/access?' + q, S);
  163. // the login's and the tickets connection's function routes (ident is down on purpose: port 9)
  164. for (const q of ['', '?ident_code=zz', '?ident_code=abc123', '?ident_code=abc&next=/code']) await save('callback' + q, 'GET', MAIN, '/login/callback' + q);
  165. await save('callback-post', 'POST', MAIN, '/login/callback', {}, 'x');
  166. await save('page-loginfailed-after', 'GET', MAIN, '/login/failed');
  167. // a failed login in a browser that has a session: the reason is parked in THAT session (the route writes it by reference)
  168. const C2 = 'gitoriasid=' + sid2;
  169. await save('callback-cookie', 'GET', MAIN, '/login/callback?ident_code=abc123', { cookie: C2 });
  170. await save('page-loginfailed-cookie', 'GET', MAIN, '/login/failed', { cookie: C2 });
  171. await save('callback-cookie-nocode', 'GET', MAIN, '/login/callback', { cookie: C2 });
  172. await save('page-loginfailed-cookie2', 'GET', MAIN, '/login/failed', { cookie: C2 });
  173. await save('connect-out', 'GET', HOST('gitoria'), '/settings/connect');
  174. await save('connect-main', 'GET', MAIN, '/settings/connect', { cookie: COOKIE });
  175. await save('connect-nosuch', 'GET', HOST('nosuchrepo'), '/settings/connect', { cookie: COOKIE });
  176. await save('connected-out', 'GET', HOST('email'), '/settings/connected?code=x&state=y');
  177. await save('connected-error', 'GET', HOST('email'), '/settings/connected?error=nope+said+tickets', { cookie: COOKIE });
  178. await save('settings-note1', 'GET', HOST('email'), '/settings', { cookie: COOKIE });
  179. await save('connected-nostate', 'GET', HOST('email'), '/settings/connected?code=x&state=y', { cookie: COOKIE });
  180. await save('settings-note2', 'GET', HOST('email'), '/settings', { cookie: COOKIE });
  181. await save('connect-start', 'GET', HOST('email'), '/settings/connect', { cookie: COOKIE });
  182. await save('connected-wrongstate', 'GET', HOST('email'), '/settings/connected?code=x&state=y', { cookie: COOKIE });
  183. await save('settings-note3', 'GET', HOST('email'), '/settings', { cookie: COOKIE });
  184. // ---- WRITES ('w-' files; realdata-compare.py masks the new ids, times and token secrets) ------------------------------
  185. await emitF('saveName-again', 'gitoriaSaveName', ['someone']);
  186. await emitF('create', 'gitoriaCreate', ['w082-new', 'W082 test repo']);
  187. await emitF('create-dup', 'gitoriaCreate', ['w082-new', '']);
  188. await emitF('create-bad', 'gitoriaCreate', ['Bad Slug', '']);
  189. await emitF('create-reserved', 'gitoriaCreate', ['www', '']);
  190. await emitF('create-longdesc', 'gitoriaCreate', ['w082-other', 'x'.repeat(201)]);
  191. await emitF('create-out', 'gitoriaCreate', ['w082-out', ''], 'gitoriasid=none');
  192. const tok = (await emitF('token', 'gitoriaMakeToken', ['w082'])) || {};
  193. await emitF('token-empty', 'gitoriaMakeToken', ['']);
  194. const key = (await emitF('key', 'gitoriaAddKey', ['w082 key', edPub])) || {};
  195. await emitF('key-dup', 'gitoriaAddKey', ['again', edPub]);
  196. await emitF('key-private', 'gitoriaAddKey', ['p', '-----BEGIN OPENSSH PRIVATE KEY-----']);
  197. await emitF('key-small', 'gitoriaAddKey', ['small', rsaSmall]);
  198. await emitF('key-junk', 'gitoriaAddKey', ['junk', 'ssh-ed25519 AAAAnotakeyatallxxxxxxxxx']);
  199. const [kt, kb] = edPub.split(' ');
  200. await save('w-keys-known', 'GET', MAIN, `/__git/keys?type=${kt}&key=${encodeURIComponent(kb)}`, S);
  201. await save('w-access-new', 'GET', MAIN, `/__git/access?user=${USER}&slug=w082-new&write=1`, S);
  202. for (const p of ['/', '/code', '/pulls', '/releases', '/settings']) await save('w-page-empty' + p, 'GET', HOST('w082-new'), p, { cookie: COOKIE });
  203. await save('w-page-main', 'GET', MAIN, '/', { cookie: COOKIE });
  204. // over HTTP: clone the empty repo, commit, push with the token (and refused without / with a wrong one)
  205. const W1 = join(RUN, 'home', 'w1'); mkdirSync(W1);
  206. const urlOf = (slug, pass) => `http://${pass ? 'x:' + pass + '@' : ''}${slug}.gitoria.test:${PORT}/${slug}.git`;
  207. file('w-git-clone-empty', gitText(await git(W1, ['clone', urlOf('w082-new'), 'r'], 'w082-new')));
  208. const R = join(W1, 'r');
  209. writeFileSync(join(R, 'README.md'), '# w082\n\nA test repo. fixes #1\n\n| a | b |\n|---|---|\n| 1 | 2 |\n');
  210. mkdirSync(join(R, 'src')); writeFileSync(join(R, 'src/a.txt'), 'line one\nline two\n');
  211. writeFileSync(join(R, 'src/bin.dat'), Buffer.from([0, 1, 2, 255, 254]));
  212. await git(R, ['add', '-A']); await git(R, ['commit', '-q', '-m', 'first commit #1']);
  213. writeFileSync(join(R, 'src/b.txt'), 'b\n'); await git(R, ['add', '-A']); await git(R, ['commit', '-q', '-m', '|||RL first release']);
  214. file('w-git-push-noauth', gitText(await git(R, ['push', urlOf('w082-new'), 'main'], 'w082-new')));
  215. file('w-git-push-badtoken', gitText(await git(R, ['push', urlOf('w082-new', 'gtr_' + '1'.repeat(40)), 'main'], 'w082-new')));
  216. file('w-git-push', gitText(await git(R, ['push', urlOf('w082-new', tok.token), 'main'], 'w082-new')));
  217. await git(R, ['checkout', '-q', '-b', 'feature']); writeFileSync(join(R, 'src/c.txt'), 'c\n'); await git(R, ['add', '-A']); await git(R, ['commit', '-q', '-m', '|||PR feature work, fixes #2']);
  218. await git(R, ['checkout', '-q', '-b', 'side', 'main']); writeFileSync(join(R, 'src/d.txt'), 'd\n'); await git(R, ['add', '-A']); await git(R, ['commit', '-q', '-m', '|||PR|nosuch] bad target']);
  219. await git(R, ['checkout', '-q', 'main']); writeFileSync(join(R, 'src/b.txt'), 'b2\n'); await git(R, ['add', '-A']); await git(R, ['commit', '-q', '-m', '|||RL|med a minor one']);
  220. file('w-git-push-branches', gitText(await git(R, ['push', urlOf('w082-new', tok.token), 'main', 'feature', 'side'], 'w082-new')));
  221. const prSha = gitIn(R, 'rev-parse feature');
  222. for (const p of ['/', '/code', '/code/src', '/code/src/a.txt', '/code/src/bin.dat', '/pulls', '/releases', '/branch/feature', '/branch/side/src', '/commit/' + prSha])
  223. await save('w-page' + p.replace(prSha, 'PR'), 'GET', HOST('w082-new'), p, { cookie: COOKIE });
  224. await emitF('setBranch', 'gitoriaSetBranch', ['w082-new', 'feature', 'code', '']);
  225. await save('w-page-code-feature', 'GET', HOST('w082-new'), '/code', { cookie: COOKIE });
  226. await emitF('setBranch-back', 'gitoriaSetBranch', ['w082-new', 'main', 'code', 'src']);
  227. await emitF('setBranch-nosuch', 'gitoriaSetBranch', ['w082-new', 'nosuch', 'code', '']);
  228. await emitF('setBranch-badkind', 'gitoriaSetBranch', ['w082-new', 'main', 'x', '']);
  229. await emitF('setBranch-out', 'gitoriaSetBranch', ['w082-new', 'main', 'code', ''], 'gitoriasid=none');
  230. await emitF('merge', 'gitoriaMergePull', ['w082-new', prSha]);
  231. await emitF('merge-again', 'gitoriaMergePull', ['w082-new', prSha]);
  232. await emitF('merge-bad', 'gitoriaMergePull', ['w082-new', 'zz']);
  233. await emitF('merge-target-missing', 'gitoriaMergePull', ['w082-new', gitIn(R, 'rev-parse side')]);
  234. await emitF('openTicket', 'gitoriaOpenTicket', ['w082-new', 'subject', 'text']);
  235. await emitF('openTicket-nosuch', 'gitoriaOpenTicket', ['nosuchrepo', 'subject', 'text']);
  236. await emitF('disconnect', 'gitoriaDisconnectTickets', ['w082-new']);
  237. await emitF('disconnect-out', 'gitoriaDisconnectTickets', ['w082-new'], 'gitoriasid=none');
  238. for (const p of ['/', '/code', '/pulls', '/releases', '/settings']) await save('w-page-after' + p, 'GET', HOST('w082-new'), p, { cookie: COOKIE });
  239. await save('w-api-new', 'GET', MAIN, '/api/repos/w082-new'); await save('w-api-new-md', 'GET', MAIN, '/api/repos/w082-new', { accept: 'text/markdown' });
  240. // a real repo: clone over HTTP, push a branch with the token
  241. file('w-git-clone-tracker', gitText(await git(W1, ['clone', '-q', urlOf('tracker'), 'tracker'], 'tracker')) + '\n' + gitIn(join(W1, 'tracker'), 'log --format=%H -3') + '\n' + gitIn(join(W1, 'tracker'), 'ls-tree -r HEAD').split('\n').length);
  242. file('w-git-clone-email', gitText(await git(W1, ['clone', '-q', urlOf('email'), 'email'], 'email')));
  243. const E = join(W1, 'email');
  244. await git(E, ['checkout', '-q', '-b', 'w082http']); writeFileSync(join(E, 'w082.txt'), 'http\n'); await git(E, ['add', '-A']); await git(E, ['commit', '-q', '-m', 'w082 over http']);
  245. file('w-git-push-email', gitText(await git(E, ['push', urlOf('email', tok.token), 'w082http'], 'email')));
  246. await save('w-page-email-branch', 'GET', HOST('email'), '/branch/w082http', { cookie: COOKIE });
  247. // over SSH: the real sshd container (docker/sshd) on a copy of the repos
  248. spawnSync('docker', ['rm', '-f', CONTAINER]);
  249. const built = spawnSync('docker', ['build', '-q', '-t', 'gitoria-sshd-gate', resolve(tree, 'docker/sshd')], { encoding: 'utf8' });
  250. const started = spawnSync('docker', ['run', '-d', '--rm', '--name', CONTAINER, '--network', 'host', '-e', 'GITORIA_SSH_SECRET=' + SECRET, '-e', 'GITORIA_SSH_PORT=' + SSHPORT, '-e', `GITORIA_URL=http://127.0.0.1:${PORT}`, '-v', GIT + ':/repos', 'gitoria-sshd-gate'], { encoding: 'utf8' });
  251. file('w-ssh-container', `build ${built.status} run ${started.status}`);
  252. for (let i = 0; i < 60; i++) { const r = spawnSync('sh', ['-c', `ssh-keyscan -p ${SSHPORT} 127.0.0.1 2>/dev/null | grep -c ssh-`], { encoding: 'utf8' }); if (Number(r.stdout) > 0) break; await sleep(250); }
  253. const SURL = (slug) => `ssh://[email protected]:${SSHPORT}/${slug}.git`;
  254. const W2 = join(RUN, 'home', 'w2'); mkdirSync(W2);
  255. file('w-ssh-clone-tracker', gitText(await git(W2, ['clone', '-q', SURL('tracker'), 'tracker'], null, { GIT_SSH_COMMAND: sshCmd })) + '\n' + gitIn(join(W2, 'tracker'), 'log --format=%H -3'));
  256. file('w-ssh-clone-email', gitText(await git(W2, ['clone', '-q', SURL('email'), 'email'], null, { GIT_SSH_COMMAND: sshCmd })));
  257. const E2 = join(W2, 'email');
  258. await git(E2, ['checkout', '-q', '-b', 'w082ssh']); writeFileSync(join(E2, 'w082ssh.txt'), 'ssh\n'); await git(E2, ['add', '-A']); await git(E2, ['commit', '-q', '-m', 'w082 over ssh #3']);
  259. file('w-ssh-push-email', gitText(await git(E2, ['push', SURL('email'), 'w082ssh'], null, { GIT_SSH_COMMAND: sshCmd })));
  260. file('w-ssh-push-nosuch', gitText(await git(E2, ['push', SURL('nosuchrepo'), 'w082ssh'], null, { GIT_SSH_COMMAND: sshCmd })));
  261. await save('w-page-email-ssh', 'GET', HOST('email'), '/branch/w082ssh', { cookie: COOKIE });
  262. await save('w-page-email-code', 'GET', HOST('email'), '/code', { cookie: COOKIE });
  263. // removing: the key stops at once, the token too
  264. await emitF('removeKey', 'gitoriaRemoveKey', [key.row ? key.row.id : 'none']);
  265. file('w-ssh-after-remove', gitText(await git(W2, ['clone', '-q', SURL('email'), 'email2'], null, { GIT_SSH_COMMAND: sshCmd })));
  266. await emitF('removeKey-again', 'gitoriaRemoveKey', [key.row ? key.row.id : 'none']);
  267. await emitF('removeToken', 'gitoriaRemoveToken', [tok.row ? tok.row.id : 'none']);
  268. file('w-git-push-removed', gitText(await git(E, ['push', urlOf('email', tok.token), 'w082http'], 'email')));
  269. await emitF('removeToken-again', 'gitoriaRemoveToken', [tok.row ? tok.row.id : 'none']);
  270. await save('w-page-main-after', 'GET', MAIN, '/', { cookie: COOKIE });
  271. await save('w-api-repos', 'GET', MAIN, '/api/repos');
  272. // the login faces (ident down) and the logout
  273. await emitF('login-bad', 'gitoriaLogin', ['zz']);
  274. await emitF('logout', 'gitoriaLogOut', []);
  275. await save('w-page-main-loggedout', 'GET', MAIN, '/', { cookie: COOKIE });
  276. console.log(`${n} responses saved to ${OUT} (${pages.length} pages x2, ${apis.length} api urls x2, + writes)`);
  277. } finally {
  278. fake.close();
  279. spawnSync('docker', ['rm', '-f', CONTAINER]);
  280. srv.kill('SIGTERM'); await sleep(1000); try { process.kill(srv.pid, 'SIGKILL'); } catch {}
  281. }
  282. writeFileSync(join(OUT, '0000-server-log'), log.split('\n').filter(l => !/listening|watch/i.test(l)).join('\n'));
  283. rmSync(RUN, { recursive: true, force: true });

Branches

Latest commits

  • 57af42bbREADME: point to deploy.sh for the port listmre
  • d63375d2README: gate commands with explicit portsmre
  • feeaa701|||PR gates: explicit ports only, deploy.sh passes themmre
  • 6cc1f943Merge branch 'records-1112' into mainGitoria
  • 9448c438|||PR records: LOG, missions and reports since 11-09mre
  • 6dc08a8eMerge branch 'p51-public-pr-reads' into mainGitoria
  • 7b88cfe0Type publicReaderOfRequest parameters (L10)Gitoria
  • 2a4b3dc1|||PR Anonymous reads of public repos' pulls and statusesmre
  • 21b2c141Merge branch 's25-no-session-on-login-error' into mainGitoria
  • 698458e2|||PR No session for cookieless login errors: READMEmre
  • cce7b785|||PR No session for cookieless login errorsmre
  • 678d6303Merge branch 'v59' into mainGitoria
  • 5803cf4f|||PR vendor: Hybriel set-day59 and GC budget 32 MiBmre
  • 9eff6627Merge branch 'f2-api-bugs' into mainGitoria
  • 26117255|||PR apps API: review comments on files with spaces in their namemre
  • b8796cecMerge branch 'f1-broken-json' into mainGitoria
  • 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
  • f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
  • 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
  • 16a3530fMerge branch 'heap-revert' into mainGitoria