Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
parlote-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
parlote-facil
Validations
baa0b436
Valider
baa0b436
rédigé
14 years ago
par
archi
Parcourir les fichiers
Options
Téléchargements
Plain Diff
Merge branch 'master' of
git://github.com/diaspora/diaspora
into 332-quickfix
parents
1d9aa4c4
fcdcf88a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
3
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
app/models/person.rb
+33
-32
33 ajouts, 32 suppressions
app/models/person.rb
spec/controllers/publics_controller_spec.rb
+22
-3
22 ajouts, 3 suppressions
spec/controllers/publics_controller_spec.rb
spec/models/person_spec.rb
+19
-5
19 ajouts, 5 suppressions
spec/models/person_spec.rb
avec
74 ajouts
et
40 suppressions
app/models/person.rb
+
33
−
32
Voir le fichier @
baa0b436
...
...
@@ -15,11 +15,11 @@ class Person
xml_accessor
:profile
,
:as
=>
Profile
xml_reader
:exported_key
key
:url
,
String
key
:url
,
String
key
:diaspora_handle
,
String
,
:unique
=>
true
key
:serialized_public_key
,
String
key
:owner_id
,
ObjectId
key
:owner_id
,
ObjectId
one
:profile
,
:class_name
=>
'Profile'
many
:albums
,
:class_name
=>
'Album'
,
:foreign_key
=>
:person_id
...
...
@@ -31,28 +31,29 @@ class Person
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
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
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
)
p
=
Person
.
all
(
'profile.first_name'
=>
/^
#{
q
}
/i
)
\
|
Person
.
all
(
'profile.last_name'
=>
/^
#{
q
}
/i
)
\
|
p
q
=
Regexp
.
escape
(
token
.
to_s
.
strip
)
p
=
Person
.
all
(
'profile.first_name'
=>
/^
#{
q
}
/i
)
\
|
Person
.
all
(
'profile.last_name'
=>
/^
#{
q
}
/i
)
\
|
p
end
return
p
return
p
end
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,38 +84,38 @@ 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
}
"
)
local_person
elsif
!
identifier
.
include?
(
"localhost"
)
&&
!
opts
[
:local
]
begin
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
]
begin
Rails
.
logger
.
info
(
"Webfingering
#{
identifier
}
"
)
f
=
Redfinger
.
finger
(
identifier
)
rescue
SocketError
=>
e
raise
"Diaspora server for
#{
identifier
}
not found"
if
e
.
message
=~
/Name or service not known/
rescue
Errno
::
ETIMEDOUT
=>
e
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
)
end
rescue
SocketError
=>
e
raise
"Diaspora server for
#{
identifier
}
not found"
if
e
.
message
=~
/Name or service not known/
rescue
Errno
::
ETIMEDOUT
=>
e
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
)
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
Ce diff est replié.
Cliquez pour l'agrandir.
spec/controllers/publics_controller_spec.rb
+
22
−
3
Voir le fichier @
baa0b436
...
...
@@ -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
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
spec/models/person_spec.rb
+
19
−
5
Voir le fichier @
baa0b436
...
...
@@ -164,17 +164,31 @@ describe Person do
people
=
Person
.
search
(
"Casey Grippi"
)
people
.
should
==
[
@friend_four
]
end
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
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
'
should
create a stub for a remote user'
do
it
'create
s
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
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter