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 <aslaughter@instructure.com>
QA-Review: Alex Slaughter <aslaughter@instructure.com>
Product-Review: Alex Slaughter <aslaughter@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
Weston Dransfield 2023-01-31 09:50:49 -07:00
parent cfdcd77cbd
commit 76dfe77482
2 changed files with 51 additions and 6 deletions

View File

@ -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
}

View File

@ -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