about summary refs log tree commit diff
path: root/spec/lib/activitypub/activity/create_spec.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2020-06-02 19:24:53 +0200
committerGitHub <noreply@github.com>2020-06-02 19:24:53 +0200
commit5d8398c8b8b51ee7363e7d45acc560f489783e34 (patch)
tree1e0b663049feafdc003ad3c01b25bf5d5d793402 /spec/lib/activitypub/activity/create_spec.rb
parent9b7e3b4774d47c184aa759364d41f40e0cdfa210 (diff)
Add E2EE API (#13820)
Diffstat (limited to 'spec/lib/activitypub/activity/create_spec.rb')
-rw-r--r--spec/lib/activitypub/activity/create_spec.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb
index 5220deabb..2ac4acc12 100644
--- a/spec/lib/activitypub/activity/create_spec.rb
+++ b/spec/lib/activitypub/activity/create_spec.rb
@@ -579,6 +579,62 @@ RSpec.describe ActivityPub::Activity::Create do
       end
     end
 
+    context 'with an encrypted message' do
+      let(:recipient) { Fabricate(:account) }
+      let(:target_device) { Fabricate(:device, account: recipient) }
+
+      subject { described_class.new(json, sender, delivery: true, delivered_to_account_id: recipient.id) }
+
+      let(:object_json) do
+        {
+          id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
+          type: 'EncryptedMessage',
+          attributedTo: {
+            type: 'Device',
+            deviceId: '1234',
+          },
+          to: {
+            type: 'Device',
+            deviceId: target_device.device_id,
+          },
+          messageType: 1,
+          cipherText: 'Foo',
+          messageFranking: 'Baz678',
+          digest: {
+            digestAlgorithm: 'Bar456',
+            digestValue: 'Foo123',
+          },
+        }
+      end
+
+      before do
+        subject.perform
+      end
+
+      it 'creates an encrypted message' do
+        encrypted_message = target_device.encrypted_messages.reload.first
+
+        expect(encrypted_message).to_not be_nil
+        expect(encrypted_message.from_device_id).to eq '1234'
+        expect(encrypted_message.from_account).to eq sender
+        expect(encrypted_message.type).to eq 1
+        expect(encrypted_message.body).to eq 'Foo'
+        expect(encrypted_message.digest).to eq 'Foo123'
+      end
+
+      it 'creates a message franking' do
+        encrypted_message = target_device.encrypted_messages.reload.first
+        message_franking  = encrypted_message.message_franking
+
+        crypt = ActiveSupport::MessageEncryptor.new(SystemKey.current_key, serializer: Oj)
+        json  = crypt.decrypt_and_verify(message_franking)
+
+        expect(json['source_account_id']).to eq sender.id
+        expect(json['target_account_id']).to eq recipient.id
+        expect(json['original_franking']).to eq 'Baz678'
+      end
+    end
+
     context 'when sender is followed by local users' do
       subject { described_class.new(json, sender, delivery: true) }