Allow Chrome OS LTS

Chrome OS has a long-term support (LTS) channel which is updated every
6 months. Some schooles have chosen to use this channel for their Chrome
OS updates. Unfortunately, the LTS distinction is not reflected in the
User-Agent string.

This change checks if the browser is Chrome running on Chrome OS and
compares it to the minimum version specified in the configuration file.

This does mean means that slightly older versions of Chrome on non-LTS
Chrome OS will also be be allowed to run Canvas without warnings, but
that's better than not allowing LTS versions to be supported at all.

flag=none
Closes FOO-3343

Test Plan:
  - Visit a page in Canvas with a browser that is running an LTS version
  of Chrome OS that is older than the latest support Chrome.
  - You can spoof this in Chrome dev tools by changing the User-Agent
     under "... > More Tools > Network Conditions".

Change-Id: Ic9cadd20a6170f144103249daba6d729ba41e47c
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/311263
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Charley Kline <ckline@instructure.com>
Product-Review: Charley Kline <ckline@instructure.com>
QA-Review: Charley Kline <ckline@instructure.com>
This commit is contained in:
Jason L Perry 2023-02-15 16:35:35 -05:00 committed by Jason Perry
parent 688398d446
commit b581fefca9
3 changed files with 69 additions and 0 deletions

View File

@ -12,3 +12,6 @@ minimums:
chrome: 107
safari: 14
firefox: 91
chrome_os_lts:
chrome: 102
platform: 14695

View File

@ -24,6 +24,7 @@ BrowserSupport = Struct.new(:browser, :version) do
def supported?(user_agent)
browser = Browser.new(user_agent)
return true if respondus? browser
return true if chrome_os_lts? browser
return false if minimum_browsers.any? { |min| browser.send("#{min.browser}?", "<#{min.version}") }
true # if we don't recognize it (e.g. Android), be nice
@ -40,6 +41,10 @@ BrowserSupport = Struct.new(:browser, :version) do
private
def lts
@lts = OpenStruct.new(configuration["chrome_os_lts"])
end
#
# Respondus lockdown browser includes a telltale in the User-Agent string which
# is platform-dependent. Hopefully this never needs to be modified.
@ -50,5 +55,19 @@ BrowserSupport = Struct.new(:browser, :version) do
false
end
#
# Chrome OS has a long-term support (LTS) channel which is updated every 6 months.
# Unfortunately, the LTS distinction is not reflected in the User-Agent string.
# This method checks if the browser is Chrome running on Chrome OS and compares it
# to the specific major LTS version specified in the configuration file.
#
def chrome_os_lts?(browser)
return false unless browser.platform.chrome_os?
return false unless browser.chrome?(lts.chrome)
return true if /X11; CrOS \w+ #{lts.platform}/.match?(browser.ua)
false
end
end
end

View File

@ -0,0 +1,47 @@
# frozen_string_literal: true
#
# Copyright (C) 2023 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
describe BrowserSupport do
let(:chrome_macos_110) { "Mozilla/5.0 (Macintosh; Intel Mac OS X 13_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" }
let(:chrome_macos_102) { "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.167 Safari/537.36" }
let(:chrome_os_102) { "Mozilla/5.0 (X11; CrOS aarch64 14695.115.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36" }
let(:chrome_os_101) { "Mozilla/5.0 (X11; CrOS aarch64 14588.98.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36" }
before do
allow(BrowserSupport).to receive(:configuration).and_return({ "minimums" => { "chrome" => 107 },
"chrome_os_lts" => { "chrome" => 102, "platform" => 14_695 } })
end
it "supports latest Chrome" do
expect(BrowserSupport.supported?(chrome_macos_110)).to be true
end
it "supports latest LTS for Chrome OS" do
expect(BrowserSupport.supported?(chrome_os_102)).to be true
end
it "does not support outdated Chrome" do
expect(BrowserSupport.supported?(chrome_macos_102)).to be false
end
it "does not support outdated Chrome for Chrome OS" do
expect(BrowserSupport.supported?(chrome_os_101)).to be false
end
end