diff --git a/app/models/environment.rb b/app/models/environment.rb
index b59dce4..1f8ba4e 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -13,7 +13,9 @@ class Environment < ActiveRecord::Base
:reports_lower_bound, :noreply_email,
:signup_welcome_screen_body, :members_whitelist_enabled,
:members_whitelist, :highlighted_news_amount,
- :portal_news_amount, :date_format, :signup_intro
+ :portal_news_amount, :date_format, :signup_intro,
+ :enable_feed_proxy, :http_feed_proxy, :https_feed_proxy,
+ :disable_feed_ssl
has_many :users
diff --git a/app/views/features/index.html.erb b/app/views/features/index.html.erb
index 9280cd1..017f53a 100644
--- a/app/views/features/index.html.erb
+++ b/app/views/features/index.html.erb
@@ -49,6 +49,25 @@ Check all the features you want to enable for your environment, uncheck all the
+<%= _('Feed') %>
+
+ <%= check_box :environment, :enable_feed_proxy %>
+
+
+
+
+
+ <%= check_box :environment, :disable_feed_ssl %>
+
+
+
+
<% button_bar do %>
<%= submit_button('save', _('Save changes')) %>
diff --git a/db/migrate/20160408011124_add_enable_feed_proxy_to_environments.rb b/db/migrate/20160408011124_add_enable_feed_proxy_to_environments.rb
new file mode 100644
index 0000000..c086b25
--- /dev/null
+++ b/db/migrate/20160408011124_add_enable_feed_proxy_to_environments.rb
@@ -0,0 +1,5 @@
+class AddEnableFeedProxyToEnvironments < ActiveRecord::Migration
+ def change
+ add_column :environments, :enable_feed_proxy, :boolean, default: false
+ end
+end
diff --git a/db/migrate/20160408011622_add_http_feed_proxy_to_environments.rb b/db/migrate/20160408011622_add_http_feed_proxy_to_environments.rb
new file mode 100644
index 0000000..9d581db
--- /dev/null
+++ b/db/migrate/20160408011622_add_http_feed_proxy_to_environments.rb
@@ -0,0 +1,5 @@
+class AddHttpFeedProxyToEnvironments < ActiveRecord::Migration
+ def change
+ add_column :environments, :http_feed_proxy, :string
+ end
+end
diff --git a/db/migrate/20160408011635_add_https_feed_proxy_to_environments.rb b/db/migrate/20160408011635_add_https_feed_proxy_to_environments.rb
new file mode 100644
index 0000000..72b5bcd
--- /dev/null
+++ b/db/migrate/20160408011635_add_https_feed_proxy_to_environments.rb
@@ -0,0 +1,5 @@
+class AddHttpsFeedProxyToEnvironments < ActiveRecord::Migration
+ def change
+ add_column :environments, :https_feed_proxy, :string
+ end
+end
diff --git a/db/migrate/20160408011720_add_disable_feed_ssl_to_environments.rb b/db/migrate/20160408011720_add_disable_feed_ssl_to_environments.rb
new file mode 100644
index 0000000..33bfebc
--- /dev/null
+++ b/db/migrate/20160408011720_add_disable_feed_ssl_to_environments.rb
@@ -0,0 +1,5 @@
+class AddDisableFeedSslToEnvironments < ActiveRecord::Migration
+ def change
+ add_column :environments, :disable_feed_ssl, :boolean, default: false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 4bd567b..586cf3e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20160324132518) do
+ActiveRecord::Schema.define(version: 20160408011720) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -390,6 +390,10 @@ ActiveRecord::Schema.define(version: 20160324132518) do
t.string "noreply_email"
t.string "redirection_after_signup", default: "keep_on_same_page"
t.string "date_format", default: "month_name_with_year"
+ t.boolean "enable_feed_proxy", default: false
+ t.string "http_feed_proxy"
+ t.string "https_feed_proxy"
+ t.boolean "disable_feed_ssl", default: false
end
create_table "external_feeds", force: :cascade do |t|
diff --git a/lib/feed_handler.rb b/lib/feed_handler.rb
index b360b0a..6824f8a 100644
--- a/lib/feed_handler.rb
+++ b/lib/feed_handler.rb
@@ -42,13 +42,21 @@ class FeedHandler
if !valid_url?(address)
raise InvalidUrl.new("\"%s\" is not a valid URL" % address)
end
+
header = {"User-Agent" => "Noosfero/#{Noosfero::VERSION}"}
- if address.starts_with?("https://")
- header.merge!(:proxy => ENV['FEED_HTTPS_PROXY']) if ENV['FEED_HTTPS_PROXY']
- else
- header.merge!(:proxy => ENV['FEED_HTTP_PROXY']) if ENV['FEED_HTTP_PROXY']
+
+ environment = Environment.default
+
+ if environment.enable_feed_proxy
+ if address.starts_with?("https://")
+ header.merge!(:proxy => environment.https_feed_proxy) if environment.https_feed_proxy
+ else
+ header.merge!(:proxy => environment.http_feed_proxy) if environment.http_feed_proxy
+ end
end
- header.merge!(:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE) if ENV['SSL_VERIFY_NONE']
+
+ header.merge!(:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE) if environment.disable_feed_ssl
+
open(address, header, &block)
end
return content
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index 8ca3449..46faee7 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -1723,4 +1723,42 @@ class EnvironmentTest < ActiveSupport::TestCase
refute environment.errors[:date_format.to_s].present?
end
+ should 'respond to enable_feed_proxy' do
+ assert_respond_to Environment.new, :enable_feed_proxy
+ end
+
+ should 'set enable_feed_proxy on environment' do
+ e = fast_create(Environment, :name => 'Enterprise test')
+ e.enable_feed_proxy = true
+ e.save
+ assert_equal true, e.enable_feed_proxy
+ end
+
+ should 'not enable feed proxy when enable by default' do
+ assert_equal false, Environment.new.enable_feed_proxy
+ end
+
+ should 'respond to disable_feed_ssl' do
+ assert_respond_to Environment.new, :disable_feed_ssl
+ end
+
+ should 'set disable_feed_ssl on environment' do
+ e = fast_create(Environment, :name => 'Enterprise test')
+ e.disable_feed_ssl = true
+ e.save
+ assert_equal true, e.disable_feed_ssl
+ end
+
+ should 'not disable feed ssl when enable by default' do
+ assert_equal false, Environment.new.disable_feed_ssl
+ end
+
+ should 'respond to http_feed_proxy' do
+ assert_respond_to Environment.new, :http_feed_proxy
+ end
+
+ should 'respond to https_feed_proxy' do
+ assert_respond_to Environment.new, :https_feed_proxy
+ end
+
end
diff --git a/test/unit/feed_handler_test.rb b/test/unit/feed_handler_test.rb
index 5fbe98d..4da7c83 100644
--- a/test/unit/feed_handler_test.rb
+++ b/test/unit/feed_handler_test.rb
@@ -5,14 +5,13 @@ class FeedHandlerTest < ActiveSupport::TestCase
def setup
@handler = FeedHandler.new
@container = nil
- ENV.stubs('[]').with(anything)
end
attr_reader :handler
def container
@container ||= create(:feed_reader_block)
end
- should 'fetch feed content' do
+ should 'fetch feed content with proxy disabled and SSL enabled' do
content = handler.fetch(container.address)
assert_match /Feed content<\/description>/, content
assert_match /Feed for unit tests<\/title>/, content
@@ -84,7 +83,11 @@ class FeedHandlerTest < ActiveSupport::TestCase
end
should 'identifies itself as noosfero user agent' do
+ Environment.any_instance.expects(:enable_feed_proxy).returns(false)
+ Environment.any_instance.expects(:disable_feed_ssl).returns(false)
+
handler.expects(:open).with('http://site.org/feed.xml', {"User-Agent" => "Noosfero/#{Noosfero::VERSION}"}, anything).returns('bli content')
+
assert_equal 'bli content', handler.fetch('http://site.org/feed.xml')
end
@@ -150,35 +153,52 @@ class FeedHandlerTest < ActiveSupport::TestCase
end
end
- should 'set proxy when FEED_HTTP_PROXY is setted from env' do
- ENV.stubs('[]').with('FEED_HTTP_PROXY').returns('http://127.0.0.1:3128')
+ should 'set proxy when http_feed_proxy is setted from env' do
+ Environment.any_instance.expects(:enable_feed_proxy).returns(true)
+ Environment.any_instance.expects(:disable_feed_ssl).returns(false)
+ Environment.any_instance.expects(:http_feed_proxy).twice.returns('http://127.0.0.1:3128')
+
handler.expects(:open).with('http://site.org/feed.xml', {"User-Agent" => "Noosfero/#{Noosfero::VERSION}", :proxy => 'http://127.0.0.1:3128'}, anything).returns('bli content')
+
assert_equal 'bli content', handler.fetch('http://site.org/feed.xml')
end
- should 'set proxy when FEED_HTTPS_PROXY is setted from env' do
- ENV.stubs('[]').with('FEED_HTTPS_PROXY').returns('http://127.0.0.1:3128')
+ should 'set proxy when https_feed_proxy is setted from env' do
+ Environment.any_instance.expects(:enable_feed_proxy).returns(true)
+ Environment.any_instance.expects(:disable_feed_ssl).returns(false)
+ Environment.any_instance.expects(:https_feed_proxy).twice.returns('http://127.0.0.1:3128')
+
handler.expects(:open).with('https://site.org/feed.xml', {"User-Agent" => "Noosfero/#{Noosfero::VERSION}", :proxy => 'http://127.0.0.1:3128'}, anything).returns('bli content')
+
assert_equal 'bli content', handler.fetch('https://site.org/feed.xml')
end
should 'use https proxy for https address when both env variables were defined' do
- ENV.stubs('[]').with('FEED_HTTPS_PROXY').returns('http://127.0.0.2:3128')
- ENV.stubs('[]').with('FEED_HTTP_PROXY').returns('http://127.0.0.1:3128')
+ Environment.any_instance.expects(:enable_feed_proxy).returns(true)
+ Environment.any_instance.expects(:disable_feed_ssl).returns(false)
+ Environment.any_instance.expects(:https_feed_proxy).twice.returns('http://127.0.0.2:3128')
+
handler.expects(:open).with('https://site.org/feed.xml', {"User-Agent" => "Noosfero/#{Noosfero::VERSION}", :proxy => 'http://127.0.0.2:3128'}, anything).returns('bli content')
+
assert_equal 'bli content', handler.fetch('https://site.org/feed.xml')
end
should 'use http proxy for http address when both env variables were defined' do
- ENV.stubs('[]').with('FEED_HTTPS_PROXY').returns('http://127.0.0.2:3128')
- ENV.stubs('[]').with('FEED_HTTP_PROXY').returns('http://127.0.0.1:3128')
+ Environment.any_instance.expects(:enable_feed_proxy).returns(true)
+ Environment.any_instance.expects(:disable_feed_ssl).returns(false)
+ Environment.any_instance.expects(:http_feed_proxy).twice.returns('http://127.0.0.1:3128')
+
handler.expects(:open).with('http://site.org/feed.xml', {"User-Agent" => "Noosfero/#{Noosfero::VERSION}", :proxy => 'http://127.0.0.1:3128'}, anything).returns('bli content')
+
assert_equal 'bli content', handler.fetch('http://site.org/feed.xml')
end
should 'not verify ssl when define env parameter SSL_VERIFY_NONE' do
- ENV.stubs('[]').with('SSL_VERIFY_NONE').returns(true)
+ Environment.any_instance.expects(:enable_feed_proxy).returns(false)
+ Environment.any_instance.expects(:disable_feed_ssl).returns(true)
+
handler.expects(:open).with('http://site.org/feed.xml', {"User-Agent" => "Noosfero/#{Noosfero::VERSION}", :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE}, anything)
+
handler.fetch('http://site.org/feed.xml')
end
--
libgit2 0.21.2