2013-10-05 23:12:31 +02:00
|
|
|
import unittest
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2016-07-18 22:36:06 +02:00
|
|
|
from werkzeug.exceptions import BadRequest
|
2013-10-05 23:12:31 +02:00
|
|
|
|
2016-07-18 20:52:37 +02:00
|
|
|
# noinspection PyPep8Naming
|
2013-10-05 23:12:31 +02:00
|
|
|
import snappass.main as snappass
|
|
|
|
|
|
|
|
__author__ = 'davedash'
|
|
|
|
|
|
|
|
|
|
|
|
class SnapPassTestCase(TestCase):
|
|
|
|
|
|
|
|
def test_set_password(self):
|
|
|
|
"""Ensure we return a 32-bit key."""
|
|
|
|
key = snappass.set_password("foo", 30)
|
|
|
|
self.assertEqual(32, len(key))
|
|
|
|
|
|
|
|
def test_get_password(self):
|
|
|
|
password = "melatonin overdose 1337!$"
|
|
|
|
key = snappass.set_password(password, 30)
|
|
|
|
self.assertEqual(password, snappass.get_password(key))
|
|
|
|
# Assert that we can't look this up a second time.
|
|
|
|
self.assertEqual(None, snappass.get_password(key))
|
|
|
|
|
|
|
|
def test_clean_input(self):
|
|
|
|
# Test Bad Data
|
|
|
|
with snappass.app.test_request_context(
|
|
|
|
"/", data={'password': 'foo', 'ttl': 'bar'}, method='POST'):
|
2016-07-18 22:36:06 +02:00
|
|
|
self.assertRaises(BadRequest, snappass.clean_input)
|
2013-10-05 23:12:31 +02:00
|
|
|
|
|
|
|
# No Password
|
|
|
|
with snappass.app.test_request_context(
|
|
|
|
"/", method='POST'):
|
2016-07-18 22:36:06 +02:00
|
|
|
self.assertRaises(BadRequest, snappass.clean_input)
|
2013-10-05 23:12:31 +02:00
|
|
|
|
|
|
|
# No TTL
|
|
|
|
with snappass.app.test_request_context(
|
|
|
|
"/", data={'password': 'foo'}, method='POST'):
|
2016-07-18 22:36:06 +02:00
|
|
|
self.assertRaises(BadRequest, snappass.clean_input)
|
2013-10-05 23:12:31 +02:00
|
|
|
|
|
|
|
with snappass.app.test_request_context(
|
|
|
|
"/", data={'password': 'foo', 'ttl': 'hour'}, method='POST'):
|
|
|
|
self.assertEqual((3600, 'foo'), snappass.clean_input())
|
|
|
|
|
|
|
|
|
|
|
|
class SnapPassRoutesTestCase(TestCase):
|
2016-07-18 20:52:37 +02:00
|
|
|
# noinspection PyPep8Naming
|
2013-10-05 23:12:31 +02:00
|
|
|
def setUp(self):
|
|
|
|
snappass.app.config['TESTING'] = True
|
|
|
|
self.app = snappass.app.test_client()
|
|
|
|
|
|
|
|
def test_show_password(self):
|
|
|
|
password = "I like novelty kitten statues!"
|
|
|
|
key = snappass.set_password(password, 30)
|
|
|
|
rv = self.app.get('/{}'.format(key))
|
|
|
|
self.assertIn(password, rv.data)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|