Remove downcasing of diaspora_handle, verify that diaspora_handle querying and validation is case insensitive.
This commit is contained in:
parent
adb559155a
commit
fce902821b
4 changed files with 23 additions and 28 deletions
|
|
@ -27,21 +27,12 @@ class Person
|
|||
|
||||
timestamps!
|
||||
|
||||
before_save :strip_and_downcase_diaspora_handle
|
||||
before_destroy :remove_all_traces
|
||||
before_validation :clean_url
|
||||
validates_presence_of :url, :profile, :serialized_public_key
|
||||
validates_format_of :url, :with =>
|
||||
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
|
||||
|
||||
|
||||
def strip_and_downcase_diaspora_handle
|
||||
if self.diaspora_handle
|
||||
self.diaspora_handle.strip!
|
||||
self.diaspora_handle.downcase!
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(query)
|
||||
return Person.all if query.to_s.empty?
|
||||
query_tokens = query.to_s.strip.split(" ")
|
||||
|
|
@ -95,12 +86,14 @@ class Person
|
|||
|
||||
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)
|
||||
query = /#{Regexp.escape(identifier.gsub('acct:', '').to_s)}/i
|
||||
local_person = Person.first(:diaspora_handle => query)
|
||||
|
||||
if local_person
|
||||
Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}")
|
||||
local_person
|
||||
elsif !identifier.include?("localhost") && !opts[:local]
|
||||
#Get remote profile
|
||||
begin
|
||||
Rails.logger.info("Webfingering #{identifier}")
|
||||
f = Redfinger.finger(identifier)
|
||||
|
|
|
|||
|
|
@ -388,7 +388,7 @@ class User
|
|||
end
|
||||
|
||||
def diaspora_handle
|
||||
"#{self.username}@#{APP_CONFIG[:terse_pod_url]}".downcase
|
||||
"#{self.username}@#{APP_CONFIG[:terse_pod_url]}"
|
||||
end
|
||||
|
||||
def as_json(opts={})
|
||||
|
|
|
|||
|
|
@ -14,11 +14,6 @@ describe Person do
|
|||
end
|
||||
|
||||
describe '#diaspora_handle' do
|
||||
it 'should downcase and strip the handle before it saves' do
|
||||
p = Factory.build(:person, :diaspora_handle => " FOOBaR@example.com ")
|
||||
p.save
|
||||
p.diaspora_handle.should == "foobar@example.com"
|
||||
end
|
||||
context 'local people' do
|
||||
it 'uses the pod config url to set the diaspora_handle' do
|
||||
@user.person.diaspora_handle.should == @user.username + "@" + APP_CONFIG[:terse_pod_url]
|
||||
|
|
@ -30,11 +25,17 @@ describe Person do
|
|||
@person.diaspora_handle.include?(APP_CONFIG[:terse_pod_url]).should be false
|
||||
end
|
||||
end
|
||||
describe 'validation' do
|
||||
it 'is unique' do
|
||||
person_two = Factory.build(:person, :url => @person.diaspora_handle)
|
||||
person_two.valid?.should be_false
|
||||
end
|
||||
|
||||
it 'should not allow two people with the same diaspora_handle' do
|
||||
person_two = Factory.build(:person, :url => @person.diaspora_handle)
|
||||
person_two.valid?.should == false
|
||||
it 'is case insensitive' do
|
||||
person_two = Factory.build(:person, :url => @person.diaspora_handle.upcase)
|
||||
person_two.valid?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'xml' do
|
||||
|
|
@ -52,7 +53,7 @@ describe Person do
|
|||
end
|
||||
end
|
||||
|
||||
it 'should know when a post belongs to it' do
|
||||
it '#owns? posts' do
|
||||
person_message = Factory.create(:status_message, :person => @person)
|
||||
person_two = Factory.create(:person)
|
||||
|
||||
|
|
@ -188,6 +189,12 @@ describe Person do
|
|||
person = Person.by_webfinger(user.person.diaspora_handle)
|
||||
person.should == user.person
|
||||
end
|
||||
|
||||
it "is case insensitive" do
|
||||
user = Factory(:user, :username => "SaMaNtHa")
|
||||
person = Person.by_webfinger(user.person.diaspora_handle.upcase)
|
||||
person.should == user.person
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates a stub for a remote user' do
|
||||
|
|
|
|||
|
|
@ -83,11 +83,6 @@ describe User do
|
|||
it 'uses the pod config url to set the diaspora_handle' do
|
||||
user.diaspora_handle.should == user.username + "@" + APP_CONFIG[:terse_pod_url]
|
||||
end
|
||||
|
||||
it 'should be lowercase, even if username is uppercase' do
|
||||
user.username = "fooBAR"
|
||||
user.diaspora_handle.should == (user.username + "@" + APP_CONFIG[:terse_pod_url]).downcase
|
||||
end
|
||||
end
|
||||
|
||||
context 'profiles' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue