From d97448e5523f1a8614fe9297356ecfabbc4d1360 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 14 Mar 2016 01:56:42 +0100 Subject: [PATCH] remove ChromeFrame Google Chrome Frame was a plugin for Internet Explorer, but is no longer supported. And it was included with http and not https which triggered a warning on most pods. Also set the minimum version to 9 to support #6557 closes #6751 --- Changelog.md | 1 + config.ru | 12 ++-- lib/rack/chrome_frame.rb | 71 ------------------- lib/rack/internet_explorer_version.rb | 41 +++++++++++ spec/lib/rack/chrome_frame_spec.rb | 63 ---------------- .../rack/internet_explorer_version_spec.rb | 48 +++++++++++++ 6 files changed, 96 insertions(+), 140 deletions(-) delete mode 100644 lib/rack/chrome_frame.rb create mode 100644 lib/rack/internet_explorer_version.rb delete mode 100644 spec/lib/rack/chrome_frame_spec.rb create mode 100644 spec/lib/rack/internet_explorer_version_spec.rb diff --git a/Changelog.md b/Changelog.md index e8448ec6b..7a73c4745 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,6 +11,7 @@ ## Features * Added the footer to conversation pages [#6710](https://github.com/diaspora/diaspora/pull/6710) +* Drop ChromeFrame and display an error page on old IE versions instead [#6751](https://github.com/diaspora/diaspora/pull/6751) # 0.5.7.1 diff --git a/config.ru b/config.ru index 9603dbba3..e25248600 100644 --- a/config.ru +++ b/config.ru @@ -1,19 +1,19 @@ - # Copyright (c) 2010-2011, Diaspora Inc. This file is +# Copyright (c) 2010-2011, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) -require ::File.expand_path('../lib/unicorn_killer', __FILE__) -require ::File.expand_path('../lib/rack/chrome_frame', __FILE__) +require ::File.expand_path("../config/environment", __FILE__) +require ::File.expand_path("../lib/unicorn_killer", __FILE__) +require ::File.expand_path("../lib/rack/internet_explorer_version", __FILE__) -# Kill unicorn workers really agressively (at 300mb) +# Kill unicorn workers really aggressively (at 300mb) if defined?(Unicorn) use UnicornKiller::Oom, 300 * 1024 end use Rack::Deflater -use Rack::ChromeFrame, :minimum => 8 +use Rack::InternetExplorerVersion, minimum: 9 use Rack::Protection::FrameOptions run Diaspora::Application diff --git a/lib/rack/chrome_frame.rb b/lib/rack/chrome_frame.rb deleted file mode 100644 index 3e4955cf8..000000000 --- a/lib/rack/chrome_frame.rb +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -module Rack - class ChromeFrame - - def initialize(app, options={}) - @app = app - @options = options - end - - def call(env) - - if env['HTTP_USER_AGENT'] =~ /MSIE/ - if env['HTTP_USER_AGENT'] =~ /chromeframe/ - status, headers, response = @app.call(env) - new_body = insert_tag(build_response_body(response)) - new_headers = recalculate_body_length(headers, new_body) - return [status, new_headers, [new_body]] - elsif @options[:minimum].nil? or ie_version(env['HTTP_USER_AGENT']) < @options[:minimum] - html = <<-HTML - - - - - Diaspora doesn't support your version of Internet Explorer. Try Chrome, Firefox, or Opera! - - -
- - - - - HTML - return [200, {'Content-Type' => 'text/html', 'Content-Length' => html.size.to_s}, Rack::Response.new([html])] - end - end - @app.call(env) - end - - def build_response_body(response) - response_body = "" - response.each { |part| response_body += part } - - # see: http://johnbintz.github.com/blog/2012/03/05/closing-given-body-in-rack-middleware/ - response.close if response.respond_to?(:close) - - response_body - end - - def recalculate_body_length(headers, body) - new_headers = headers - new_headers["Content-Length"] = body.length.to_s - new_headers - end - - def insert_tag(body) - head = <<-HEAD - - HEAD - - body.gsub!(//, "\n" + head ) - body - end - - def ie_version(ua_string) - ua_string.match(/MSIE ?(\S+)/)[1].to_f - end - end -end diff --git a/lib/rack/internet_explorer_version.rb b/lib/rack/internet_explorer_version.rb new file mode 100644 index 000000000..4d3b44468 --- /dev/null +++ b/lib/rack/internet_explorer_version.rb @@ -0,0 +1,41 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +module Rack + class InternetExplorerVersion + def initialize(app, options={}) + @app = app + @options = options + end + + def call(env) + if env["HTTP_USER_AGENT"] =~ /MSIE/ && ie_version(env["HTTP_USER_AGENT"]) < @options[:minimum] + html = <<-HTML + + + + + Diaspora doesn't support your version of Internet Explorer. Try Firefox, Chrome or Opera! + + +

Diaspora doesn't support your version of Internet Explorer.

+ You can use one of these browsers (and many more): + + + + HTML + return [200, {"Content-Type" => "text/html", "Content-Length" => html.size.to_s}, Rack::Response.new([html])] + end + @app.call(env) + end + + def ie_version(ua_string) + ua_string.match(/MSIE ?(\S+)/)[1].to_f + end + end +end diff --git a/spec/lib/rack/chrome_frame_spec.rb b/spec/lib/rack/chrome_frame_spec.rb deleted file mode 100644 index e7feaf15d..000000000 --- a/spec/lib/rack/chrome_frame_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -require 'spec_helper' - -describe Rack::ChromeFrame do - - before :all do - @app = Rack::Builder.parse_file(Rails.root.join('config.ru').to_s).first - end - - before :each do - @response = get_response_for_user_agent(@app, ua_string); - end - - subject { @response } - - context "non-IE browser" do - let(:ua_string) { "another browser chromeframe" } - - it "shouldn't complain about the browser and shouldn't have chrome frame" do - expect(subject.body).not_to match(/chrome=1/) - expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) - end - end - - context "IE8 without chromeframe" do - let(:ua_string) { "MSIE 8" } - - it "shouldn't complain about the browser and shouldn't have chrome frame" do - expect(subject.body).not_to match(/chrome=1/) - expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) - end - end - - context "IE7 without chromeframe" do - let(:ua_string) { "MSIE 7" } - - it "should complain about the browser" do - expect(subject.body).not_to match(/chrome=1/) - expect(subject.body).to match(/Diaspora doesn't support your version of Internet Explorer/) - end - specify {expect(@response.headers["Content-Length"]).to eq(@response.body.length.to_s)} - end - - context "any IE with chromeframe" do - let(:ua_string) { "MSIE number chromeframe" } - - it "shouldn't complain about the browser and should have chrome frame" do - expect(subject.body).to match(/chrome=1/) - expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) - end - specify {expect(@response.headers["Content-Length"]).to eq(@response.body.length.to_s)} - end - - context "Specific case with no space after MSIE" do - let(:ua_string) { "Mozilla/4.0 (compatible; MSIE8.0; Windows NT 6.0) .NET CLR 2.0.50727" } - - it "shouldn't complain about the browser" do - expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) - end - end -end diff --git a/spec/lib/rack/internet_explorer_version_spec.rb b/spec/lib/rack/internet_explorer_version_spec.rb new file mode 100644 index 000000000..2bc7a75c0 --- /dev/null +++ b/spec/lib/rack/internet_explorer_version_spec.rb @@ -0,0 +1,48 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. +require "spec_helper" + +describe Rack::InternetExplorerVersion do + before :all do + @app = Rack::Builder.parse_file(Rails.root.join("config.ru").to_s).first + end + + subject { get_response_for_user_agent(@app, ua_string) } + + context "non-IE browser" do + let(:ua_string) { "another browser chromeframe" } + + it "shouldn't complain about the browser" do + expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) + end + end + + context "new IE" do + let(:ua_string) { "MSIE 9" } + + it "shouldn't complain about the browser" do + expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) + end + end + + context "old IE" do + let(:ua_string) { "MSIE 7" } + + it "should complain about the browser" do + expect(subject.body).to match(/Diaspora doesn't support your version of Internet Explorer/) + end + + it "should have the correct content-length header" do + expect(subject.headers["Content-Length"]).to eq(subject.body.length.to_s) + end + end + + context "Specific case with no space after MSIE" do + let(:ua_string) { "Mozilla/4.0 (compatible; MSIE8.0; Windows NT 6.0) .NET CLR 2.0.50727" } + + it "should complain about the browser" do + expect(subject.body).to match(/Diaspora doesn't support your version of Internet Explorer/) + end + end +end