From 76dfe77482969caf6b10ea08240689bc51cdc751 Mon Sep 17 00:00:00 2001 From: Weston Dransfield Date: Tue, 31 Jan 2023 09:50:49 -0700 Subject: [PATCH] Consider the test domain when generating asset_map_url Closes QUIZ-10736 flag=none Test Plan: - Tail the canvas-live-events kinesis stream locally - Do a course copy - Validate the `content_migration_completed` event has a `resource_map_url` using `canvas.docker` as the domain - Validate the `source_host` in the attachment matches this domain as well - Simulate Canvas beta ENV locally (pair with weston for details) - Do a course copy - Validate the `content_migration_completed` event has a `resource_map_url` that uses the configured beta domain as the domain in the file url - Validate the `source_host` in the attachment matches this domain as well Change-Id: Ic86b80f0e44d91c75b4fe2b661bad695aa3ab4a4 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/310021 Reviewed-by: Alex Slaughter QA-Review: Alex Slaughter Product-Review: Alex Slaughter Tested-by: Service Cloud Jenkins --- app/models/content_migration.rb | 15 ++++++---- spec/models/content_migration_spec.rb | 42 ++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/app/models/content_migration.rb b/app/models/content_migration.rb index 1864c90b792..103b5c66161 100644 --- a/app/models/content_migration.rb +++ b/app/models/content_migration.rb @@ -1184,10 +1184,15 @@ class ContentMigration < ActiveRecord::Base def asset_map_url(generate_if_needed: false) generate_asset_map if !asset_map_attachment && generate_if_needed - asset_map_attachment && file_download_url(asset_map_attachment, { verifier: asset_map_attachment.uuid, - download: "1", - download_frd: "1", - host: HostUrl.context_host(context) }) + asset_map_attachment && file_download_url( + asset_map_attachment, + { + verifier: asset_map_attachment.uuid, + download: "1", + download_frd: "1", + host: context.root_account.domain(ApplicationController.test_cluster_name) + } + ) end def generate_asset_map @@ -1195,7 +1200,7 @@ class ContentMigration < ActiveRecord::Base return if data.nil? payload = { - "source_host" => source_course.root_account.domain, + "source_host" => source_course.root_account.domain(ApplicationController.test_cluster_name), "source_course" => source_course_id.to_s, "resource_mapping" => data } diff --git a/spec/models/content_migration_spec.rb b/spec/models/content_migration_spec.rb index 75198fd8a46..30de1e89448 100644 --- a/spec/models/content_migration_spec.rb +++ b/spec/models/content_migration_spec.rb @@ -1206,7 +1206,7 @@ describe ContentMigration do end it "returns a url to a file containing the asset map" do - expect_any_instance_of(Account).to receive(:domain).and_return("pineapple.edu") + allow(HostUrl).to receive(:default_host).and_return("pineapple.edu") url = @cm.asset_map_url(generate_if_needed: true) @cm.reload expect(url).to include "/files/#{@cm.asset_map_attachment.id}/download" @@ -1219,5 +1219,45 @@ describe ContentMigration do "assignments" => { @old.id.to_s => @new.id.to_s } } }) end + + context "when not on a test cluster" do + let(:content_migration) do + @cm.update!(source_course: source_course) + + @cm + end + let(:source_course) { course_factory } + + before do + allow(ApplicationController).to receive(:test_cluster_name).and_return nil + allow(content_migration.context.root_account).to receive(:domain).and_return "pineapple.edu" + end + + it "uses the 'production' host" do + expect(content_migration.context.root_account).to receive(:domain).with(nil) + + content_migration.asset_map_url(generate_if_needed: true) + end + end + + context "when on a test cluster" do + let(:content_migration) do + @cm.update!(source_course: source_course) + + @cm + end + let(:source_course) { course_factory } + + before do + allow(ApplicationController).to receive(:test_cluster_name).and_return "banana" + allow(content_migration.context.root_account).to receive(:domain).and_return "pineapple.edu" + end + + it "uses the test host" do + expect(content_migration.context.root_account).to receive(:domain).with("banana") + + content_migration.asset_map_url(generate_if_needed: true) + end + end end end