diff --git a/apps/dashboard/app/models/motd_file.rb b/apps/dashboard/app/models/motd_file.rb index 7368593a77..8ff16a3d08 100644 --- a/apps/dashboard/app/models/motd_file.rb +++ b/apps/dashboard/app/models/motd_file.rb @@ -61,7 +61,17 @@ def exist? private def load(motd_uri) - motd_uri ? open(motd_uri).read : nil + uri = URI.parse(motd_uri) + + case uri.scheme + when 'http', 'https' + uri.read + when nil + File.read(uri.to_s) + else + Rails.logger.warn("Unknown scheme for #{motd_uri}. No MOTD is loaded") + nil + end rescue Errno::ENOENT Rails.logger.warn "MOTD File is missing; it was expected at #{motd_uri}" nil diff --git a/apps/dashboard/test/models/motd_file_test.rb b/apps/dashboard/test/models/motd_file_test.rb index 7c953028c3..5a6fbc71c3 100644 --- a/apps/dashboard/test/models/motd_file_test.rb +++ b/apps/dashboard/test/models/motd_file_test.rb @@ -40,4 +40,13 @@ class MotdFileTest < ActiveSupport::TestCase assert_equal '', motd_file.content end + test 'when rss is a remote source' do + with_modified_env({ MOTD_PATH: 'https://www.osc.edu/rss.xml', MOTD_FORMAT: 'rss' }) do + formatter = MotdFile.new.formatter + assert_not_nil(formatter.title) + assert_not_nil(formatter.content) + assert_not_nil(formatter.content.items) + end + end + end diff --git a/apps/dashboard/test/models/motd_test.rb b/apps/dashboard/test/models/motd_test.rb deleted file mode 100644 index 7f05e64997..0000000000 --- a/apps/dashboard/test/models/motd_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'test_helper' - -class MotdTest < ActiveSupport::TestCase - - test "test when motd valid" do - - path = "#{Rails.root}/test/fixtures/files/motd_valid" - motd_file = MotdFile.new(path) - expected_file = File.open(path).read - - assert_equal true, motd_file.exist? - assert_equal path, motd_file.motd_path - assert_equal expected_file, motd_file.content - end - - test "test when motd empty" do - path = "#{Rails.root}/test/fixtures/files/motd_empty" - motd_file = MotdFile.new(path) - - assert_equal true, motd_file.exist? - assert_equal path, motd_file.motd_path - assert_equal '', motd_file.content - end - - test "test when motd missing" do - path = "#{Rails.root}/test/fixtures/files/motd_missing" - motd_file = MotdFile.new(path) - - assert_equal false, motd_file.exist? - assert_equal path, motd_file.motd_path - assert_equal '', motd_file.content - end - - test "test when motd nil" do - - motd_file = MotdFile.new(nil) - - assert_equal false, motd_file.exist? - assert_nil motd_file.motd_path - assert_equal '', motd_file.content - end - -end