Fallseite bei gescheitertem Scan und Schnappschuss bei untypischen Elementen
This commit is contained in:
6 files changed
+34
-3
No files matched your search
+1
-1
@@ -63,7 +63,7 @@ SNAPSHOT_JS = """
|
||||
else if (wrap && tag !== 'label') label = wrap.innerText + ' ' + label;
|
||||
const item = {n, tag, type, label: label.replace(/\\s+/g, ' ').trim().slice(0, maxLabel)};
|
||||
if (tag === 'select') item.options = Array.from(el.options).map(o => o.text.trim()).slice(0, maxOptions);
|
||||
if (type === 'checkbox' || type === 'radio') item.checked = el.checked;
|
||||
if (tag === 'input' && (type === 'checkbox' || type === 'radio')) item.checked = el.checked;
|
||||
elements.push(item);
|
||||
}
|
||||
const captcha = !!document.querySelector(
|
||||
|
||||
@@ -37,6 +37,8 @@ PAGES = {
|
||||
"<form><input type='password' name='pw'><button>Abmelden</button></form>",
|
||||
"/frame-password": "<p>Abmelden</p><iframe src='/pwframe'></iframe><button>Abmelden bestätigen</button>",
|
||||
"/pwframe": "<form><input type='text' name='u'><input type='password' name='pw'></form>",
|
||||
# a button that carries type=radio has no "checked" property of its own
|
||||
"/odd-type": "<p>Bitte bestätigen</p><button type='radio'>Abmelden bestätigen</button>",
|
||||
# overrides Array.prototype.push, which the snapshot script uses, to plant a prompt marker in an element number
|
||||
"/tamper-push": "<p>Bitte bestätigen</p><button>Abmelden bestätigen</button><script>"
|
||||
"const push = Array.prototype.push; Array.prototype.push = function (...items) {"
|
||||
|
||||
@@ -221,6 +221,13 @@ def test_embedded_private_content_is_blocked_but_the_page_still_works(browser, s
|
||||
assert "http://192.168.8.111/pixel.gif" in refused # the embedded request was made and refused
|
||||
|
||||
|
||||
def test_non_input_element_with_checkbox_type_is_not_a_page_error(browser, site):
|
||||
llm = Script('{"action":"done","result":"unclear","reason":"seen"}')
|
||||
r = run(browser, site, "/odd-type", llm)
|
||||
assert r["reason"] != "page_error" and len(llm.prompts) == 1
|
||||
assert '[1] button' in llm.prompts[0] and 'Abmelden bestätigen"' in llm.prompts[0] # offered as an element
|
||||
|
||||
|
||||
def test_page_that_tampers_with_the_snapshot_ends_as_page_error_without_the_model(browser, site):
|
||||
llm = Script()
|
||||
r = run(browser, site, "/tamper-push", llm)
|
||||
|
||||
@@ -24,7 +24,7 @@ from flask import Flask, abort, redirect, render_template, request, url_for
|
||||
|
||||
from cases import CaseStore
|
||||
from oauth import MailboxOAuth, OAuthError, xoauth2_string
|
||||
from worker import AgentUnavailable, Worker, _tick, start_scheduler
|
||||
from worker import AgentUnavailable, ScanFailed, Worker, _tick, start_scheduler
|
||||
|
||||
load_dotenv() # optional .env for local runs
|
||||
|
||||
@@ -267,13 +267,17 @@ def result():
|
||||
finally:
|
||||
mail.logout()
|
||||
return render_template("result.html", links_data=links_data)
|
||||
uids = scan_inbox()
|
||||
try:
|
||||
uids, scan_failed = scan_inbox(), False
|
||||
except ScanFailed: # show what is stored; without the inbox no mail can be offered for trash or retry
|
||||
uids, scan_failed = {}, True
|
||||
cases = [dict(c, uid=uids[c["key"]].decode() if c["key"] in uids else "", label=STATE_LABELS[c["state"]])
|
||||
for c in STORE.all()]
|
||||
last = json.loads(STORE.meta("last_run", "{}"))
|
||||
at = STORE.meta("last_run_at")
|
||||
return render_template(
|
||||
"cases.html", cases=cases, last=last, agent=bool(AGENT_URL), paused=STORE.meta("paused") == "1",
|
||||
scan_failed=scan_failed,
|
||||
last_at=datetime.datetime.fromtimestamp(int(at)).strftime("%Y-%m-%d %H:%M") if at else "never")
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
{% if last.get('deferred') %}{{ last['deferred'] }} case(s) waiting for the model.{% endif %}{% endif %}
|
||||
</p>
|
||||
{% if last.get('error') %}<p class="error">Last run: {{ last['error'] }}</p>{% endif %}
|
||||
{% if scan_failed %}<p class="error">The inbox could not be read: the list shows the stored cases only.</p>{% endif %}
|
||||
{% if not agent %}<p class="error">The agent is switched off: cases are listed, nothing is unsubscribed automatically.</p>{% endif %}
|
||||
<form action="{{ url_for('run_now') }}" method="post">
|
||||
<button type="submit" class="btn-primary">Run now</button>
|
||||
|
||||
@@ -52,6 +52,23 @@ def test_result_shows_cases_with_state_reason_evidence_and_links(unsub, monkeypa
|
||||
assert "2 mail(s) from senders that are not allowed" in html
|
||||
|
||||
|
||||
def test_result_still_lists_cases_when_the_inbox_scan_fails(unsub, monkeypatch):
|
||||
from worker import ScanFailed
|
||||
s = unsub.STORE
|
||||
s.add("<no@x>", "Fwd: Bank", ["https://bank.example/u"], "")
|
||||
s.claim("<no@x>")
|
||||
s.finish("<no@x>", "not_possible", "login")
|
||||
|
||||
def failing():
|
||||
raise ScanFailed("inbox scan failed")
|
||||
monkeypatch.setattr(unsub, "scan_inbox", failing)
|
||||
response = unsub.app.test_client().get("/result")
|
||||
html = response.get_data(as_text=True)
|
||||
assert response.status_code == 200
|
||||
assert "Fwd: Bank" in html and "The inbox could not be read" in html
|
||||
assert 'name="email_id"' not in html and 'action="/retry"' not in html # nothing is known about the mails
|
||||
|
||||
|
||||
def test_max_deferrals_default_and_from_environment(unsub, monkeypatch):
|
||||
import app
|
||||
assert unsub.WORKER.max_deferrals == 12
|
||||
|
||||
Reference in new issue
Block a user