[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [bridgedb/master] The JSON data coming into moat is being processed as a str.
commit 8b4f7367e82636701997acbb57ae463c4471e3c4
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date: Tue Feb 13 20:02:47 2018 +0000
The JSON data coming into moat is being processed as a str.
Duck-typing is why we can't have nice things.
---
bridgedb/distributors/moat/server.py | 14 +++++++-------
bridgedb/test/test_distributors_moat_server.py | 22 +++++++++++-----------
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/bridgedb/distributors/moat/server.py b/bridgedb/distributors/moat/server.py
index d1d0b10..4137f51 100644
--- a/bridgedb/distributors/moat/server.py
+++ b/bridgedb/distributors/moat/server.py
@@ -185,7 +185,7 @@ class JsonAPIErrorResource(JsonAPIResource):
object.
"""
resource.Resource.__init__(self)
- self.id = id
+ self.id = "%s" % id
self.type = type
self.code = code
self.status = status
@@ -452,7 +452,7 @@ class CaptchaFetchResource(CaptchaResource):
data = {
'data': [{
- 'id': 1,
+ 'id': '1',
'type': 'moat-challenge',
'version': MOAT_API_VERSION,
'transport': preferred,
@@ -565,7 +565,7 @@ class CaptchaCheckResource(CaptchaResource):
raise ValueError(
"Bad JSON API object type: expected %s got %s" %
("moat-solution", data["type"]))
- elif data["id"] != 2:
+ elif data["id"] != "2":
raise ValueError(
"Bad JSON API data id: expected 2 got %s" %
(data["id"]))
@@ -632,15 +632,15 @@ class CaptchaCheckResource(CaptchaResource):
"""
if id == 4:
error_response = resource419
- error_response.id = 4
+ error_response.id = "4"
error_response.detail = "The CAPTCHA solution was incorrect."
elif id == 5:
error_response = resource419
- error_response.id = 5
+ error_response.id = "5"
error_response.detail = "The CAPTCHA challenge timed out."
elif id == 6:
error_response = resource404
- error_response.id = 6
+ error_response.id = "6"
error_response.detail = ("No bridges available to fulfill "
"request: %s.") % bridgeRequest
@@ -673,7 +673,7 @@ class CaptchaCheckResource(CaptchaResource):
data = {
"data": [{
- "id": 3,
+ "id": '3',
"type": 'moat-bridges',
"version": MOAT_API_VERSION,
"bridges": None,
diff --git a/bridgedb/test/test_distributors_moat_server.py b/bridgedb/test/test_distributors_moat_server.py
index 2f84557..f29f224 100644
--- a/bridgedb/test/test_distributors_moat_server.py
+++ b/bridgedb/test/test_distributors_moat_server.py
@@ -233,7 +233,7 @@ class JsonAPIErrorResourceTests(unittest.TestCase):
self.use_resource(server.JsonAPIErrorResource())
error = self.do_render_for_method(b'GET')
- self.assertEqual(error['id'], 0)
+ self.assertEqual(error['id'], '0')
self.assertEqual(error['type'], '')
self.assertEqual(error['code'], 200)
self.assertEqual(error['status'], 'OK')
@@ -640,7 +640,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
def create_valid_POST_with_challenge(self, challenge):
data = {
'data': [{
- 'id': 2,
+ 'id': '2',
'type': 'moat-solution',
'version': server.MOAT_API_VERSION,
'transport': 'obfs4',
@@ -674,7 +674,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
def test_withoutBlockIn(self):
data = {
'data': [{
- 'id': 2,
+ 'id': '2',
'type': 'moat-solution',
'version': server.MOAT_API_VERSION,
'transport': 'obfs4',
@@ -740,7 +740,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
def test_extractClientSolution_weird_transport(self):
data = {
'data': [{
- 'id': 2,
+ 'id': '2',
'type': 'moat-solution',
'version': server.MOAT_API_VERSION,
'transport': 'dinosaur',
@@ -759,7 +759,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
def test_extractClientSolution_wrong_version(self):
data = {
'data': [{
- 'id': 2,
+ 'id': '2',
'type': 'moat-solution',
'version': '0.0.1', # this version never existed
'transport': 'obfs4',
@@ -778,7 +778,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
def test_extractClientSolution_wrong_type(self):
data = {
'data': [{
- 'id': 2,
+ 'id': '2',
'type': 'boat-revolution',
'version': server.MOAT_API_VERSION,
'transport': 'obfs4',
@@ -809,7 +809,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
self.assertEqual(error['status'], "No You're A Teapot")
self.assertEqual(error['code'], 419)
self.assertEqual(error['detail'], "The CAPTCHA challenge timed out.")
- self.assertEqual(error['id'], 5)
+ self.assertEqual(error['id'], '5')
def test_checkSolution(self):
request = self.create_valid_POST_make_new_challenge()
@@ -840,7 +840,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
self.assertEqual(error['detail'], "The CAPTCHA solution was incorrect.")
self.assertEqual(error['version'], server.MOAT_API_VERSION)
self.assertEqual(error['type'], "moat-bridges")
- self.assertEqual(error['id'], 4)
+ self.assertEqual(error['id'], '4')
def test_createBridgeRequest(self):
request = self.create_valid_POST_with_challenge(self.expiredChallenge)
@@ -909,7 +909,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
self.assertIsNotNone(data['bridges'])
self.assertEqual(data['version'], server.MOAT_API_VERSION)
self.assertEqual(data['type'], 'moat-bridges')
- self.assertEqual(data['id'], 3)
+ self.assertEqual(data['id'], '3')
def test_render_POST_unexpired_with_qrcode(self):
request = DummyRequest([self.pagename])
@@ -925,7 +925,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
data = {
'data': [{
- 'id': 2,
+ 'id': '2',
'type': 'moat-solution',
'version': server.MOAT_API_VERSION,
'transport': 'obfs4',
@@ -953,7 +953,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
self.assertIsNotNone(data['bridges'])
self.assertEqual(data['version'], server.MOAT_API_VERSION)
self.assertEqual(data['type'], 'moat-bridges')
- self.assertEqual(data['id'], 3)
+ self.assertEqual(data['id'], '3')
class AddMoatServerTests(unittest.TestCase):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits