Skip to content

Change request_iteration_count to use a GET request #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions lastpass/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def fetch(session, web_client=http):


def request_iteration_count(username, web_client=http):
response = web_client.post('https://lastpass.com/iterations.php',
data={'email': username},
headers=headers)
response = web_client.get('https://lastpass.com/iterations.php',
params={'email': username},
headers=headers)
if response.status_code != requests.codes.ok:
raise NetworkError()

Expand Down
18 changes: 9 additions & 9 deletions tests/test_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,35 @@ def test_logout_raises_an_exception_on_HTTP_error(self):

def test_request_iteration_count_makes_a_post_request(self):
m = mock.Mock()
m.post.return_value = self._http_ok(str(self.key_iteration_count))
m.get.return_value = self._http_ok(str(self.key_iteration_count))
fetcher.request_iteration_count(self.username, m)
m.post.assert_called_with('https://lastpass.com/iterations.php',
data={'email': self.username},
headers=fetcher.headers)
m.get.assert_called_with('https://lastpass.com/iterations.php',
params={'email': self.username},
headers=fetcher.headers)

def test_request_iteration_count_returns_key_iteration_count(self):
m = mock.Mock()
m.post.return_value = self._http_ok(str(self.key_iteration_count))
m.get.return_value = self._http_ok(str(self.key_iteration_count))
self.assertEqual(fetcher.request_iteration_count(self.username, m), self.key_iteration_count)

def test_request_iteration_count_raises_an_exception_on_http_error(self):
m = mock.Mock()
m.post.return_value = self._http_error()
m.get.return_value = self._http_error()
self.assertRaises(lastpass.NetworkError, fetcher.request_iteration_count, self.username, m)

def test_request_iteration_count_raises_an_exception_on_invalid_key_iteration_count(self):
m = mock.Mock()
m.post.return_value = self._http_ok('not a number')
m.get.return_value = self._http_ok('not a number')
self.assertRaises(lastpass.InvalidResponseError, fetcher.request_iteration_count, self.username, m)

def test_request_iteration_count_raises_an_exception_on_zero_key_iteration_cont(self):
m = mock.Mock()
m.post.return_value = self._http_ok('0')
m.get.return_value = self._http_ok('0')
self.assertRaises(lastpass.InvalidResponseError, fetcher.request_iteration_count, self.username, m)

def test_request_iteration_count_raises_an_exception_on_negative_key_iteration_cont(self):
m = mock.Mock()
m.post.return_value = self._http_ok('-1')
m.get.return_value = self._http_ok('-1')
self.assertRaises(lastpass.InvalidResponseError, fetcher.request_iteration_count, self.username, m)

def test_request_login_makes_a_post_request(self):
Expand Down