Allow to receive non-public profiles without private data

This commit is contained in:
Benjamin Neff 2017-09-04 04:49:10 +02:00
parent 0b07b36017
commit 834d358eca
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
2 changed files with 29 additions and 4 deletions

View file

@ -7,11 +7,18 @@ module DiasporaFederation
def validate
super
raise NotPublic if entity_can_be_public_but_it_is_not?
validate_public_flag
end
def entity_can_be_public_but_it_is_not?
entity.respond_to?(:public) && !entity.public
def validate_public_flag
return if !entity.respond_to?(:public) || entity.public
if entity.is_a?(Entities::Profile) &&
%i[bio birthday gender location].all? {|prop| entity.public_send(prop).nil? }
return
end
raise NotPublic, "received entity #{entity} should be public!"
end
end
end

View file

@ -116,7 +116,7 @@ module DiasporaFederation
described_class.new(magic_env).receive
end
it "does not allow non-public entities" do
it "doesn't allow non-public entities" do
private_post = Fabricate(:status_message_entity, public: false)
magic_env = Salmon::MagicEnvelope.new(private_post, private_post.author)
@ -133,6 +133,24 @@ module DiasporaFederation
described_class.new(magic_env).receive
end
it "allows profiles flagged as private if they don't contain private information" do
profile = Fabricate(:profile_entity, public: false, bio: nil, birthday: nil, gender: nil, location: nil)
magic_env = Salmon::MagicEnvelope.new(profile, profile.author)
expect_callback(:receive_entity, profile, profile.author, nil)
described_class.new(magic_env).receive
end
it "doesn't allow profiles flagged as private if they contain private information" do
profile = Fabricate(:profile_entity, public: false)
magic_env = Salmon::MagicEnvelope.new(profile, profile.author)
expect {
described_class.new(magic_env).receive
}.to raise_error Federation::Receiver::NotPublic
end
end
context "with text" do