Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
diaspora
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Milan
diaspora
Commits
108bf9d9
Commit
108bf9d9
authored
14 years ago
by
danielvincent
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of github.com:diaspora/diaspora
parents
7160e9f8
fcdcf88a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/models/person.rb
+33
-32
33 additions, 32 deletions
app/models/person.rb
spec/controllers/publics_controller_spec.rb
+22
-3
22 additions, 3 deletions
spec/controllers/publics_controller_spec.rb
spec/models/person_spec.rb
+19
-5
19 additions, 5 deletions
spec/models/person_spec.rb
with
74 additions
and
40 deletions
app/models/person.rb
+
33
−
32
View file @
108bf9d9
...
...
@@ -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
This diff is collapsed.
Click to expand it.
spec/controllers/publics_controller_spec.rb
+
22
−
3
View file @
108bf9d9
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
spec/models/person_spec.rb
+
19
−
5
View file @
108bf9d9
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment