Upload via GUI (23 Dateien)
This commit is contained in:
@@ -91,7 +91,7 @@ test('apiCall: 401 räumt die Anmeldung weg, Netzwerkfehler wird gemeldet', asyn
|
||||
assert.notEqual(await getSession(), null, 'ein Netzwerkfehler meldet nicht ab');
|
||||
});
|
||||
|
||||
test('Anmeldung: Berechtigung, Authenticator-Code, Speichern', async () => {
|
||||
test('Anmeldung: ohne Rückfrage, Authenticator-Code, Speichern', async () => {
|
||||
const { login, getSession } = await fresh();
|
||||
let step = 0;
|
||||
globalThis.fetch = makeFetch({ 'POST login.php': (u, init) => {
|
||||
@@ -103,33 +103,52 @@ test('Anmeldung: Berechtigung, Authenticator-Code, Speichern', async () => {
|
||||
} });
|
||||
const r1 = await login('support.example.de', 'a@b.de', 'geheim', '');
|
||||
assert.deepEqual(r1, { requiresTotp: true });
|
||||
assert.deepEqual(env.calls.permissionsRequested, ['https://support.example.de/*'], 'nur dieser eine Server');
|
||||
assert.deepEqual(env.calls.permissionsRequested, [], 'es gibt keine Berechtigungsabfrage mehr');
|
||||
assert.equal(await getSession(), null, 'ohne Code noch keine Anmeldung');
|
||||
const r2 = await login('support.example.de', 'a@b.de', 'geheim', '123456');
|
||||
assert.equal(r2.session.staff.name, 'Agent');
|
||||
assert.equal((await getSession()).serverUrl, SERVER);
|
||||
});
|
||||
|
||||
test('Anmeldung ohne erteilte Berechtigung bricht ab, ohne etwas zu senden', async () => {
|
||||
test('Anmeldung mit falscher Adresse bricht ab, ohne etwas zu senden', async () => {
|
||||
const { login } = await fresh();
|
||||
env.chromeMock.permissions.allow = false;
|
||||
globalThis.fetch = makeFetch({});
|
||||
await assert.rejects(login('support.example.de', 'a@b.de', 'x', ''), /Erlaubnis/);
|
||||
await assert.rejects(login('http://support.example.de', 'a@b.de', 'x', ''), /HTTPS/);
|
||||
assert.equal(globalThis.fetch.log.length, 0);
|
||||
});
|
||||
|
||||
test('Abmelden sperrt das Token, entfernt Berechtigung und Daten', async () => {
|
||||
test('Abmelden sperrt das Token und entfernt die Daten', async () => {
|
||||
const { logout, setSession, getSession } = await fresh();
|
||||
await setSession(SESSION); await chrome.storage.local.set({ badgeCount: 3, lastSeen: 'x' });
|
||||
env.chromeMock.permissions.granted.add(SERVER + '/*');
|
||||
globalThis.fetch = makeFetch({ 'POST logout.php': { body: { ok: true } } });
|
||||
await logout();
|
||||
assert.equal(globalThis.fetch.log[0].key, 'POST logout.php');
|
||||
assert.deepEqual(env.calls.permissionsRemoved, [SERVER + '/*']);
|
||||
assert.equal(await getSession(), null);
|
||||
assert.deepEqual(await chrome.storage.local.get(['badgeCount', 'lastSeen']), {});
|
||||
});
|
||||
|
||||
test('apiBeacon: Anfrage geht sofort und mit keepalive raus (Popup schließt sich)', async () => {
|
||||
const { apiBeacon } = await fresh();
|
||||
globalThis.fetch = makeFetch({ 'POST ticket_unlock.php': { body: { ok: true } } });
|
||||
apiBeacon(SESSION, 'ticket_unlock.php', { number: 'T-1' });
|
||||
assert.equal(globalThis.fetch.log.length, 1, 'synchron abgeschickt, ohne auf Speicherzugriffe zu warten');
|
||||
const { init } = globalThis.fetch.log[0];
|
||||
assert.equal(init.keepalive, true); assert.equal(init.method, 'POST'); assert.equal(init.credentials, 'omit');
|
||||
assert.equal(init.headers.Authorization, `Bearer ${SESSION.token}`);
|
||||
assert.deepEqual(JSON.parse(init.body), { number: 'T-1' });
|
||||
apiBeacon(null, 'ticket_unlock.php', {});
|
||||
assert.equal(globalThis.fetch.log.length, 1, 'ohne Sitzung wird nichts gesendet');
|
||||
});
|
||||
|
||||
test('Abmelden löscht auch nicht gesendete Entwürfe, aber nicht die Einstellungen', async () => {
|
||||
const { clearSession, setSession, setSettings } = await fresh();
|
||||
await setSession(SESSION); await setSettings({ theme: 'dark' });
|
||||
await chrome.storage.local.set({ 'draft:T-1': 'halber Text', 'draft:T-2': 'mehr', lastLogin: { serverUrl: SERVER } });
|
||||
await clearSession();
|
||||
const left = await chrome.storage.local.get(null);
|
||||
assert.deepEqual(Object.keys(left).sort(), ['lastLogin', 'settings']);
|
||||
});
|
||||
|
||||
test('Ticketpfad und Textumwandlung', async () => {
|
||||
const { ticketPath, plainToHtml } = await fresh();
|
||||
assert.equal(ticketPath('T-2026-0001'), '/staff/ticket_view.php?n=T-2026-0001');
|
||||
@@ -217,12 +236,53 @@ test('Hintergrund: abgelaufene Anmeldung zeigt „!“ und bittet um neue Anmeld
|
||||
assert.equal(r.skipped, true); assert.equal(globalThis.fetch.log.length, 0);
|
||||
});
|
||||
|
||||
test('Manifest: nur nötige Rechte, kein Zugriff auf alle Webseiten ab Start, strenge Inhaltsrichtlinie', async () => {
|
||||
test('Hintergrund: Meldungsarten lassen sich einzeln abschalten', async () => {
|
||||
const { core, bg } = await freshBackground();
|
||||
await core.setSession(SESSION); await core.setSettings({ notifyUnassigned: false });
|
||||
await chrome.storage.local.set({ lastSeen: 'x' });
|
||||
globalThis.fetch = makeFetch({ 'GET activity.php': { body: { newReplies: 2, newUnassigned: 7, serverTime: 'y' } } });
|
||||
const r = await bg.poll();
|
||||
assert.equal(r.fresh, 2, 'nicht zugewiesene Tickets zählen nicht, wenn abgeschaltet');
|
||||
assert.match(env.calls.notifications[0].message, /2 Aktualisierungen/);
|
||||
assert.doesNotMatch(env.calls.notifications[0].message, /nicht zugewiesen/);
|
||||
});
|
||||
|
||||
test('Zeitangaben: Serverzeit lesen und kurz anzeigen', async () => {
|
||||
const { parseServerTime, timeAgo, fmtBytes, initials, safeColor } = await fresh();
|
||||
const now = new Date(2026, 9, 31, 12, 0, 0);
|
||||
assert.equal(parseServerTime('2026-10-31 04:03:00').getHours(), 4);
|
||||
assert.equal(parseServerTime('unsinn'), null);
|
||||
assert.equal(timeAgo('2026-10-31 11:59:30', now), 'gerade eben');
|
||||
assert.equal(timeAgo('2026-10-31 11:40:00', now), 'vor 20 Min');
|
||||
assert.equal(timeAgo('2026-10-31 04:03:00', now), 'heute 04:03');
|
||||
assert.equal(timeAgo('2026-10-30 23:33:00', now), 'gestern 23:33');
|
||||
assert.equal(timeAgo('2026-10-20 08:05:00', now), '20.10. 08:05');
|
||||
assert.equal(timeAgo('', now), '');
|
||||
assert.equal(timeAgo('2026-10-31 17:00:00', now), 'heute 17:00', 'Zukunft: Wiedervorlage');
|
||||
assert.equal(timeAgo('2026-11-01 08:00:00', now), 'morgen 08:00');
|
||||
assert.equal(timeAgo('2026-11-05 08:00:00', now), '05.11. 08:00');
|
||||
assert.equal(fmtBytes(500), '500 B'); assert.equal(fmtBytes(2048), '2 KB'); assert.equal(fmtBytes(3 * 1048576), '3.0 MB');
|
||||
assert.equal(initials('Lukas Muster'), 'LM'); assert.equal(initials(''), '?');
|
||||
assert.equal(safeColor('#0f766e'), '#0f766e'); assert.equal(safeColor('red;background:url(x)'), null);
|
||||
});
|
||||
|
||||
test('Wiedervorlage: nur künftige Zeitpunkte, im Serverformat', async () => {
|
||||
globalThis.document = undefined;
|
||||
const { snoozeChoices } = await import('../views/ticket.js');
|
||||
const now = new Date(2026, 9, 31, 18, 0, 0); // nach 17 Uhr: „Heute 17:00“ entfällt
|
||||
const labels = snoozeChoices(now).map(([l]) => l);
|
||||
assert.ok(!labels.includes('Heute 17:00')); assert.ok(labels.includes('Morgen 08:00')); assert.ok(labels.includes('In 1 Stunde'));
|
||||
for (const [, v] of snoozeChoices(now)) assert.match(v, /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:00$/);
|
||||
assert.deepEqual(snoozeChoices(now).find(([l]) => l === 'Morgen 08:00'), ['Morgen 08:00', '2026-11-01 08:00:00']);
|
||||
});
|
||||
|
||||
test('Manifest: Serverzugriff ohne Rückfrage, nur nötige Rechte, strenge Inhaltsrichtlinie', async () => {
|
||||
const { readFile } = await import('node:fs/promises');
|
||||
const m = JSON.parse(await readFile(new URL('../manifest.json', import.meta.url), 'utf8'));
|
||||
assert.equal(m.manifest_version, 3);
|
||||
assert.deepEqual([...m.permissions].sort(), ['alarms', 'contextMenus', 'notifications', 'storage']);
|
||||
assert.equal(m.host_permissions, undefined, 'Serverzugriff wird erst bei der Anmeldung für genau einen Server erfragt');
|
||||
assert.deepEqual([...m.permissions].sort(), ['alarms', 'contextMenus', 'notifications', 'sidePanel', 'storage']);
|
||||
assert.equal(m.optional_host_permissions, undefined, 'keine nachträgliche Berechtigungsabfrage');
|
||||
assert.ok(m.host_permissions.includes('https://*/*'), 'Zugriff auf den Server ist von Anfang an erlaubt');
|
||||
assert.match(m.content_security_policy.extension_pages, /script-src 'self'/);
|
||||
assert.doesNotMatch(m.content_security_policy.extension_pages, /unsafe-inline|unsafe-eval/);
|
||||
for (const f of Object.values(m.icons)) await readFile(new URL('../' + f, import.meta.url));
|
||||
|
||||
Reference in New Issue
Block a user