A platform for community discussion. Free, open, simple.
DEV: Cover forged Admin Assistant drafts in specs
Régis Hanolb7e935d4f7c3
diff --git a/plugins/discourse-ai/spec/lib/agents/tools/draft_reference_spec.rb b/plugins/discourse-ai/spec/lib/agents/tools/draft_reference_spec.rbindex 1ffa2f7ca08..828fd48c7a7 100644--- a/plugins/discourse-ai/spec/lib/agents/tools/draft_reference_spec.rb+++ b/plugins/discourse-ai/spec/lib/agents/tools/draft_reference_spec.rb@@ -22,10 +22,17 @@ RSpec.describe DiscourseAi::Agents::Tools::DraftReference doexpect(draft_class.read(reference)).to be_nilend- it "rejects malformed, tampered, expired, and oversized drafts" do+ it "rejects malformed, forged, expired, and oversized drafts" doreference = draft_class.sign({ value: "safe" }, user: admin)expect(draft_class.read("#{reference}tampered")).to be_nil+ forged = draft_class.sign({ value: "forged" }, user: admin)+ Discourse.redis.set(+ "admin-assistant:draft:spec:#{forged}",+ { value: "forged", user_id: admin.id, site: Discourse.current_hostname }.to_json,+ )+ expect(draft_class.read(forged)).to be_nil+freeze_time 2.days.from_nowexpect(draft_class.read(reference)).to be_nildiff --git a/plugins/discourse-data-explorer/spec/lib/discourse_data_explorer/admin_assistant/query_tools_spec.rb b/plugins/discourse-data-explorer/spec/lib/discourse_data_explorer/admin_assistant/query_tools_spec.rbindex 95956c6dc1a..0419b9f27e4 100644--- a/plugins/discourse-data-explorer/spec/lib/discourse_data_explorer/admin_assistant/query_tools_spec.rb+++ b/plugins/discourse-data-explorer/spec/lib/discourse_data_explorer/admin_assistant/query_tools_spec.rb@@ -83,21 +83,13 @@ RSpec.describe DiscourseDataExplorer::AdminAssistant::CreateQuery doexpect(DiscourseDataExplorer::Query.count).to eq(0)end- it "rejects unauthorized, expired, tampered, and cross-site drafts" do+ it "rejects unauthorized and invalid drafts" docontext.user = userexpect(tool.validation_error[:status]).to eq("error")context.user = admintool.parameters[:draft_token] = "#{token}tampered"expect(tool.validation_error[:status]).to eq("error")-- tool.parameters[:draft_token] = token- freeze_time 2.days.from_now- expect(tool.validation_error[:status]).to eq("error")-- freeze_time 2.days.ago- Discourse.stubs(:current_hostname).returns("another.example.com")- expect(DiscourseDataExplorer::AdminAssistant::QueryDraft.read(token)).to be_nilendit "rechecks public capability and requester authorization at approval time" dodiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/admin_assistant/workflow_tools_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/admin_assistant/workflow_tools_spec.rbindex 2a9c34aafe3..49b335129d1 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/admin_assistant/workflow_tools_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/admin_assistant/workflow_tools_spec.rb@@ -241,15 +241,10 @@ RSpec.describe DiscourseWorkflows::AdminAssistant::CreateWorkflow doexpect(tool.validation_error[:status]).to eq("error")end- it "rejects invalid, expired, and malformed graph drafts" do+ it "rejects invalid and malformed graph drafts" dotool.parameters[:draft_token] = token + "tampered"expect(tool.validation_error[:status]).to eq("error")- tool.parameters[:draft_token] = token- freeze_time 2.days.from_now- expect(tool.validation_error[:status]).to eq("error")-- freeze_time 2.days.agomalformed =DiscourseWorkflows::AdminAssistant::WorkflowDraft.sign({ name: "Broken", operations: [{ op: "add_node", node: { type: "missing", name: "X" } }] },