Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
diaspora
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Milan
diaspora
Commits
e16b9af7
Commit
e16b9af7
authored
Jun 07, 2015
by
Benjamin Neff
Committed by
Dennis Schubert
Jun 08, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make public and private receiver work similar ...
parent
ed10bea2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
111 additions
and
66 deletions
+111
-66
lib/postzord/receiver.rb
lib/postzord/receiver.rb
+13
-6
lib/postzord/receiver/private.rb
lib/postzord/receiver/private.rb
+19
-28
lib/postzord/receiver/public.rb
lib/postzord/receiver/public.rb
+22
-19
spec/lib/postzord/receiver/private_spec.rb
spec/lib/postzord/receiver/private_spec.rb
+4
-4
spec/lib/postzord/receiver/public_spec.rb
spec/lib/postzord/receiver/public_spec.rb
+5
-4
spec/lib/postzord/receiver_spec.rb
spec/lib/postzord/receiver_spec.rb
+46
-3
spec/models/poll_participation_spec.rb
spec/models/poll_participation_spec.rb
+2
-2
No files found.
lib/postzord/receiver.rb
View file @
e16b9af7
...
...
@@ -14,12 +14,19 @@ class Postzord::Receiver
self
.
receive!
end
private
def
author_does_not_match_xml_author?
if
(
@author
.
diaspora_handle
!=
xml_author
)
logger
.
warn
"event=receive status=abort reason='author in xml does not match retrieved person' "
\
"payload_type=
#{
@object
.
class
}
sender=
#{
@author
.
diaspora_handle
}
"
return
true
end
return
false
unless
@author
.
diaspora_handle
!=
xml_author
logger
.
error
"event=receive status=abort reason='author in xml does not match retrieved person' "
\
"type=
#{
@object
.
class
}
sender=
#{
@author
.
diaspora_handle
}
"
true
end
end
def
relayable_without_parent?
return
false
unless
@object
.
respond_to?
(
:relayable?
)
&&
@object
.
parent
.
nil?
logger
.
error
"event=receive status=abort reason='no corresponding post' type=
#{
@object
.
class
}
"
\
"sender=
#{
@author
.
diaspora_handle
}
"
true
end
end
lib/postzord/receiver/private.rb
View file @
e16b9af7
...
...
@@ -9,30 +9,28 @@ class Postzord::Receiver::Private < Postzord::Receiver
@user_person
=
@user
.
person
@salmon_xml
=
opts
[
:salmon_xml
]
@sender
=
opts
[
:person
]
||
Webfinger
.
new
(
self
.
salmon
.
author_id
).
fetch
@author
=
@sender
@author
=
opts
[
:person
]
||
Webfinger
.
new
(
salmon
.
author_id
).
fetch
@object
=
opts
[
:object
]
end
def
receive!
if
@
sender
&&
self
.
salmon
.
verified_for_key?
(
@sende
r
.
public_key
)
if
@
author
&&
salmon
.
verified_for_key?
(
@autho
r
.
public_key
)
parse_and_receive
(
salmon
.
parsed_data
)
else
logger
.
error
"event=receive status=abort reason='not_verified for key' "
\
"recipient=
#{
@user
.
diaspora_handle
}
sender=
#{
@salmon
.
author_id
}
"
end
rescue
=>
e
logger
.
error
"failed to receive
#{
@object
.
class
}
from sender:
#{
@
sende
r
.
id
}
for user:
#{
@user
.
id
}
:
#{
e
.
message
}
\n
"
\
logger
.
error
"failed to receive
#{
@object
.
class
}
from sender:
#{
@
autho
r
.
id
}
for user:
#{
@user
.
id
}
:
#{
e
.
message
}
\n
"
\
"
#{
@object
.
inspect
}
"
raise
e
end
def
parse_and_receive
(
xml
)
@object
||=
Diaspora
::
Parser
.
from_xml
(
xml
)
return
if
@object
.
nil?
logger
.
info
"user:
#{
@user
.
id
}
starting private receive from person:
#{
@
sende
r
.
guid
}
"
logger
.
info
"user:
#{
@user
.
id
}
starting private receive from person:
#{
@
autho
r
.
guid
}
"
validate_object
set_author!
...
...
@@ -43,27 +41,17 @@ class Postzord::Receiver::Private < Postzord::Receiver
def
receive_object
obj
=
@object
.
receive
(
@user
,
@author
)
Notification
.
notify
(
@user
,
obj
,
@author
)
if
obj
.
respond_to?
(
:notification_type
)
logger
.
info
"user:
#{
@user
.
id
}
successfully received
#{
@object
.
class
}
from person
#{
@
sende
r
.
guid
}
"
\
logger
.
info
"user:
#{
@user
.
id
}
successfully received
#{
@object
.
class
}
from person
#{
@
autho
r
.
guid
}
"
\
"
#{
":
#{
@object
.
guid
}
"
if
@object
.
respond_to?
(
:guid
)
}
"
logger
.
debug
"received:
#{
@object
.
inspect
}
"
end
protected
def
salmon
@salmon
||=
Salmon
::
EncryptedSlap
.
from_xml
(
@salmon_xml
,
@user
)
end
def
validate_object
raise
Diaspora
::
ContactRequiredUnlessRequest
if
contact_required_unless_request
raise
Diaspora
::
RelayableObjectWithoutParent
if
relayable_without_parent?
assign_sender_handle_if_request
raise
Diaspora
::
AuthorXMLAuthorMismatch
if
author_does_not_match_xml_author?
@object
end
def
xml_author
if
@object
.
respond_to?
(
:relayable?
)
#if A and B are friends, and A sends B a comment from C, we delegate the validation to the owner of the post being commented on
...
...
@@ -84,19 +72,22 @@ class Postzord::Receiver::Private < Postzord::Receiver
private
#validations
def
relayable_without_parent?
if
@object
.
respond_to?
(
:relayable?
)
&&
@object
.
parent
.
nil?
logger
.
error
"event=receive status=abort reason='no corresponding post' type=
#{
@object
.
class
}
"
\
"recipient=
#{
@user_person
.
diaspora_handle
}
sender=
#{
@sender
.
diaspora_handle
}
"
return
true
end
# validations
def
validate_object
raise
Diaspora
::
XMLNotParseable
if
@object
.
nil?
raise
Diaspora
::
ContactRequiredUnlessRequest
if
contact_required_unless_request
raise
Diaspora
::
RelayableObjectWithoutParent
if
relayable_without_parent?
assign_sender_handle_if_request
raise
Diaspora
::
AuthorXMLAuthorMismatch
if
author_does_not_match_xml_author?
end
def
contact_required_unless_request
unless
@object
.
is_a?
(
Request
)
||
@user
.
contact_for
(
@
sende
r
)
unless
@object
.
is_a?
(
Request
)
||
@user
.
contact_for
(
@
autho
r
)
logger
.
error
"event=receive status=abort reason='sender not connected to recipient' type=
#{
@object
.
class
}
"
\
"recipient=
#{
@user_person
.
diaspora_handle
}
sender=
#{
@
sende
r
.
diaspora_handle
}
"
"recipient=
#{
@user_person
.
diaspora_handle
}
sender=
#{
@
autho
r
.
diaspora_handle
}
"
return
true
end
end
...
...
@@ -104,7 +95,7 @@ class Postzord::Receiver::Private < Postzord::Receiver
def
assign_sender_handle_if_request
#special casey
if
@object
.
is_a?
(
Request
)
@object
.
sender_handle
=
@
sende
r
.
diaspora_handle
@object
.
sender_handle
=
@
autho
r
.
diaspora_handle
end
end
end
lib/postzord/receiver/public.rb
View file @
e16b9af7
...
...
@@ -9,8 +9,6 @@ class Postzord::Receiver::Public < Postzord::Receiver
def
initialize
(
xml
)
@salmon
=
Salmon
::
Slap
.
from_xml
(
xml
)
@author
=
Webfinger
.
new
(
@salmon
.
author_id
).
fetch
logger
.
info
"Receiving public object from person:
#{
@author
.
id
}
"
end
# @return [Boolean]
...
...
@@ -23,7 +21,7 @@ class Postzord::Receiver::Public < Postzord::Receiver
return
unless
verified_signature?
# return false unless account_deletion_is_from_author
return
unless
save_object
parse_and_receive
(
@salmon
.
parsed_data
)
logger
.
info
"received a
#{
@object
.
inspect
}
"
if
@object
.
is_a?
(
SignedRetraction
)
# feels like a hack
...
...
@@ -51,15 +49,19 @@ class Postzord::Receiver::Public < Postzord::Receiver
receiver
.
notify_users
end
# @return [Object]
def
save_object
@object
=
Diaspora
::
Parser
.
from_xml
(
@salmon
.
parsed_data
)
raise
Diaspora
::
XMLNotParseable
if
@object
.
nil?
raise
Diaspora
::
NonPublic
if
object_can_be_public_and_it_is_not?
raise
Diaspora
::
RelayableObjectWithoutParent
if
object_must_have_parent_and_does_not?
raise
Diaspora
::
AuthorXMLAuthorMismatch
if
author_does_not_match_xml_author?
# @return [void]
def
parse_and_receive
(
xml
)
@object
=
Diaspora
::
Parser
.
from_xml
(
xml
)
logger
.
info
"starting public receive from person:
#{
@author
.
guid
}
"
validate_object
receive_object
end
# @return [void]
def
receive_object
@object
.
save!
if
@object
.
respond_to?
(
:save!
)
@object
end
# @return [Array<Integer>] User ids
...
...
@@ -78,6 +80,15 @@ class Postzord::Receiver::Public < Postzord::Receiver
private
# validations
def
validate_object
raise
Diaspora
::
XMLNotParseable
if
@object
.
nil?
raise
Diaspora
::
NonPublic
if
object_can_be_public_and_it_is_not?
raise
Diaspora
::
RelayableObjectWithoutParent
if
relayable_without_parent?
raise
Diaspora
::
AuthorXMLAuthorMismatch
if
author_does_not_match_xml_author?
end
def
account_deletion_is_from_author
return
true
unless
@object
.
is_a?
(
AccountDeletion
)
return
false
if
@object
.
diaspora_handle
!=
@author
.
diaspora_handle
...
...
@@ -88,12 +99,4 @@ class Postzord::Receiver::Public < Postzord::Receiver
def
object_can_be_public_and_it_is_not?
@object
.
respond_to?
(
:public
)
&&
!
@object
.
public?
end
def
object_must_have_parent_and_does_not?
if
@object
.
respond_to?
(
:relayable?
)
# comment, like
@object
.
parent
.
nil?
else
false
end
end
end
spec/lib/postzord/receiver/private_spec.rb
View file @
e16b9af7
...
...
@@ -18,7 +18,7 @@ describe Postzord::Receiver::Private do
zord
=
Postzord
::
Receiver
::
Private
.
new
(
bob
,
:person
=>
alice
.
person
,
:object
=>
@alices_post
)
expect
(
zord
.
instance_variable_get
(
:@user
)).
not_to
be_nil
expect
(
zord
.
instance_variable_get
(
:@
sende
r
)).
not_to
be_nil
expect
(
zord
.
instance_variable_get
(
:@
autho
r
)).
not_to
be_nil
expect
(
zord
.
instance_variable_get
(
:@object
)).
not_to
be_nil
end
...
...
@@ -32,7 +32,7 @@ describe Postzord::Receiver::Private do
zord
=
Postzord
::
Receiver
::
Private
.
new
(
bob
,
:salmon_xml
=>
@salmon_xml
)
expect
(
zord
.
instance_variable_get
(
:@user
)).
not_to
be_nil
expect
(
zord
.
instance_variable_get
(
:@
sende
r
)).
not_to
be_nil
expect
(
zord
.
instance_variable_get
(
:@
autho
r
)).
not_to
be_nil
expect
(
zord
.
instance_variable_get
(
:@salmon_xml
)).
not_to
be_nil
end
end
...
...
@@ -45,13 +45,13 @@ describe Postzord::Receiver::Private do
context
"does not parse and receive"
do
it
"if the salmon author does not exist"
do
@zord
.
instance_variable_set
(
:@
sende
r
,
nil
)
@zord
.
instance_variable_set
(
:@
autho
r
,
nil
)
expect
(
@zord
).
not_to
receive
(
:parse_and_receive
)
@zord
.
receive!
end
it
"if the author does not match the signature"
do
@zord
.
instance_variable_set
(
:@
sende
r
,
FactoryGirl
.
create
(
:person
))
@zord
.
instance_variable_set
(
:@
autho
r
,
FactoryGirl
.
create
(
:person
))
expect
(
@zord
).
not_to
receive
(
:parse_and_receive
)
@zord
.
receive!
end
...
...
spec/lib/postzord/receiver/public_spec.rb
View file @
e16b9af7
...
...
@@ -47,7 +47,7 @@ describe Postzord::Receiver::Public do
it
"does not save the object if signature is not verified"
do
expect
(
@receiver
).
to
receive
(
:verified_signature?
).
and_return
(
false
)
expect
(
@receiver
).
not_to
receive
(
:
save_object
)
expect
(
@receiver
).
not_to
receive
(
:
parse_and_receive
)
@receiver
.
perform!
end
...
...
@@ -58,7 +58,7 @@ describe Postzord::Receiver::Public do
end
it
'saves the parsed object'
do
expect
(
@receiver
).
to
receive
(
:
save_object
)
expect
(
@receiver
).
to
receive
(
:
parse_and_receive
).
and_call_original
@receiver
.
perform!
end
...
...
@@ -120,14 +120,15 @@ describe Postzord::Receiver::Public do
end
end
describe
"#
save_object
"
do
describe
"#
parse_and_receive
"
do
before
do
@receiver
=
Postzord
::
Receiver
::
Public
.
new
(
@xml
)
@parsed_salmon
=
Salmon
::
Slap
.
from_xml
(
@xml
)
end
it
"should raise a Diaspora::XMLNotParseable when the parsed object is nil"
do
expect
(
Diaspora
::
Parser
).
to
receive
(
:from_xml
).
and_return
(
nil
)
expect
{
@receiver
.
save_object
}.
to
raise_error
(
Diaspora
::
XMLNotParseable
)
expect
{
@receiver
.
parse_and_receive
(
@parsed_salmon
.
parsed_data
)
}.
to
raise_error
(
Diaspora
::
XMLNotParseable
)
end
end
end
spec/lib/postzord/receiver_spec.rb
View file @
e16b9af7
...
...
@@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require
'spec_helper'
require
"spec_helper"
describe
Postzord
::
Receiver
do
before
do
...
...
@@ -14,10 +14,53 @@ describe Postzord::Receiver do
allow
(
@receiver
).
to
receive
(
:receive!
).
and_return
(
true
)
end
it
'calls receive!'
do
it
"calls receive!"
do
expect
(
@receiver
).
to
receive
(
:receive!
)
@receiver
.
perform!
end
end
end
describe
"#author_does_not_match_xml_author?"
do
before
do
@receiver
.
instance_variable_set
(
:@author
,
alice
.
person
)
allow
(
@receiver
).
to
receive
(
:xml_author
).
and_return
(
alice
.
diaspora_handle
)
end
it
"should return false if the author matches"
do
allow
(
@receiver
).
to
receive
(
:xml_author
).
and_return
(
alice
.
diaspora_handle
)
expect
(
@receiver
.
send
(
:author_does_not_match_xml_author?
)).
to
be_falsey
end
it
"should return true if the author does not match"
do
allow
(
@receiver
).
to
receive
(
:xml_author
).
and_return
(
bob
.
diaspora_handle
)
expect
(
@receiver
.
send
(
:author_does_not_match_xml_author?
)).
to
be_truthy
end
end
describe
"#relayable_without_parent?"
do
before
do
@receiver
.
instance_variable_set
(
:@author
,
alice
.
person
)
end
it
"should return false if object is not relayable"
do
@receiver
.
instance_variable_set
(
:@object
,
nil
)
expect
(
@receiver
.
send
(
:relayable_without_parent?
)).
to
be_falsey
end
context
"if object is relayable"
do
before
do
@comment
=
bob
.
build_comment
(
text:
"yo"
,
post:
FactoryGirl
.
create
(
:status_message
))
@receiver
.
instance_variable_set
(
:@object
,
@comment
)
end
it
"should return false if object has parent"
do
expect
(
@receiver
.
send
(
:relayable_without_parent?
)).
to
be_falsey
end
it
"should return true if object has no parent"
do
@comment
.
parent
=
nil
expect
(
@receiver
.
send
(
:relayable_without_parent?
)).
to
be_truthy
end
end
end
end
spec/models/poll_participation_spec.rb
View file @
e16b9af7
...
...
@@ -2,7 +2,6 @@ require 'spec_helper'
require
Rails
.
root
.
join
(
"spec"
,
"shared_behaviors"
,
"relayable"
)
describe
PollParticipation
,
:type
=>
:model
do
before
do
@alices_aspect
=
alice
.
aspects
.
first
@status
=
bob
.
post
(
:status_message
,
:text
=>
"hello"
,
:to
=>
bob
.
aspects
.
first
.
id
)
...
...
@@ -98,7 +97,8 @@ describe PollParticipation, :type => :model do
allow_any_instance_of
(
Person
).
to
receive
(
:local?
).
and_return
(
false
)
expect
{
salmon
=
Salmon
::
Slap
.
create_by_user_and_activity
(
alice
,
@poll_participation_alice
.
to_diaspora_xml
).
xml_for
(
@poll_participant
)
Postzord
::
Receiver
::
Public
.
new
(
salmon
).
save_object
parsed_salmon
=
Salmon
::
Slap
.
from_xml
(
salmon
)
Postzord
::
Receiver
::
Public
.
new
(
salmon
).
parse_and_receive
(
parsed_salmon
.
parsed_data
)
}.
to_not
raise_error
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment