Commit 5bcc3acb authored by MrZYX's avatar MrZYX
Browse files

save the correct url on redirect in http_multi job; be tolerant about messed up urls in the db

parent a9ab8422
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'uri'
module Job
class HttpMulti < Base
@queue = :http
......@@ -24,7 +30,11 @@ module Job
request.on_complete do |response|
if response.code >= 300 && response.code < 400
if response.headers_hash['Location'] == response.request.url.sub('http://', 'https://')
person.url = response.headers_hash['Location']
location = URI.parse(response.headers_hash['Location'])
newuri = "#{location.scheme}://#{location.host}"
newuri += ":#{location.port}" unless ["80", "443"].include?(location.port.to_s)
newuri += "/"
person.url = newuri
person.save
end
end
......
......@@ -2,6 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'uri'
require File.join(Rails.root, 'lib/hcard')
class Person < ActiveRecord::Base
......@@ -93,13 +94,25 @@ class Person < ActiveRecord::Base
def owns?(post)
self == post.person
end
def url
begin
uri = URI.parse(@attributes['url'])
url = "#{uri.scheme}://#{uri.host}"
url += ":#{uri.port}" unless ["80", "443"].include?(uri.port.to_s)
url += "/"
rescue Exception => e
url = @attributes['url']
end
url
end
def receive_url
"#{self.url}receive/users/#{self.guid}/"
"#{url}receive/users/#{self.guid}/"
end
def public_url
"#{self.url}public/#{self.owner.username}"
"#{url}public/#{self.owner.username}"
end
def public_key_hash
......
......@@ -34,22 +34,11 @@ available:
tr: 'Türk'
zh: '中文'
fallbacks:
en-GB:
- :en
en-US:
- :en
en_shaw:
- :en
- :en-GB
- :en-US
sv:
- :sv-SE
he:
- :he-IL
es-CL:
- :es
gl:
- :gl-ES
zh:
- :zh-CN
- :zh-TW
en-GB: [:en]
en-US: [:en]
en_shaw: [:en, :en-GB, :en-US]
sv: [:sv-SE]
he: [:he-IL]
es-CL: [:es]
gl: [:gl-ES]
zh: [:zh-CN, :zh-TW]
......@@ -72,6 +72,6 @@ describe Job::HttpMulti do
Job::HttpMulti.perform(bob.id, @post_xml, [person.id])
person.reload
person.url.should =~ /https:\/\/remote.net\//
person.url.should == "https://remote.net/"
end
end
......@@ -20,11 +20,21 @@ describe Person do
end
describe "vaild url" do
it 'should allow for https urls' do
it 'should allow for https urls' do
person = Factory.create(:person, :url => "https://example.com")
person.should be_valid
end
end
it 'should always return the correct receive url' do
person = Factory.create(:person, :url => "https://example.com/a/bit/messed/up")
person.receive_url.should == "https://example.com/receive/users/#{person.guid}/"
end
it 'should allow ports in the url' do
person = Factory.create(:person, :url => "https://example.com:3000/")
person.url.should == "https://example.com:3000/"
end
end
describe '#diaspora_handle' do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment