Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_signature_checker():
token = generate_token()
robot = WeRoBot(token, SESSION_STORAGE=False)
timestamp = str(int(time.time()))
nonce = '12345678'
sign = [token, timestamp, nonce]
sign.sort()
sign = ''.join(sign)
if six.PY3:
sign = sign.encode()
sign = hashlib.sha1(sign).hexdigest()
assert robot.check_signature(timestamp, nonce, sign)
def test_token_generator():
assert not check_token('AA C')
assert check_token(generate_token())
assert 3 <= len(generate_token()) <= 32
def tester(app, token, endpoint):
test_app = webtest.TestApp(app)
response = test_app.get(endpoint, expect_errors=True)
assert response.status_code == 403
timestamp = str(time.time())
nonce = str(random.randint(0, 10000))
signature = get_signature(token, timestamp, nonce)
echostr = generate_token()
params = "?timestamp=%s&nonce=%s&signature=%s&echostr=%s" % (
timestamp, nonce, signature, echostr
)
response = test_app.get(endpoint + params)
assert response.status_code == 200
assert response.body.decode('utf-8') == echostr
response = test_app.get(endpoint, expect_errors=True)
assert response.status_code == 403
assert response.body.decode('utf-8') == u'喵'
xml = """
def test_bottle(wsgi_tester, hello_robot):
from werobot.contrib.bottle import make_view
from bottle import Bottle
token = generate_token()
endpoint = '/werobot_bottle'
hello_robot.token = token
bottle_app = Bottle()
bottle_app.route(endpoint, ['GET', 'POST'], make_view(hello_robot))
wsgi_tester(bottle_app, token=token, endpoint=endpoint)
def test_tornado(self):
token = self.token
timestamp = str(time.time())
nonce = str(random.randint(0, 10000))
signature = get_signature(token, timestamp, nonce)
echostr = generate_token()
params = "?timestamp=%s&nonce=%s&signature=%s&echostr=%s" % (
timestamp, nonce, signature, echostr
)
response = self.fetch(path=self.endpoint + params)
assert response.code == 200
assert response.body.decode('utf-8') == echostr
response = self.fetch(path=self.endpoint, )
assert response.code == 403
assert response.body.decode('utf-8') == u'喵'
xml = """
def test_tornado(wsgi_tester, hello_robot):
from tornado.wsgi import WSGIAdapter
import tornado.web
from werobot.contrib.tornado import make_handler
token = generate_token()
endpoint = r'/werobot_tornado'
hello_robot.token = token
tornado_app = tornado.web.Application(
[
(endpoint, make_handler(hello_robot)),
], debug=True
)
wsgi_tester(WSGIAdapter(tornado_app), token=token, endpoint=endpoint)
else: