forked from mirrors/bookwyrm
Fixes celery mocks on more signature unit tests
This commit is contained in:
parent
73279d65d7
commit
829615cdd7
1 changed files with 57 additions and 56 deletions
|
@ -111,55 +111,56 @@ class Signature(TestCase):
|
|||
response = self.send_test_request(sender=self.fake_remote)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# @responses.activate
|
||||
# def test_key_needs_refresh(self):
|
||||
# datafile = pathlib.Path(__file__).parent.joinpath('data/ap_user.json')
|
||||
# data = json.loads(datafile.read_bytes())
|
||||
# data['id'] = self.fake_remote.remote_id
|
||||
# data['publicKey']['publicKeyPem'] = self.fake_remote.public_key
|
||||
# del data['icon'] # Avoid having to return an avatar.
|
||||
# responses.add(
|
||||
# responses.GET,
|
||||
# self.fake_remote.remote_id,
|
||||
# json=data,
|
||||
# status=200)
|
||||
# responses.add(
|
||||
# responses.GET,
|
||||
# 'https://localhost/.well-known/nodeinfo',
|
||||
# status=404)
|
||||
# responses.add(
|
||||
# responses.GET,
|
||||
# 'https://example.com/user/mouse/outbox?page=true',
|
||||
# json={'orderedItems': []},
|
||||
# status=200
|
||||
# )
|
||||
#
|
||||
# # Second and subsequent fetches get a different key:
|
||||
# new_private_key, new_public_key = create_key_pair()
|
||||
# new_sender = Sender(
|
||||
# self.fake_remote.remote_id, new_private_key, new_public_key)
|
||||
# data['publicKey']['publicKeyPem'] = new_public_key
|
||||
# responses.add(
|
||||
# responses.GET,
|
||||
# self.fake_remote.remote_id,
|
||||
# json=data,
|
||||
# status=200)
|
||||
#
|
||||
# # Key correct:
|
||||
# response = self.send_test_request(sender=self.fake_remote)
|
||||
# self.assertEqual(response.status_code, 200)
|
||||
#
|
||||
# # Old key is cached, so still works:
|
||||
# response = self.send_test_request(sender=self.fake_remote)
|
||||
# self.assertEqual(response.status_code, 200)
|
||||
#
|
||||
# # Try with new key:
|
||||
# response = self.send_test_request(sender=new_sender)
|
||||
# self.assertEqual(response.status_code, 200)
|
||||
#
|
||||
# # Now the old key will fail:
|
||||
# response = self.send_test_request(sender=self.fake_remote)
|
||||
# self.assertEqual(response.status_code, 401)
|
||||
@responses.activate
|
||||
def test_key_needs_refresh(self):
|
||||
datafile = pathlib.Path(__file__).parent.joinpath('data/ap_user.json')
|
||||
data = json.loads(datafile.read_bytes())
|
||||
data['id'] = self.fake_remote.remote_id
|
||||
data['publicKey']['publicKeyPem'] = self.fake_remote.public_key
|
||||
del data['icon'] # Avoid having to return an avatar.
|
||||
responses.add(
|
||||
responses.GET,
|
||||
self.fake_remote.remote_id,
|
||||
json=data,
|
||||
status=200)
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://localhost/.well-known/nodeinfo',
|
||||
status=404)
|
||||
responses.add(
|
||||
responses.GET,
|
||||
'https://example.com/user/mouse/outbox?page=true',
|
||||
json={'orderedItems': []},
|
||||
status=200
|
||||
)
|
||||
|
||||
# Second and subsequent fetches get a different key:
|
||||
new_private_key, new_public_key = create_key_pair()
|
||||
new_sender = Sender(
|
||||
self.fake_remote.remote_id, new_private_key, new_public_key)
|
||||
data['publicKey']['publicKeyPem'] = new_public_key
|
||||
responses.add(
|
||||
responses.GET,
|
||||
self.fake_remote.remote_id,
|
||||
json=data,
|
||||
status=200)
|
||||
|
||||
with patch('bookwyrm.remote_user.get_remote_reviews.delay') as _:
|
||||
# Key correct:
|
||||
response = self.send_test_request(sender=self.fake_remote)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Old key is cached, so still works:
|
||||
response = self.send_test_request(sender=self.fake_remote)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Try with new key:
|
||||
response = self.send_test_request(sender=new_sender)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Now the old key will fail:
|
||||
response = self.send_test_request(sender=self.fake_remote)
|
||||
self.assertEqual(response.status_code, 401)
|
||||
|
||||
|
||||
@responses.activate
|
||||
|
@ -173,13 +174,13 @@ class Signature(TestCase):
|
|||
response = self.send_test_request(sender=self.fake_remote)
|
||||
self.assertEqual(response.status_code, 401)
|
||||
|
||||
# @pytest.mark.integration
|
||||
# def test_changed_data(self):
|
||||
# '''Message data must match the digest header.'''
|
||||
# response = self.send_test_request(
|
||||
# self.mouse,
|
||||
# send_data=get_follow_data(self.mouse, self.cat))
|
||||
# self.assertEqual(response.status_code, 401)
|
||||
@pytest.mark.integration
|
||||
def test_changed_data(self):
|
||||
'''Message data must match the digest header.'''
|
||||
response = self.send_test_request(
|
||||
self.mouse,
|
||||
send_data=get_follow_data(self.mouse, self.cat))
|
||||
self.assertEqual(response.status_code, 401)
|
||||
|
||||
# @pytest.mark.integration
|
||||
# def test_invalid_digest(self):
|
||||
|
|
Loading…
Reference in a new issue