def post(self): data = json.loads(self.request.body.decode()) if data.get('username') == USERNAME: data['password'] = hashlib.md5(PASSWORD.encode()).hexdigest() signature = upyun.make_signature(**data) print(signature) self.write(signature) else: print('Unknow username:'******'username'))
def test_make_signature(self): headers = { 'Date': 'Fri, 20 Jan 2017 08:46:20 GMT', 'Content-MD5': 'd36489794822f8d33fd28217d8a5bed4', 'Authorization': 'UPYUN upyun:kfIIHZ+vY9qwp+cZXE2m7jGWzcE=' } self.assertEqual( headers['Authorization'], upyun.make_signature(username='******', password='******', method='POST', uri='/api/v1/echo', date=headers['Date'], content_md5=headers['Content-MD5']))