Skip to content
Extraits de code Groupes Projets
Valider 4b588cce rédigé par Joseph Method's avatar Joseph Method
Parcourir les fichiers

Addresses [#380] and [#239] by handling the errors from bad identities

parent d200aaab
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -35,8 +35,15 @@ class RequestsController < ApplicationController ...@@ -35,8 +35,15 @@ class RequestsController < ApplicationController
begin begin
rel_hash = relationship_flow(params[:request][:destination_url].strip) rel_hash = relationship_flow(params[:request][:destination_url].strip)
rescue Exception => e rescue Exception => e
raise e unless e.message.include? "not found" if e.message.include? "not found"
flash[:error] = I18n.t 'requests.create.error' flash[:error] = I18n.t 'requests.create.error'
elsif e.message.include? "Connection timed out"
flash[:error] = I18n.t 'requests.create.error_server'
elsif e.message == "Identifier is invalid"
flash[:error] = I18n.t 'requests.create.invalid_identity'
else
raise e
end
respond_with :location => aspect respond_with :location => aspect
return return
end end
......
...@@ -85,7 +85,11 @@ class Person ...@@ -85,7 +85,11 @@ class Person
end 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 # Raise an error if identifier has a port number
raise "Identifier is invalid" if(identifier.strip.match(/\:\d+$/))
# Raise an error if identifier is not a valid email (generous regexp)
raise "Identifier is invalid" if !(identifier =~ /\A.*\@.*\..*\Z/)
query = /#{Regexp.escape(identifier.gsub('acct:', '').to_s)}/i query = /#{Regexp.escape(identifier.gsub('acct:', '').to_s)}/i
local_person = Person.first(:diaspora_handle => query) local_person = Person.first(:diaspora_handle => query)
......
...@@ -229,6 +229,8 @@ en: ...@@ -229,6 +229,8 @@ en:
ignore: "Ignored friend request." ignore: "Ignored friend request."
create: create:
error: "No diaspora seed found with this email!" error: "No diaspora seed found with this email!"
invalid_identity: "This identity is not properly formatted"
error_server: "Problem with other server. Maybe it doesn't exist?"
yourself: "You cannot befriend yourself!" yourself: "You cannot befriend yourself!"
already_friends: "You are already friends with %{destination_url}!" already_friends: "You are already friends with %{destination_url}!"
success: "A friend request was sent to %{destination_url}." success: "A friend request was sent to %{destination_url}."
......
...@@ -22,4 +22,34 @@ describe RequestsController do ...@@ -22,4 +22,34 @@ describe RequestsController do
response.should redirect_to aspect_path(@user.aspects[0].id.to_s) response.should redirect_to aspect_path(@user.aspects[0].id.to_s)
end end
it "should not error out when requesting an invalid identity" do
put("create", "request" => {
"destination_url" => "not_a_@valid_email",
"aspect_id" => @user.aspects[0].id
}
)
response.should redirect_to aspect_path(@user.aspects[0].id.to_s)
end
it "should not error out when requesting an invalid identity with a port number" do
put("create", "request" => {
"destination_url" => "johndoe@email.com:3000",
"aspect_id" => @user.aspects[0].id
}
)
response.should redirect_to aspect_path(@user.aspects[0].id.to_s)
end
it "should not error out when requesting an identity from an invalid server" do
stub_request(:get, /notadiasporaserver\.com/).to_raise(Errno::ETIMEDOUT)
put("create", "request" => {
"destination_url" => "johndoe@notadiasporaserver.com",
"aspect_id" => @user.aspects[0].id
}
)
response.should redirect_to aspect_path(@user.aspects[0].id.to_s)
end
end end
...@@ -197,6 +197,26 @@ describe Person do ...@@ -197,6 +197,26 @@ describe Person do
end end
end end
it 'identifier should be a valid email' do
stub_success("joe.valid+email@my-address.com")
Proc.new {
Person.by_webfinger("joe.valid+email@my-address.com")
}.should_not raise_error(RuntimeError, "Identifier is invalid")
stub_success("not_a_@valid_email")
Proc.new {
Person.by_webfinger("not_a_@valid_email")
}.should raise_error(RuntimeError, "Identifier is invalid")
end
it 'should not accept a port number' do
stub_success("eviljoe@diaspora.local:3000")
Proc.new {
Person.by_webfinger('eviljoe@diaspora.local:3000')
}.should raise_error(RuntimeError, "Identifier is invalid")
end
it 'creates a stub for a remote user' do it 'creates a stub for a remote user' do
stub_success("tom@tom.joindiaspora.com") stub_success("tom@tom.joindiaspora.com")
tom = Person.by_webfinger('tom@tom.joindiaspora.com') tom = Person.by_webfinger('tom@tom.joindiaspora.com')
......
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