Upload via GUI (273 Dateien)
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Prüft die Umwandlung eingehender E-Mails in Ticket-Text (includes/mail_text.php): CSS und Skripte, versteckte Vorschautexte und
|
||||
* unsichtbare Füllzeichen landen nicht im Ticket, Absätze und Listen bleiben lesbar, Text-Teile werden bevorzugt, Kodierungen
|
||||
* (Base64, Quoted-Printable, ISO-8859-1) und Anhänge werden richtig behandelt.
|
||||
*/
|
||||
|
||||
require_once dirname(__DIR__) . '/includes/mail_text.php';
|
||||
|
||||
$failures = [];
|
||||
$total = 0;
|
||||
$check = function (bool $ok, string $what) use (&$failures, &$total): void { $total++; if (!$ok) $failures[] = $what; };
|
||||
|
||||
// ── Eine Newsletter-Mail wie die von Meta (Stil-Block, versteckter Vorschautext, Füllzeichen, Tabellen-Layout) ─────────────────
|
||||
$meta = <<<'HTML'
|
||||
<html><head><meta charset="utf-8"><title>Meta</title>
|
||||
<style type="text/css">@media all and (max-width: 480px){*[class].ib_t{min-width:100%!important}*[class].ib_row{display:block!important}}
|
||||
.d_mb_show{display:none}.mb_text h1,.mb_text h2{line-height:normal}.mb_work_text a{color:#1270e9}</style>
|
||||
<script>var x = "tracking";</script></head>
|
||||
<body>
|
||||
<!-- Kommentar, der nicht erscheinen soll -->
|
||||
<div style="display:none;max-height:0px;overflow:hidden">Versteckter Vorschautext͏‌ ͏‌ </div>
|
||||
<table><tr><td><h1>Dein Meta-Konto steht bereit</h1></td></tr>
|
||||
<tr><td><p>Dein upgedatetes Konto funktioniert über Meta-Apps und -Geräte hinweg.</p></td></tr>
|
||||
<tr><td>windelgeschichten<br>Instagram<br> mlukas6993 Threads</td></tr></table>
|
||||
<ul><li>Ein Login für alle Apps.</li><li>Verbesserte Sicherheitsfunktionen.</li></ul>
|
||||
<p>Viele Grüße<br>Meta</p>
|
||||
<img src="https://example.org/pixel.gif" alt="">
|
||||
<a href="https://example.org/x">Meta-Konten entdecken</a>
|
||||
<span style="font-size:0px">Abstandshalter</span>
|
||||
</body></html>
|
||||
HTML;
|
||||
$t = mail_html_to_text($meta);
|
||||
$check(!str_contains($t, '@media') && !str_contains($t, '{') && !str_contains($t, 'ib_row') && !str_contains($t, 'line-height'), 'Kein CSS im Text');
|
||||
$check(!str_contains($t, 'tracking') && !str_contains($t, 'var x'), 'Kein Skript im Text');
|
||||
$check(!str_contains($t, 'Kommentar') && !str_contains($t, 'Versteckter Vorschautext') && !str_contains($t, 'Abstandshalter'), 'Kommentare und versteckte Elemente fehlen');
|
||||
$check(!str_contains($t, "\u{034F}") && !str_contains($t, "\u{200C}") && !str_contains($t, "\u{00A0}"), 'Unsichtbare Füllzeichen und geschützte Leerzeichen sind weg');
|
||||
$check(str_contains($t, "Dein Meta-Konto steht bereit\n") && str_contains($t, 'über Meta-Apps und -Geräte hinweg.'), 'Überschrift und Absatz mit Umlauten bleiben lesbar');
|
||||
$check(str_contains($t, "• Ein Login für alle Apps.\n• Verbesserte Sicherheitsfunktionen."), 'Listen werden zu Aufzählungszeilen');
|
||||
$check(str_contains($t, "windelgeschichten\nInstagram\nmlukas6993 Threads"), 'Zeilenumbrüche (br) bleiben, doppelte Leerzeichen werden zusammengefasst');
|
||||
$check(str_contains($t, "Viele Grüße\nMeta") && str_contains($t, 'Meta-Konten entdecken'), 'Grußformel und Linktext bleiben');
|
||||
$check(!preg_match("/\n{3,}/", $t) && $t === trim($t), 'Keine Leerzeilen-Flut, kein Leerraum am Anfang oder Ende');
|
||||
$check(strlen($t) < 700, 'Der Text ist kurz und lesbar (' . strlen($t) . ' Zeichen)');
|
||||
|
||||
// ── Weitere HTML-Fälle ───────────────────────────────────────────────────────
|
||||
$check(mail_html_to_text('<p>Hallo <b>Welt</b> & Co <3</p>') === 'Hallo Welt & Co <3', 'Entitäten werden entschlüsselt, Tags entfernt');
|
||||
$check(mail_html_to_text('<div>Zeile 1</div><div>Zeile 2</div>') === "Zeile 1\nZeile 2", 'Blöcke werden zu eigenen Zeilen');
|
||||
$check(mail_html_to_text('<img src="x.png" alt="Logo der Firma"> Text') === 'Logo der Firma Text', 'Alternativtext von Bildern bleibt');
|
||||
$check(mail_html_to_text('') === '' && mail_html_to_text(" \n ") === '', 'Leere Mail bleibt leer');
|
||||
$check(mail_html_to_text('<p style="visibility:hidden">weg</p><p>da</p>') === 'da', 'Unsichtbare Absätze fallen weg');
|
||||
$check(mail_html_to_text('Nur Text ohne Tags, aber mit Umlauten äöü') === 'Nur Text ohne Tags, aber mit Umlauten äöü', 'Text ohne HTML bleibt unverändert');
|
||||
$check(mail_html_to_text_regex('<style>a{color:red}</style><p>Hallo</p><br>Welt') === "Hallo\n\nWelt" || str_contains(mail_html_to_text_regex('<style>a{color:red}</style><p>Hallo</p><br>Welt'), 'Hallo'), 'Ersatzweg ohne DOM entfernt Stil-Blöcke');
|
||||
$check(!str_contains(mail_html_to_text_regex('<style>a{color:red}</style><p>Hallo</p>'), 'color'), 'Ersatzweg: kein CSS');
|
||||
|
||||
// ── Kodierungen ──────────────────────────────────────────────────────────────
|
||||
$check(mail_decode_part(base64_encode("Grüße"), 3, 'utf-8') === 'Grüße', 'Base64');
|
||||
$check(mail_decode_part("Gr=C3=BC=C3=9Fe", 4, 'utf-8') === 'Grüße', 'Quoted-Printable');
|
||||
$check(mail_decode_part(mb_convert_encoding('Grüße', 'ISO-8859-1', 'UTF-8'), 0, 'iso-8859-1') === 'Grüße', 'ISO-8859-1 wird nach UTF-8 umgewandelt');
|
||||
$check(mail_decode_part(chunk_split(base64_encode(mb_convert_encoding('Äpfel', 'Windows-1252', 'UTF-8'))), 3, 'windows-1252') === 'Äpfel', 'Base64 mit Zeilenumbrüchen und Windows-1252');
|
||||
$check(mail_decode_part('ohne Angabe', 0, '') === 'ohne Angabe', 'Ohne Zeichensatz');
|
||||
|
||||
// ── Mail-Aufbau (wie imap_fetchstructure ihn liefert) ────────────────────────
|
||||
$param = fn(string $a, string $v) => (object) ['attribute' => $a, 'value' => $v];
|
||||
$text = fn(string $sub, int $enc = 0, string $charset = 'utf-8', array $extra = []) => (object) array_merge(['type' => 0, 'subtype' => $sub, 'encoding' => $enc, 'ifparameters' => 1, 'parameters' => [$param('charset', $charset)]], $extra);
|
||||
$multi = fn(array $parts) => (object) ['type' => 1, 'subtype' => 'ALTERNATIVE', 'parts' => $parts];
|
||||
$fetchFrom = function (array $bodies) { return fn(string $no) => $bodies[$no] ?? ''; };
|
||||
|
||||
// multipart/alternative: Text bevorzugt
|
||||
$s = $multi([$text('PLAIN'), $text('HTML')]);
|
||||
$check(mail_best_text($s, $fetchFrom(['1' => 'Das ist der einfache Text der Mail mit genug Inhalt.', '2' => '<p>Das ist <b>HTML</b></p><style>x{}</style>'])) === 'Das ist der einfache Text der Mail mit genug Inhalt.', 'Alternativ-Mail: der Text-Teil wird bevorzugt');
|
||||
// nur HTML (Newsletter)
|
||||
$s = $text('HTML', 4);
|
||||
$check(mail_best_text($s, $fetchFrom(['1' => quoted_printable_encode('<style>.a{x:y}</style><h1>Hallo</h1><p>Willkommen</p>')])) === "Hallo\nWillkommen", 'Reine HTML-Mail: nur der sichtbare Text, ohne CSS');
|
||||
// Text-Teil ist nur eine Floskel, HTML hat den Inhalt
|
||||
$s = $multi([$text('PLAIN'), $text('HTML')]);
|
||||
$long = '<p>' . str_repeat('Der eigentliche Inhalt steht nur in der HTML-Fassung. ', 6) . '</p>';
|
||||
$check(str_contains(mail_best_text($s, $fetchFrom(['1' => 'Bitte HTML ansehen', '2' => $long])), 'eigentliche Inhalt'), 'Kurze Text-Floskel: die HTML-Fassung wird genommen');
|
||||
// Anhänge werden übersprungen, verschachtelte Teile gefunden
|
||||
$att = $text('PLAIN', 0, 'utf-8', ['ifdisposition' => 1, 'disposition' => 'attachment']);
|
||||
$nested = (object) ['type' => 1, 'subtype' => 'MIXED', 'parts' => [$multi([$text('PLAIN', 3), $text('HTML', 3)]), $att]];
|
||||
$b64 = base64_encode('Text im verschachtelten Teil mit ausreichend vielen Zeichen drin.');
|
||||
$check(mail_best_text($nested, $fetchFrom(['1.1' => $b64, '1.2' => base64_encode('<p>html</p>'), '2' => 'ANHANG-INHALT'])) === 'Text im verschachtelten Teil mit ausreichend vielen Zeichen drin.', 'Verschachtelte Teile (1.1) und Base64; Anhang wird ignoriert');
|
||||
$parts = mail_collect_text_parts($nested);
|
||||
$check(count($parts) === 2 && $parts[0]['no'] === '1.1' && $parts[1]['no'] === '1.2', 'Teil-Nummern stimmen mit IMAP überein');
|
||||
// Anhang mit Dateiname (ohne disposition) zählt nicht als Text
|
||||
$named = $text('PLAIN', 0, 'utf-8', ['parameters' => [$param('name', 'protokoll.txt')]]);
|
||||
$check(mail_collect_text_parts($named) === [], 'Textdatei als Anhang wird nicht als Mailtext gelesen');
|
||||
// Nicht-Text (Bild) ergibt nichts
|
||||
$check(mail_collect_text_parts((object) ['type' => 5, 'subtype' => 'PNG']) === [], 'Bild-Teil ist kein Text');
|
||||
// ISO-8859-1-Mail
|
||||
$s = $text('PLAIN', 0, 'iso-8859-1');
|
||||
$check(mail_best_text($s, $fetchFrom(['1' => mb_convert_encoding('Größe und Straße sind wichtig für diese Anfrage, bitte prüfen.', 'ISO-8859-1', 'UTF-8')])) === 'Größe und Straße sind wichtig für diese Anfrage, bitte prüfen.', 'Mail in ISO-8859-1');
|
||||
// leere Mail
|
||||
$check(mail_best_text($text('PLAIN'), $fetchFrom(['1' => ''])) === '', 'Leere Mail ergibt leeren Text (das Ticket zeigt dann „kein Inhalt“)');
|
||||
|
||||
if ($failures) {
|
||||
fwrite(STDERR, "Fehlgeschlagen:\n - " . implode("\n - ", $failures) . "\n");
|
||||
exit(1);
|
||||
}
|
||||
echo "Mail text checks passed ({$total} Prüfungen).\n";
|
||||
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Prüft die Ticket-Sperre: Administratoren dürfen ein von anderen bearbeitetes Ticket lesen und bearbeiten (Web und API), die Sperre
|
||||
* lässt sich aufheben (Admin: jede, jeder: die eigene), normale Mitarbeiter bleiben ausgesperrt, im Live-Chat wird ein Admin nie ausgesperrt.
|
||||
*/
|
||||
|
||||
if (!extension_loaded('pdo_sqlite') || !function_exists('curl_init')) { echo "Aktivitäts-Test übersprungen: pdo_sqlite oder curl fehlt.\n"; exit(0); }
|
||||
|
||||
date_default_timezone_set('Europe/Berlin'); // wie in der Test-Installation
|
||||
$root = dirname(__DIR__);
|
||||
$work = sys_get_temp_dir() . '/deskhub-lock-' . bin2hex(random_bytes(4));
|
||||
$tmp = $work . '/inst';
|
||||
mkdir($tmp, 0755, true);
|
||||
$webPort = random_int(33500, 33999);
|
||||
$skip = '#^(config/config\.php|database/[^/]+\.sqlite[^/]*|backups|uploads|tests|plugins/[^/]+|\.git)(/|$)#';
|
||||
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $f) {
|
||||
$rel = str_replace(chr(92), '/', substr($f->getPathname(), strlen($root) + 1));
|
||||
if (preg_match($skip, $rel) && !preg_match('#^(backups|uploads|plugins)/(\.htaccess|README\.md)$#', $rel)) continue;
|
||||
if ($f->isDir()) { @mkdir($tmp . '/' . $rel, 0755, true); continue; }
|
||||
@mkdir(dirname($tmp . '/' . $rel), 0755, true);
|
||||
copy($f->getPathname(), $tmp . '/' . $rel);
|
||||
}
|
||||
@mkdir($tmp . '/uploads');
|
||||
@mkdir($tmp . '/config');
|
||||
file_put_contents($tmp . '/config/config.php', '<?php return ' . var_export([
|
||||
'app_key' => bin2hex(random_bytes(32)),
|
||||
'db' => ['driver' => 'sqlite', 'sqlite_path' => $tmp . '/database/deskhub.sqlite'],
|
||||
'site' => ['name' => 'Test', 'url' => 'http://127.0.0.1', 'admin_email' => 'a@test.de', 'timezone' => 'Europe/Berlin'],
|
||||
'uploads' => ['max_size_bytes' => 10485760, 'allowed_extensions' => ['png'], 'path' => $tmp . '/uploads'],
|
||||
], true) . ';');
|
||||
|
||||
putenv('DESKHUB_CONFIG_JSON');
|
||||
putenv('DESKHUB_SQLITE_PATH');
|
||||
putenv('DESKHUB_TESTING');
|
||||
putenv('DESKHUB_API_ALLOW_INSECURE=1');
|
||||
require_once $root . '/database/sqlite_schema.php';
|
||||
require_once $root . '/database/migrate.php';
|
||||
$db = new PDO('sqlite:' . $tmp . '/database/deskhub.sqlite');
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
$db->exec('PRAGMA foreign_keys = ON');
|
||||
$db->exec(convert_schema_to_sqlite((string) file_get_contents($root . '/database/schema.sql')));
|
||||
$mig = run_migrations($db, true);
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$dept = (int) $db->query('SELECT id FROM departments ORDER BY id LIMIT 1')->fetchColumn();
|
||||
$db->exec('DELETE FROM staff');
|
||||
$ins = $db->prepare('INSERT INTO staff (name, email, password_hash, role, department_id, is_active, created_at) VALUES (?,?,?,?,?,1,?)');
|
||||
$ids = [];
|
||||
foreach ([['Chef', 'chef@test.de', 'admin'], ['Agent', 'agent@test.de', 'agent'], ['Andere', 'andere@test.de', 'agent']] as [$n, $e, $r]) {
|
||||
$ins->execute([$n, $e, password_hash('Sehr-Sicher-1234', PASSWORD_DEFAULT), $r, $dept, $now]);
|
||||
$ids[$n] = (int) $db->lastInsertId();
|
||||
}
|
||||
$db = null;
|
||||
|
||||
$failures = [];
|
||||
$total = 0;
|
||||
$check = function (bool $ok, string $what) use (&$failures, &$total): void { $total++; if (!$ok) $failures[] = $what; };
|
||||
$webProc = proc_open([PHP_BINARY, '-S', "127.0.0.1:$webPort", '-t', $tmp], [['pipe', 'r'], ['file', $work . '/web.out', 'w'], ['file', $work . '/web.out', 'a']], $wp, $tmp);
|
||||
|
||||
try {
|
||||
for ($i = 0; $i < 50; $i++) { if (@fsockopen('127.0.0.1', $webPort)) break; usleep(100000); }
|
||||
$pdo = function () use ($tmp): PDO {
|
||||
$p = new PDO('sqlite:' . $tmp . '/database/deskhub.sqlite');
|
||||
$p->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$p->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
return $p;
|
||||
};
|
||||
$call = function (string $method, string $path, ?array $json = null, ?string $bearer = null, array $form = [], string $jar = '', array $extra = []) use ($webPort): array {
|
||||
$ch = curl_init("http://127.0.0.1:$webPort$path");
|
||||
$h = array_merge($json !== null ? ['Content-Type: application/json'] : [], $extra);
|
||||
if ($bearer) $h[] = 'Authorization: Bearer ' . $bearer;
|
||||
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => false, CURLOPT_TIMEOUT => 60, CURLOPT_HTTPHEADER => $h]);
|
||||
if ($jar !== '') { curl_setopt($ch, CURLOPT_COOKIEJAR, $jar); curl_setopt($ch, CURLOPT_COOKIEFILE, $jar); }
|
||||
if ($method === 'POST') { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json !== null ? json_encode($json) : http_build_query($form)); }
|
||||
$b = (string) curl_exec($ch);
|
||||
$s = (int) curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
||||
curl_close($ch);
|
||||
return [$s, json_decode($b, true) ?? $b];
|
||||
};
|
||||
$login = function (string $email) use ($call): string {
|
||||
[, $r] = $call('POST', '/api/staff/v1/login.php', ['email' => $email, 'password' => 'Sehr-Sicher-1234', 'deviceName' => 'T']);
|
||||
return (string) ($r['token'] ?? '');
|
||||
};
|
||||
$chef = $login('chef@test.de');
|
||||
$agent = $login('agent@test.de');
|
||||
$other = $login('andere@test.de');
|
||||
$check($chef !== '' && $agent !== '' && $other !== '', 'Anmeldung über die Mitarbeiter-API');
|
||||
|
||||
$prio = (int) $pdo()->query('SELECT id FROM priorities ORDER BY id LIMIT 1')->fetchColumn();
|
||||
$mkTicket = function (string $number, string $source = 'web') use ($pdo, $dept, $prio): void {
|
||||
$n = date('Y-m-d H:i:s');
|
||||
$pdo()->prepare('INSERT INTO tickets (ticket_number, subject, requester_name, requester_email, department_id, priority_id, status, source, created_at, updated_at) VALUES (?,?,?,?,?,?,?,?,?,?)')
|
||||
->execute([$number, 'Testticket ' . $number, 'Kunde', 'kunde@example.org', $dept, $prio, 'open', $source, $n, $n]);
|
||||
};
|
||||
$lockedBy = fn(string $number) => $pdo()->query("SELECT locked_by FROM tickets WHERE ticket_number = '$number'")->fetchColumn();
|
||||
$mkTicket('T-LOCK-1');
|
||||
|
||||
// Mitarbeiter A öffnet das Ticket und besitzt danach die Sperre
|
||||
[$s, $r] = $call('GET', '/api/staff/v1/ticket.php?number=T-LOCK-1', null, $agent);
|
||||
$check($s === 200 && (int) $lockedBy('T-LOCK-1') === $ids['Agent'] && array_key_exists('lockedBy', $r['ticket'] ?? []) && $r['ticket']['lockedBy'] === null, 'Mitarbeiter öffnet das Ticket und bekommt die Sperre (HTTP ' . $s . ')');
|
||||
// anderer Mitarbeiter: wie bisher gesperrt
|
||||
[$s, $r] = $call('GET', '/api/staff/v1/ticket.php?number=T-LOCK-1', null, $other);
|
||||
$check($s === 409 && str_contains(json_encode($r), 'Agent'), 'Anderer Mitarbeiter bekommt weiter den Hinweis „wird gerade bearbeitet“ (HTTP ' . $s . ')');
|
||||
[$s] = $call('POST', '/api/staff/v1/ticket_message.php', ['number' => 'T-LOCK-1', 'type' => 'note', 'message' => 'Fremd'], $other);
|
||||
$check($s === 409, 'Anderer Mitarbeiter darf nicht schreiben (HTTP ' . $s . ')');
|
||||
// Admin: darf lesen, Sperre bleibt beim anderen
|
||||
[$s, $r] = $call('GET', '/api/staff/v1/ticket.php?number=T-LOCK-1', null, $chef);
|
||||
$check($s === 200 && ($r['ticket']['lockedBy'] ?? '') === 'Agent' && ($r['ticket']['canUnlock'] ?? false) === true, 'Admin kann das gesperrte Ticket lesen und sieht, wer es bearbeitet (HTTP ' . $s . ' ' . json_encode([$r['ticket']['lockedBy'] ?? 'FEHLT', $r['ticket']['canUnlock'] ?? 'FEHLT']) . ')');
|
||||
$check((int) $lockedBy('T-LOCK-1') === $ids['Agent'], 'Die Sperre des anderen bleibt dabei bestehen');
|
||||
// Admin darf bearbeiten
|
||||
[$s] = $call('POST', '/api/staff/v1/ticket_message.php', ['number' => 'T-LOCK-1', 'type' => 'reply', 'message' => 'Antwort vom Admin'], $chef);
|
||||
$check($s === 201, 'Admin kann auf ein gesperrtes Ticket antworten (HTTP ' . $s . ')');
|
||||
[$s] = $call('POST', '/api/staff/v1/ticket_message.php', ['number' => 'T-LOCK-1', 'type' => 'note', 'message' => 'Notiz vom Admin'], $chef);
|
||||
$check($s === 201, 'und Notizen schreiben (HTTP ' . $s . ')');
|
||||
|
||||
// Sperre aufheben
|
||||
[$s] = $call('POST', '/api/staff/v1/ticket_unlock.php', ['number' => 'T-LOCK-1'], $other);
|
||||
$check($s === 403 && (int) $lockedBy('T-LOCK-1') === $ids['Agent'], 'Normaler Mitarbeiter darf die Sperre eines anderen nicht aufheben (HTTP ' . $s . ')');
|
||||
[$s, $r] = $call('POST', '/api/staff/v1/ticket_unlock.php', ['number' => 'T-LOCK-1'], $chef);
|
||||
$check($s === 200 && ($r['unlocked'] ?? false) === true && $lockedBy('T-LOCK-1') === null, 'Admin hebt die Sperre eines anderen auf (HTTP ' . $s . ')');
|
||||
$log = $pdo()->query("SELECT COUNT(*) FROM activity_log WHERE action LIKE 'Sperre von%'")->fetchColumn();
|
||||
$check((int) $log === 1, 'Das Aufheben steht im Ticket-Verlauf');
|
||||
[$s] = $call('GET', '/api/staff/v1/ticket.php?number=T-LOCK-1', null, $other);
|
||||
$check($s === 200 && (int) $lockedBy('T-LOCK-1') === $ids['Andere'], 'Danach kann der andere Mitarbeiter das Ticket öffnen (HTTP ' . $s . ')');
|
||||
// eigene Sperre selbst freigeben
|
||||
[$s] = $call('POST', '/api/staff/v1/ticket_unlock.php', ['number' => 'T-LOCK-1'], $other);
|
||||
$check($s === 200 && $lockedBy('T-LOCK-1') === null, 'Jeder darf die eigene Sperre freigeben');
|
||||
[$s, $r] = $call('POST', '/api/staff/v1/ticket_unlock.php', ['number' => 'T-LOCK-1'], $other);
|
||||
$check($s === 200 && ($r['unlocked'] ?? true) === false, 'Freigeben ohne Sperre ist harmlos');
|
||||
|
||||
// Live-Chat: Admin wird nie ausgesperrt
|
||||
$mkTicket('T-LOCK-CHAT', 'chat');
|
||||
$call('GET', '/api/staff/v1/ticket.php?number=T-LOCK-CHAT', null, $agent);
|
||||
[$s, $r] = $call('GET', '/api/staff/v1/ticket.php?number=T-LOCK-CHAT', null, $other);
|
||||
$check($s === 200 && !empty($r['ticket']['lockedByOtherName']), 'Live-Chat: anderer Mitarbeiter ist nur Zuschauer ' . json_encode($r['ticket']['lockedByOtherName'] ?? 'FEHLT'));
|
||||
[$s, $r] = $call('GET', '/api/staff/v1/ticket.php?number=T-LOCK-CHAT', null, $chef);
|
||||
$check($s === 200 && empty($r['ticket']['lockedByOtherName']), 'Live-Chat: Admin wird nicht ausgesperrt');
|
||||
[$s] = $call('POST', '/api/staff/v1/ticket_message.php', ['number' => 'T-LOCK-CHAT', 'type' => 'reply', 'message' => 'Hallo vom Admin'], $chef);
|
||||
$check($s === 201, 'Live-Chat: Admin darf antworten (HTTP ' . $s . ')');
|
||||
|
||||
// Weboberfläche
|
||||
$mkTicket('T-LOCK-WEB');
|
||||
$call('GET', '/api/staff/v1/ticket.php?number=T-LOCK-WEB', null, $agent); // Agent hält die Sperre
|
||||
$webLogin = function (string $email) use ($call): string {
|
||||
$jar = tempnam(sys_get_temp_dir(), 'lck');
|
||||
[, $lp] = $call('GET', '/staff/login.php', null, null, [], $jar);
|
||||
preg_match('/name="csrf_token" value="([a-f0-9]+)"/', is_string($lp) ? $lp : '', $m);
|
||||
$call('POST', '/staff/login.php', null, null, ['csrf_token' => $m[1] ?? '', 'email' => $email, 'password' => 'Sehr-Sicher-1234'], $jar);
|
||||
return $jar;
|
||||
};
|
||||
$jarChef = $webLogin('chef@test.de');
|
||||
$jarOther = $webLogin('andere@test.de');
|
||||
[$s, $page] = $call('GET', '/staff/ticket_view.php?n=T-LOCK-WEB', null, null, [], $jarOther, ['Sec-Fetch-Mode: navigate']);
|
||||
$check($s === 302, 'Web: normaler Mitarbeiter wird bei gesperrtem Ticket weitergeleitet (HTTP ' . $s . ')');
|
||||
[$s, $page] = $call('GET', '/staff/ticket_view.php?n=T-LOCK-WEB', null, null, [], $jarChef, ['Sec-Fetch-Mode: navigate']);
|
||||
$page = is_string($page) ? $page : '';
|
||||
$check($s === 200 && str_contains($page, 'Sperre aufheben und übernehmen') && str_contains($page, 'Testticket T-LOCK-WEB'), 'Web: Admin öffnet das gesperrte Ticket und sieht den Hinweis mit Knopf (HTTP ' . $s . ')');
|
||||
$check((int) $lockedBy('T-LOCK-WEB') === $ids['Agent'], 'Web: die Sperre des anderen bleibt beim Lesen bestehen');
|
||||
preg_match('/name="csrf_token" value="([a-f0-9]+)"[^>]*>\s*<input type="hidden" name="action" value="admin_force_unlock"/', $page, $m);
|
||||
[$s] = $call('POST', '/staff/ticket_view.php?n=T-LOCK-WEB', null, null, ['csrf_token' => $m[1] ?? '', 'action' => 'admin_force_unlock', 'locked_by_name' => 'Agent'], $jarChef);
|
||||
$check($s === 302 && $lockedBy('T-LOCK-WEB') === null, 'Web: „Sperre aufheben und übernehmen“ funktioniert (HTTP ' . $s . ')');
|
||||
[$s, $page] = $call('GET', '/staff/ticket_view.php?n=T-LOCK-WEB', null, null, [], $jarChef, ['Sec-Fetch-Mode: navigate']);
|
||||
$check($s === 200 && (int) $lockedBy('T-LOCK-WEB') === $ids['Chef'], 'Web: danach besitzt der Admin die Sperre');
|
||||
@unlink($jarChef);
|
||||
@unlink($jarOther);
|
||||
} finally {
|
||||
if (isset($webProc) && is_resource($webProc)) { proc_terminate($webProc); proc_close($webProc); }
|
||||
}
|
||||
|
||||
usleep(300000);
|
||||
$rm = function (string $d) use (&$rm) {
|
||||
foreach (scandir($d) ?: [] as $e) { if ($e === '.' || $e === '..') continue; is_dir("$d/$e") && !is_link("$d/$e") ? $rm("$d/$e") : @unlink("$d/$e"); }
|
||||
@rmdir($d);
|
||||
};
|
||||
if (str_starts_with($work, sys_get_temp_dir() . '/deskhub-lock-')) $rm($work);
|
||||
|
||||
if ($failures) {
|
||||
fwrite(STDERR, "Fehlgeschlagen:\n - " . implode("\n - ", $failures) . "\n");
|
||||
exit(1);
|
||||
}
|
||||
echo "Ticket lock checks passed ({$total} Prüfungen).\n";
|
||||
Reference in New Issue
Block a user