Skip to content

Commit

Permalink
Fixed dump pubkey
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Mar 27, 2017
1 parent 073050f commit cacf1d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions openprocurement/archivarius/core/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def test_dump_resource(self, mock_crypto_box_keypair):
'doc_type': 'Tenders'
}
request.context.serialize.return_value = context
res, key = dump_resource(request)
dump = dump_resource(request)
res, key = dump['item'], dump['pubkey']
decrypt_box = Box("b"*32, "c"*32)
decrypted_data = decrypt_box.decrypt(b64decode(res))
decrypted_data = json.loads(decrypted_data)
Expand All @@ -140,7 +141,7 @@ def test_dump(self, mock_crypto_box_keypair):
response = self.app.get('/tenders/abc/dump')
encrypted_dump = response.json['data']['tender']
archive_box = self.config.registry.decr_box
decrypted_data = archive_box.decrypt(b64decode(encrypted_dump[0]))
decrypted_data = archive_box.decrypt(b64decode(encrypted_dump['item']))
decrypted_data = json.loads(decrypted_data)
self.assertEqual(response.status, '200 OK')
self.assertEqual(decrypted_data, tender.serialize.return_value)
Expand All @@ -157,7 +158,7 @@ def test_delete(self, mock_error_handler, mock_context_unpack, mock_crypto_box_k
response = self.app.delete('/tenders/abc/dump')
encrypted_dump = response.json['data']['tender']
archive_box = self.config.registry.decr_box
decrypted_data = archive_box.decrypt(b64decode(encrypted_dump[0]))
decrypted_data = archive_box.decrypt(b64decode(encrypted_dump['item']))
decrypted_data = json.loads(decrypted_data)
self.assertEqual(response.status, '200 OK')
self.assertEqual(decrypted_data, tender.serialize.return_value)
5 changes: 3 additions & 2 deletions openprocurement/archivarius/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ def delete_resource(request):
def dump_resource(request):
arch_pubkey = getattr(request.registry, 'arch_pubkey', None)
res_secretkey = SecretKey()
archive_box = Box(res_secretkey.sk, arch_pubkey)
archive_box = Box(res_secretkey, arch_pubkey)
res_pubkey = res_secretkey.pk
del res_secretkey
data = request.context.serialize()
json_data = dumps(data)
encrypted_data = archive_box.encrypt(json_data)
return b64encode(encrypted_data), res_pubkey
return {'item': b64encode(encrypted_data), 'pubkey': b64encode(res_pubkey)}


class ArchivariusResource(APIResource):

Expand Down

0 comments on commit cacf1d3

Please sign in to comment.