Person.by_webfinger preserves case of identifier. Backfill specs for PublicsController#webfinger.
This commit is contained in:
parent
50f9e8f240
commit
fcdcf88a79
3 changed files with 74 additions and 40 deletions
|
|
@ -36,12 +36,12 @@ class Person
|
|||
def self.search(query)
|
||||
return Person.all if query.to_s.empty?
|
||||
query_tokens = query.to_s.strip.split(" ")
|
||||
full_query_text = Regexp.escape( query.to_s.strip )
|
||||
full_query_text = Regexp.escape(query.to_s.strip)
|
||||
|
||||
p = []
|
||||
|
||||
query_tokens.each do |token|
|
||||
q = Regexp.escape( token.to_s.strip )
|
||||
q = Regexp.escape(token.to_s.strip)
|
||||
p = Person.all('profile.first_name' => /^#{q}/i) \
|
||||
| Person.all('profile.last_name' => /^#{q}/i) \
|
||||
| p
|
||||
|
|
@ -53,6 +53,7 @@ class Person
|
|||
def real_name
|
||||
"#{profile.first_name.to_s} #{profile.last_name.to_s}"
|
||||
end
|
||||
|
||||
def owns?(post)
|
||||
self.id == post.person.id
|
||||
end
|
||||
|
|
@ -71,7 +72,7 @@ class Person
|
|||
end
|
||||
|
||||
def public_key
|
||||
OpenSSL::PKey::RSA.new( serialized_public_key )
|
||||
OpenSSL::PKey::RSA.new(serialized_public_key)
|
||||
end
|
||||
|
||||
def exported_key
|
||||
|
|
@ -83,9 +84,9 @@ class Person
|
|||
@serialized_public_key = new_key
|
||||
end
|
||||
|
||||
def self.by_webfinger( identifier, opts = {})
|
||||
def self.by_webfinger(identifier, opts = {})
|
||||
#need to check if this is a valid email structure, maybe should do in JS
|
||||
local_person = Person.first(:diaspora_handle => identifier.gsub('acct:', '').to_s.downcase)
|
||||
local_person = Person.first(:diaspora_handle => identifier.gsub('acct:', '').to_s)
|
||||
|
||||
if local_person
|
||||
Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}")
|
||||
|
|
@ -100,21 +101,21 @@ class Person
|
|||
raise "Connection timed out to Diaspora server for #{identifier}"
|
||||
end
|
||||
raise "No webfinger profile found at #{identifier}" if f.nil? || f.links.empty?
|
||||
Person.from_webfinger_profile(identifier, f )
|
||||
Person.from_webfinger_profile(identifier, f)
|
||||
end
|
||||
end
|
||||
|
||||
def self.from_webfinger_profile( identifier, profile)
|
||||
def self.from_webfinger_profile(identifier, profile)
|
||||
new_person = Person.new
|
||||
|
||||
public_key_entry = profile.links.select{|x| x.rel == 'diaspora-public-key'}
|
||||
public_key_entry = profile.links.select { |x| x.rel == 'diaspora-public-key' }
|
||||
|
||||
return nil unless public_key_entry
|
||||
|
||||
pubkey = public_key_entry.first.href
|
||||
new_person.exported_key = Base64.decode64 pubkey
|
||||
|
||||
guid = profile.links.select{|x| x.rel == 'http://joindiaspora.com/guid'}.first.href
|
||||
guid = profile.links.select { |x| x.rel == 'http://joindiaspora.com/guid' }.first.href
|
||||
new_person.id = guid
|
||||
|
||||
new_person.diaspora_handle = identifier
|
||||
|
|
@ -151,12 +152,12 @@ class Person
|
|||
self.url ||= "http://localhost:3000/" if self.class == User
|
||||
if self.url
|
||||
self.url = 'http://' + self.url unless self.url.match('http://' || 'https://')
|
||||
self.url = self.url + '/' if self.url[-1,1] != '/'
|
||||
self.url = self.url + '/' if self.url[-1, 1] != '/'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def remove_all_traces
|
||||
Post.all(:person_id => id).each{|p| p.delete}
|
||||
Post.all(:person_id => id).each { |p| p.delete }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -49,9 +49,28 @@ describe PublicsController do
|
|||
end
|
||||
|
||||
describe 'webfinger' do
|
||||
it 'should not try to webfinger out on a request to webfinger' do
|
||||
Redfinger.should_not_receive :finger
|
||||
post :webfinger, :q => 'remote@example.com'
|
||||
it "succeeds when the person and user exist locally" do
|
||||
user = Factory(:user)
|
||||
post :webfinger, 'q' => user.person.diaspora_handle
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it "404s when the person exists remotely because it is local only" do
|
||||
stub_success('me@mydiaspora.pod.com')
|
||||
post :webfinger, 'q' => 'me@mydiaspora.pod.com'
|
||||
response.should be_not_found
|
||||
end
|
||||
|
||||
it "404s when the person is local but doesn't have an owner" do
|
||||
person = Factory(:person)
|
||||
post :webfinger, 'q' => person.diaspora_handle
|
||||
response.should be_not_found
|
||||
end
|
||||
|
||||
it "404s when the person does not exist locally or remotely" do
|
||||
stub_failure('me@mydiaspora.pod.com')
|
||||
post :webfinger, 'q' => 'me@mydiaspora.pod.com'
|
||||
response.should be_not_found
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -164,17 +164,31 @@ describe Person do
|
|||
people = Person.search("Casey Grippi")
|
||||
people.should == [@friend_four]
|
||||
end
|
||||
|
||||
it 'should search by diaspora_handle exactly' do
|
||||
stub_success("tom@tom.joindiaspora.com")
|
||||
Person.by_webfinger(@friend_one.diaspora_handle).should == @friend_one
|
||||
end
|
||||
|
||||
it 'should create a stub for a remote user' do
|
||||
describe ".by_webfinger" do
|
||||
context "local people" do
|
||||
before do
|
||||
@local_person = Factory(:person)
|
||||
Redfinger.should_not_receive :finger
|
||||
end
|
||||
|
||||
it "finds the local person without calling out" do
|
||||
person = Person.by_webfinger(@local_person.diaspora_handle)
|
||||
person.should == @local_person
|
||||
end
|
||||
|
||||
it "finds a local person with a mixed-case username" do
|
||||
user = Factory(:user, :username => "SaMaNtHa")
|
||||
person = Person.by_webfinger(user.person.diaspora_handle)
|
||||
person.should == user.person
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates a stub for a remote user' do
|
||||
stub_success("tom@tom.joindiaspora.com")
|
||||
tom = Person.by_webfinger('tom@tom.joindiaspora.com')
|
||||
tom.real_name.include?("Hamiltom").should be true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue