Skip to content

Commit 06d2909

Browse files
committed
verify callback test
1 parent 4534030 commit 06d2909

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

qiniu/compat.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
basestring = basestring # noqa
4343
numeric_types = (int, long, float) # noqa
4444

45-
def b(s):
46-
return s
45+
def b(data):
46+
return data
4747

48-
def s(b):
49-
return b
48+
def s(data):
49+
return data
5050

51-
def u(s):
52-
return unicode(s, 'unicode_escape') # noqa
51+
def u(data):
52+
return unicode(data, 'unicode_escape') # noqa
5353

5454
elif is_py3:
5555
from urllib.parse import urlparse # noqa
@@ -63,15 +63,15 @@ def u(s):
6363
basestring = (str, bytes)
6464
numeric_types = (int, float)
6565

66-
def b(s):
67-
if isinstance(s, str):
68-
return s.encode('utf-8')
69-
return s
66+
def b(data):
67+
if isinstance(data, str):
68+
return data.encode('utf-8')
69+
return data
7070

71-
def s(b):
72-
if isinstance(b, bytes):
73-
b = b.decode('utf-8')
74-
return b
71+
def s(data):
72+
if isinstance(data, bytes):
73+
data = data.decode('utf-8')
74+
return data
7575

76-
def u(s):
77-
return s
76+
def u(data):
77+
return data

qiniu/services/storage/uploader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def put_file(up_token, key, file_path, params=None, mime_type='application/octet
2929
return ret, info
3030

3131

32-
def _form_put(up_token, key, data, params, mime_type, crc32, is_file=False, progress_handler=None):
32+
def _form_put(up_token, key, data, params, mime_type, crc, is_file=False, progress_handler=None):
3333
fields = {}
3434
if params:
3535
for k, v in params.items():
3636
fields[k] = str(v)
37-
if crc32:
38-
fields['crc32'] = crc32
37+
if crc:
38+
fields['crc32'] = crc
3939
if key is not None:
4040
fields['key'] = key
4141
fields['token'] = up_token

qiniu/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def _etag(input_stream):
5656
data = array[0]
5757
prefix = b('\x16')
5858
else:
59-
s = b('').join(array)
60-
data = _sha1(s)
59+
sha1_str = b('').join(array)
60+
data = _sha1(sha1_str)
6161
prefix = b('\x96')
6262
return urlsafe_base64_encode(prefix + data)
6363

test_qiniu.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ def test_deprecatedPolicy(self):
8888
with pytest.raises(ValueError):
8989
dummy_auth.upload_token('1', None, policy={'asyncOps': 1})
9090

91+
def test_token_of_request(self):
92+
token = dummy_auth.token_of_request('http://www.qiniu.com?go=1', 'test', '')
93+
assert token == 'abcdefghklmnopq:cFyRVoWrE3IugPIMP5YJFTO-O-Y='
94+
token = dummy_auth.token_of_request('http://www.qiniu.com?go=1', 'test', 'application/x-www-form-urlencoded')
95+
assert token == 'abcdefghklmnopq:svWRNcacOE-YMsc70nuIYdaa1e4='
96+
97+
def test_verify_callback(self):
98+
body = 'name=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm-RlQx_4O2&location=Shanghai&price=1500.00&uid=123'
99+
url = 'test.qiniu.com/callback'
100+
ok = dummy_auth.verify_callback('QBox abcdefghklmnopq:ZWyeM5ljWMRFwuPTPOwQ4RwSto4=', url, body)
101+
assert ok
102+
91103

92104
class BucketTestCase(unittest.TestCase):
93105
q = Auth(access_key, secret_key)
@@ -226,7 +238,7 @@ def test_putInvalidCrc(self):
226238
data = 'hello bubby!'
227239
crc32 = 'wrong crc32'
228240
token = self.q.upload_token(bucket_name)
229-
ret, info = _form_put(token, key, data, None, None, crc32=crc32)
241+
ret, info = _form_put(token, key, data, None, None, crc=crc32)
230242
print(info)
231243
assert ret is None
232244
assert info.status_code == 400

0 commit comments

Comments
 (0)