Skip to content
Extraits de code Groupes Projets
Valider 8ada8414 rédigé par maxwell's avatar maxwell
Parcourir les fichiers

username can be any case, but diaspora handle should always, always, ALWAYS be...

username can be any case, but diaspora handle should always, always, ALWAYS be lowercase, for webfinger reasons
parent 8894fa4d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -26,13 +26,22 @@ class Person ...@@ -26,13 +26,22 @@ class Person
belongs_to :owner, :class_name => 'User' belongs_to :owner, :class_name => 'User'
timestamps! timestamps!
before_save :strip_and_downcase_diaspora_handle
before_destroy :remove_all_traces before_destroy :remove_all_traces
before_validation :clean_url before_validation :clean_url
validates_presence_of :url, :profile, :serialized_public_key validates_presence_of :url, :profile, :serialized_public_key
validates_format_of :url, :with => validates_format_of :url, :with =>
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix /^(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) def self.search(query)
return Person.all if query.to_s.empty? return Person.all if query.to_s.empty?
query_tokens = query.to_s.strip.split(" ") query_tokens = query.to_s.strip.split(" ")
...@@ -46,7 +55,7 @@ class Person ...@@ -46,7 +55,7 @@ class Person
| Person.all('profile.last_name' => /^#{q}/i) \ | Person.all('profile.last_name' => /^#{q}/i) \
| p | p
end end
return p return p
end end
......
...@@ -388,7 +388,7 @@ class User ...@@ -388,7 +388,7 @@ class User
end end
def diaspora_handle def diaspora_handle
"#{self.username}@#{APP_CONFIG[:terse_pod_url]}" "#{self.username}@#{APP_CONFIG[:terse_pod_url]}".downcase
end end
def as_json(opts={}) def as_json(opts={})
......
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
require File.join(Rails.root, 'lib/em-webfinger')
describe EMWebfinger do
let(:user1) { Factory(:user) }
let(:user2) { Factory(:user) }
let(:account) {"tom@tom.joindiaspora.com"}
let(:finger){EMWebfinger.new(account)}
let(:person){ Factory(:person) }
let(:good_request) { FakeHttpRequest.new(:success)}
let(:bad_request) { FakeHttpRequest.new(:failure)}
let(:stub_good) {EventMachine::HttpRequest.stub!(:new).and_return(good_request)}
let(:stub_bad) {EventMachine::HttpRequest.stub!(:new).and_return(bad_request)}
let(:diaspora_xrd) {File.open(File.join(Rails.root, 'spec/fixtures/host_xrd'))}
let(:diaspora_finger) {File.open(File.join(Rails.root, 'spec/fixtures/finger_xrd'))}
let(:hcard_xml) {File.open(File.join(Rails.root, 'spec/fixtures/hcard_response'))}
let(:non_diaspora_xrd) {File.open(File.join(Rails.root, 'spec/fixtures/nonseed_finger_xrd'))}
let(:non_diaspora_hcard) {File.open(File.join(Rails.root, 'spec/fixtures/evan_hcard'))}
context 'setup' do
let(:action){ Proc.new{|person| puts person.inspect }}
describe '#intialize' do
it 'sets account ' do
n = EMWebfinger.new("mbs348@gmail.com")
n.instance_variable_get(:@account).should_not be nil
end
it 'should raise an error on an unresonable email' do
pending
proc{EMWebfinger.new("asfadfasdf")}.should raise_error
end
end
describe '#on_person' do
it 'should set a callback' do
n = EMWebfinger.new("mbs@gmail.com")
n.on_person{|person| puts "foo"}
n.instance_variable_get(:@callbacks).count.should be 1
end
end
describe '#fetch' do
it 'should require a callback' do
proc{finger.fetch }.should raise_error "you need to set a callback before calling fetch"
end
it 'should'
end
end
context 'webfinger query chain processing' do
describe '#webfinger_profile_url' do
it 'should parse out the webfinger template' do
finger.webfinger_profile_url(account, diaspora_xrd).should == "http://example.com/webfinger/?q=#{account}"
end
end
describe '#xrd_url' do
it 'should return canonical host-meta url' do
finger.xrd_url(account).should be "http://tom.joindiaspora.com/.well-known/host-meta"
end
it 'can return the https version' do
finger.xrd_url(account, true).should be "https://tom.joindiaspora.com/.well-known/host-meta"
end
end
end
context 'webfingering local people' do
it 'should return a person from the database if it matches its handle' do
pending
end
end
end
class FakeHttpRequest
def initialize(callback_wanted)
@callback = callback_wanted
end
def response
end
def post; end
def get; end
def callback(&b)
b.call if @callback == :success
end
def errback(&b)
b.call if @callback == :failure
end
end
...@@ -14,6 +14,11 @@ describe Person do ...@@ -14,6 +14,11 @@ describe Person do
end end
describe '#diaspora_handle' do 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 context 'local people' do
it 'uses the pod config url to set the diaspora_handle' 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] @user.person.diaspora_handle.should == @user.username + "@" + APP_CONFIG[:terse_pod_url]
...@@ -32,7 +37,7 @@ describe Person do ...@@ -32,7 +37,7 @@ describe Person do
person_two.valid?.should == false person_two.valid?.should == false
end end
describe 'xml' do describe 'xml' do
before do before do
@xml = @person.to_xml.to_s @xml = @person.to_xml.to_s
end end
......
...@@ -83,6 +83,11 @@ describe User do ...@@ -83,6 +83,11 @@ describe User do
it 'uses the pod config url to set the diaspora_handle' do it 'uses the pod config url to set the diaspora_handle' do
user.diaspora_handle.should == user.username + "@" + APP_CONFIG[:terse_pod_url] user.diaspora_handle.should == user.username + "@" + APP_CONFIG[:terse_pod_url]
end 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 end
context 'profiles' do context 'profiles' do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter