save the correct url on redirect in http_multi job; be tolerant about messed up urls in the db
This commit is contained in:
parent
a9ab842242
commit
5bcc3acbbb
5 changed files with 47 additions and 25 deletions
|
|
@ -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
|
module Job
|
||||||
class HttpMulti < Base
|
class HttpMulti < Base
|
||||||
@queue = :http
|
@queue = :http
|
||||||
|
|
@ -24,7 +30,11 @@ module Job
|
||||||
request.on_complete do |response|
|
request.on_complete do |response|
|
||||||
if response.code >= 300 && response.code < 400
|
if response.code >= 300 && response.code < 400
|
||||||
if response.headers_hash['Location'] == response.request.url.sub('http://', 'https://')
|
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
|
person.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require 'uri'
|
||||||
require File.join(Rails.root, 'lib/hcard')
|
require File.join(Rails.root, 'lib/hcard')
|
||||||
|
|
||||||
class Person < ActiveRecord::Base
|
class Person < ActiveRecord::Base
|
||||||
|
|
@ -93,13 +94,25 @@ class Person < ActiveRecord::Base
|
||||||
def owns?(post)
|
def owns?(post)
|
||||||
self == post.person
|
self == post.person
|
||||||
end
|
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
|
def receive_url
|
||||||
"#{self.url}receive/users/#{self.guid}/"
|
"#{url}receive/users/#{self.guid}/"
|
||||||
end
|
end
|
||||||
|
|
||||||
def public_url
|
def public_url
|
||||||
"#{self.url}public/#{self.owner.username}"
|
"#{url}public/#{self.owner.username}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def public_key_hash
|
def public_key_hash
|
||||||
|
|
|
||||||
|
|
@ -34,22 +34,11 @@ available:
|
||||||
tr: 'Türk'
|
tr: 'Türk'
|
||||||
zh: '中文'
|
zh: '中文'
|
||||||
fallbacks:
|
fallbacks:
|
||||||
en-GB:
|
en-GB: [:en]
|
||||||
- :en
|
en-US: [:en]
|
||||||
en-US:
|
en_shaw: [:en, :en-GB, :en-US]
|
||||||
- :en
|
sv: [:sv-SE]
|
||||||
en_shaw:
|
he: [:he-IL]
|
||||||
- :en
|
es-CL: [:es]
|
||||||
- :en-GB
|
gl: [:gl-ES]
|
||||||
- :en-US
|
zh: [:zh-CN, :zh-TW]
|
||||||
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])
|
Job::HttpMulti.perform(bob.id, @post_xml, [person.id])
|
||||||
person.reload
|
person.reload
|
||||||
person.url.should =~ /https:\/\/remote.net\//
|
person.url.should == "https://remote.net/"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,21 @@ describe Person do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "vaild url" do
|
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 = Factory.create(:person, :url => "https://example.com")
|
||||||
person.should be_valid
|
person.should be_valid
|
||||||
end
|
|
||||||
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
|
describe '#diaspora_handle' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue