Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ virtualenv:

env:
global:
- VERSION="0.1.0"
- RELEASE="0.0.2"
- VERSION="0.2"
- RELEASE="0.2.1"
- PROJECT="Python Red October"
- BRANCH_PROD="master"
- BRANCH_DOC="gh-pages"
Expand Down
18 changes: 11 additions & 7 deletions red_october/red_october.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# Copyright 2016-2017 LasLabs Inc.
# License MIT (https://opensource.org/licenses/MIT).

import json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why import the entire library instead of what you're using? :)

from json import loads

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shitty namespace of loads and dumps basically. import json.loads doesn't work either 😦

>>> import json.loads
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named loads

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's (sadpanda)

import requests

from datetime import timedelta
Expand Down Expand Up @@ -152,13 +153,19 @@ def decrypt(self, data):
the set of ``owners`` have delegated their keys to the server,
or if the decryption credentials are incorrect.
Returns:
str: Decrypted string
dict: Response object with the following keys:
* `Data` (`str`): Decrypted data
* `Secure` (`bool`): Not documented. Seems to always be `True`
* `Delegates` (`list` of `str`): Delegate names
"""
data = self._clean_mapping({
'Data': data,
})
try:
return self.call('decrypt', data=data)
response = self.call('decrypt', data=data)
response = json.loads(response.decode('base64'))
response['Data'] = response['Data'].decode('base64')
return response
except RedOctoberRemoteException as e:
raise RedOctoberDecryptException(e.message)

Expand Down Expand Up @@ -366,10 +373,7 @@ def call(self, endpoint, method='POST', params=None, data=None):
response = response.json()
if response['Status'] != 'ok':
raise RedOctoberRemoteException(
'\n'.join([
'Response:',
'\n'.join(response.get('Response', [])),
])
response['Status'],
)
try:
return response['Response']
Expand Down
22 changes: 20 additions & 2 deletions red_october/tests/test_red_october.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2016 LasLabs Inc.
# Copyright 2016-2017 LasLabs Inc.
# License MIT (https://opensource.org/licenses/MIT).

import json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, why not just import dumps?

import mock
import unittest

Expand Down Expand Up @@ -87,14 +88,31 @@ def test_encrypt(self, call):
call.assert_called_once_with('encrypt', data=expect)

@mock.patch.object(RedOctober, 'call')
def test_decrypt(self, call):
def test_decrypt_call(self, call):
""" It should call with proper args """
expect = {
'Data': self.data64,
}
response = {
'Data': self.data64,
}
call.return_value = json.dumps(response).encode('base64')
self.red_october.decrypt(self.data64)
call.assert_called_once_with('decrypt', data=expect)

@mock.patch.object(RedOctober, 'call')
def test_decrypt_return(self, call):
""" It should return proper value. """
expect = {
'Data': self.data64,
'Secure': True,
'Delegates': self.owners,
}
call.return_value = json.dumps(expect).encode('base64')
res = self.red_october.decrypt(self.data64)
expect['Data'] = expect['Data'].decode('base64')
self.assertDictEqual(res, expect)

@mock.patch.object(RedOctober, 'call')
def test_decrypt_fail(self, call):
""" It should raise proper error on failure. """
Expand Down