forked from mirrors/bookwyrm
Fixes generating new key paris for user
and the broadcast test
This commit is contained in:
parent
eb6206252d
commit
fee5846aa8
5 changed files with 15 additions and 15 deletions
|
@ -65,7 +65,7 @@ def sign_and_send(sender, data, destination):
|
|||
''' crpyto whatever and http junk '''
|
||||
now = http_date()
|
||||
|
||||
if not sender.private_key:
|
||||
if not sender.key_pair.private_key:
|
||||
# this shouldn't happen. it would be bad if it happened.
|
||||
raise ValueError('No private key found for sender')
|
||||
|
||||
|
|
|
@ -98,15 +98,15 @@ def has_valid_signature(request, activity):
|
|||
remote_user = activitypub.resolve_remote_id(models.User, key_actor)
|
||||
|
||||
try:
|
||||
signature.verify(remote_user.public_key, request)
|
||||
signature.verify(remote_user.key_pair.public_key, request)
|
||||
except ValueError:
|
||||
old_key = remote_user.public_key
|
||||
old_key = remote_user.key_pair.public_key
|
||||
activitypub.resolve_remote_id(
|
||||
models.User, remote_user, refresh=True
|
||||
)
|
||||
if remote_user.public_key == old_key:
|
||||
if remote_user.key_pair.public_key == old_key:
|
||||
raise # Key unchanged.
|
||||
signature.verify(remote_user.public_key, request)
|
||||
signature.verify(remote_user.key_pair.public_key, request)
|
||||
except (ValueError, requests.exceptions.HTTPError):
|
||||
return False
|
||||
return True
|
||||
|
|
|
@ -155,8 +155,6 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
|||
self.inbox = '%s/inbox' % self.remote_id
|
||||
self.shared_inbox = 'https://%s/inbox' % DOMAIN
|
||||
self.outbox = '%s/outbox' % self.remote_id
|
||||
if not self.key_pair:
|
||||
self.key_pair = KeyPair.objects.create()
|
||||
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
|
@ -197,6 +195,9 @@ def execute_after_save(sender, instance, created, *args, **kwargs):
|
|||
if not instance.local:
|
||||
set_remote_server.delay(instance.id)
|
||||
|
||||
instance.key_pair = KeyPair.objects.create(
|
||||
remote_id='%s/#main-key' % instance.remote_id)
|
||||
|
||||
shelves = [{
|
||||
'name': 'To Read',
|
||||
'identifier': 'to-read',
|
||||
|
|
|
@ -19,8 +19,8 @@ class User(TestCase):
|
|||
self.assertEqual(self.user.shared_inbox, 'https://%s/inbox' % DOMAIN)
|
||||
self.assertEqual(self.user.inbox, '%s/inbox' % expected_id)
|
||||
self.assertEqual(self.user.outbox, '%s/outbox' % expected_id)
|
||||
self.assertIsNotNone(self.user.private_key)
|
||||
self.assertIsNotNone(self.user.public_key)
|
||||
self.assertIsNotNone(self.user.key_pair.private_key)
|
||||
self.assertIsNotNone(self.user.key_pair.public_key)
|
||||
|
||||
|
||||
def test_user_shelves(self):
|
||||
|
|
|
@ -6,13 +6,12 @@ from bookwyrm import models, broadcast
|
|||
|
||||
class Book(TestCase):
|
||||
def setUp(self):
|
||||
with patch('bookwyrm.models.user.get_remote_reviews.delay'):
|
||||
self.user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword')
|
||||
self.user = models.User.objects.create_user(
|
||||
'mouse', 'mouse@mouse.mouse', 'mouseword', local=True)
|
||||
|
||||
local_follower = models.User.objects.create_user(
|
||||
'joe', 'joe@mouse.mouse', 'jeoword')
|
||||
self.user.followers.add(local_follower)
|
||||
local_follower = models.User.objects.create_user(
|
||||
'joe', 'joe@mouse.mouse', 'jeoword', local=True)
|
||||
self.user.followers.add(local_follower)
|
||||
|
||||
with patch('bookwyrm.models.user.set_remote_server.delay'):
|
||||
follower = models.User.objects.create_user(
|
||||
|
|
Loading…
Reference in a new issue