[extensions-web] update-info: allow POST requests
- From: Yuri Konotopov <ykonotopov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] update-info: allow POST requests
- Date: Sun, 13 Jan 2019 07:35:49 +0000 (UTC)
commit 0b38da1b2b440db1b4eb767cff74acf8f8de18e0
Author: Yuri Konotopov <ykonotopov gnome org>
Date: Sun Jan 13 11:03:44 2019 +0400
update-info: allow POST requests
Since json-encoded list of installed extensions may be big enough it
should be provided in POST request.
Deprecate GET requests for '/update-info/' API.
Bug: https://github.com/nE0sIghT/chrome-gnome-shell-mirror/issues/97
sweettooth/extensions/tests.py | 28 ++++++++++++++++++++++++++++
sweettooth/extensions/views.py | 6 +++++-
2 files changed, 33 insertions(+), 1 deletion(-)
---
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index d086790..0346279 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -472,6 +472,14 @@ class UpdateVersionTest(TestCase):
return json.loads(response.content.decode(response.charset))
+ def grab_post_response(self, installed):
+ installed = self.build_response(installed)
+ response = self.client.post(reverse('extensions-shell-update') + "?shell_version=3.2.0",
+ data=json.dumps(installed),
+ content_type='application/json')
+
+ return json.loads(response.content.decode(response.charset))
+
def test_upgrade_me(self):
uuid = self.upgrade_uuid
@@ -479,10 +487,14 @@ class UpdateVersionTest(TestCase):
expected = {uuid: self.full_expected[self.upgrade_uuid]}
response = self.grab_response({ uuid: 1 })
self.assertEqual(response, expected)
+ response = self.grab_post_response({ uuid: 1 })
+ self.assertEqual(response, expected)
# The user has a newer version on his machine.
response = self.grab_response({ uuid: 2 })
self.assertEqual(response, {})
+ response = self.grab_post_response({ uuid: 2 })
+ self.assertEqual(response, {})
def test_reject_me(self):
uuid = self.reject_uuid
@@ -490,10 +502,14 @@ class UpdateVersionTest(TestCase):
expected = {uuid: self.full_expected[self.reject_uuid]}
response = self.grab_response({ uuid: 1 })
self.assertEqual(response, expected)
+ response = self.grab_post_response({ uuid: 1 })
+ self.assertEqual(response, expected)
# The user has a newer version than what's on the site.
response = self.grab_response({ uuid: 2 })
self.assertEqual(response, {})
+ response = self.grab_post_response({ uuid: 2 })
+ self.assertEqual(response, {})
def test_downgrade_me(self):
uuid = self.downgrade_uuid
@@ -502,15 +518,21 @@ class UpdateVersionTest(TestCase):
expected = { uuid: self.full_expected[self.downgrade_uuid] }
response = self.grab_response({ uuid: 2 })
self.assertEqual(response, expected)
+ response = self.grab_post_response({ uuid: 2 })
+ self.assertEqual(response, expected)
# The user has the appropriate version on his machine.
response = self.grab_response({ uuid: 1 })
self.assertEqual(response, {})
+ response = self.grab_post_response({ uuid: 1 })
+ self.assertEqual(response, {})
def test_nonexistent_uuid(self):
# The user has an extension that's not on the site.
response = self.grab_response({ self.nonexistant_uuid: 1 })
self.assertEqual(response, {})
+ response = self.grab_post_response({ self.nonexistant_uuid: 1 })
+ self.assertEqual(response, {})
def test_multiple(self):
installed = { self.upgrade_uuid: 1,
@@ -520,6 +542,8 @@ class UpdateVersionTest(TestCase):
response = self.grab_response(installed)
self.assertEqual(self.full_expected, response)
+ response = self.grab_post_response(installed)
+ self.assertEqual(self.full_expected, response)
def test_wrong_version(self):
uuid = self.upgrade_uuid
@@ -528,10 +552,14 @@ class UpdateVersionTest(TestCase):
expected = {uuid: self.full_expected[self.upgrade_uuid]}
response = self.grab_response({uuid: ''})
self.assertEqual(response, expected)
+ response = self.grab_post_response({uuid: ''})
+ self.assertEqual(response, expected)
expected = {uuid: self.full_expected[self.upgrade_uuid]}
response = self.grab_response({uuid: '0.8.4'})
self.assertEqual(response, expected)
+ response = self.grab_post_response({uuid: '0.8.4'})
+ self.assertEqual(response, expected)
class QueryExtensionsTest(BasicUserTestCase, TestCase):
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index a7c15da..abdb88a 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -108,7 +108,11 @@ def shell_download(request, uuid):
@ajax_view
def shell_update(request):
try:
- installed = json.loads(request.GET['installed'])
+ if request.method == 'POST':
+ installed = json.load(request)
+ # TODO: drop GET request support at year after chrome-gnome-shell 11 release
+ else:
+ installed = json.loads(request.GET['installed'])
shell_version = request.GET['shell_version']
disable_version_validation = request.GET.get('disable_version_validation', False)
except (KeyError, ValueError):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]