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

This commit is contained in:
MrZYX 2011-02-26 13:37:10 +01:00
parent a9ab842242
commit 5bcc3acbbb
5 changed files with 47 additions and 25 deletions

View file

@ -1,3 +1,9 @@
# 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

View file

@ -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
@ -94,12 +95,24 @@ class Person < ActiveRecord::Base
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

View file

@ -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]

View file

@ -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

View file

@ -20,12 +20,22 @@ 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
context 'local people' do