Commit dc356d387f39b26cb8738db07af076f428cc2ae9

Authored by AntonioTerceiro
1 parent d31f0c9f

ActionItem438: base URL must be SSL-aware

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2470 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/helpers/application_helper.rb
... ... @@ -713,4 +713,8 @@ module ApplicationHelper
713 713 url_for(options)
714 714 end
715 715  
  716 + def base_url
  717 + environment.top_url(request.ssl?)
  718 + end
  719 +
716 720 end
... ...
app/models/environment.rb
... ... @@ -256,8 +256,9 @@ class Environment < ActiveRecord::Base
256 256 end
257 257 end
258 258  
259   - def top_url
260   - result = "http://#{default_hostname}"
  259 + def top_url(ssl = false)
  260 + protocol = (ssl ? 'https' : 'http')
  261 + result = "#{protocol}://#{default_hostname}"
261 262 if Noosfero.url_options.has_key?(:port)
262 263 result << ':' << Noosfero.url_options[:port].to_s
263 264 end
... ...
app/views/layouts/application.rhtml
... ... @@ -50,7 +50,7 @@
50 50 <%# FIXME %>
51 51 <%= stylesheet_link_tag '/designs/icons/default/style.css' %>
52 52  
53   - <base href="<%= environment.top_url %>"/>
  53 + <base href="<%= base_url %>"/>
54 54 </head>
55 55  
56 56 <body class='noosfero category<%= category_color %><%=
... ...
test/unit/environment_test.rb
... ... @@ -187,6 +187,12 @@ class EnvironmentTest &lt; Test::Unit::TestCase
187 187 assert_equal 'http://www.lalala.net:9999', env.top_url
188 188 end
189 189  
  190 + should 'use https when asked for a ssl url' do
  191 + env = Environment.new
  192 + env.expects(:default_hostname).returns('www.lalala.net')
  193 + assert_equal 'https://www.lalala.net', env.top_url(true)
  194 + end
  195 +
190 196 should 'provide an approval_method setting' do
191 197 env = Environment.new
192 198  
... ...