From f526f0c1fefadd2251b3972b702db0d0a6127269 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Sat, 31 Mar 2018 18:41:03 +0200
Subject: [PATCH] More flexible auth signature factory

---
 api/funkwhale_api/federation/factories.py | 32 ++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/api/funkwhale_api/federation/factories.py b/api/funkwhale_api/federation/factories.py
index 3cfecfa9..e290eee6 100644
--- a/api/funkwhale_api/federation/factories.py
+++ b/api/funkwhale_api/federation/factories.py
@@ -16,7 +16,12 @@ class SignatureAuthFactory(factory.Factory):
     key = factory.LazyFunction(lambda: keys.get_key_pair()[0])
     key_id = factory.Faker('url')
     use_auth_header = False
-
+    headers = [
+        '(request-target)',
+        'user-agent',
+        'host',
+        'date',
+        'content-type',]
     class Meta:
         model = requests_http_signature.HTTPSignatureAuth
 
@@ -29,3 +34,28 @@ class SignedRequestFactory(factory.Factory):
 
     class Meta:
         model = requests.Request
+
+    @factory.post_generation
+    def headers(self, create, extracted, **kwargs):
+        default_headers = {
+            'User-Agent': 'Test',
+            'Host': 'test.host',
+            'Date': 'Right now',
+            'Content-Type': 'application/activity+json'
+        }
+        if extracted:
+            default_headers.update(extracted)
+        self.headers.update(default_headers)
+
+
+# @registry.register
+# class ActorFactory(factory.DjangoModelFactory):
+#     url = factory.Faker('url')
+#     inbox_url = factory.Faker('url')
+#     outbox_url = factory.Faker('url')
+#     public_key = factory.LazyFunction(lambda: keys.get_key_pair()[1])
+#     preferred_username = factory.Faker('username')
+#     summary = factory.Faker('paragraph')
+#
+#     class Meta:
+#         model = models.Actor
-- 
GitLab