summaryrefslogtreecommitdiff
path: root/tests/test_scrypt_py2x.py
blob: 811cf3793e9f0617bc0770ef8a932ce01edc0160 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-

from sys import version_info

if ((version_info > (3, 2, 0, 'final', 0)) or
    (version_info > (2, 7, 0, 'final', 0) and version_info < (3, 0, 0, 'final', 0))):
    import unittest as testm
else:
    try:
        import unittest2 as testm
    except ImportError:
        print("Please install unittest2 to run the test suite")
        exit(-1)

import scrypt


@testm.skipIf(version_info > (3, 0, 0, 'final', 0), "Tests for Python 2 only")
class TestScryptForPython2(testm.TestCase):

    def setUp(self):
        self.input = "message"
        self.password = "password"
        self.unicode_text = '\xe1\x93\x84\xe1\x93\x87\xe1\x95\x97\xe1\x92\xbb\xe1\x92\xa5\xe1\x90\x85\xe1\x91\xa6'.decode('utf-8')

    def test_py2_encrypt_fails_on_unicode_input(self):
        """Test Py2 encrypt raises TypeError when Unicode input passed"""
        self.assertRaises(TypeError, lambda: scrypt.encrypt(self.unicode_text, self.password))

    def test_py2_encrypt_fails_on_unicode_password(self):
        """Test Py2 encrypt raises TypeError when Unicode password passed"""
        self.assertRaises(TypeError, lambda: scrypt.encrypt(self.input, self.unicode_text))

    def test_py2_encrypt_returns_string(self):
        """Test Py2 encrypt returns str"""
        e = scrypt.encrypt(self.input, self.password, 0.1)
        self.assertTrue(isinstance(e, str))

    def test_py2_decrypt_returns_string(self):
        """Test Py2 decrypt returns str"""
        s = scrypt.encrypt(self.input, self.password, 0.1)
        m = scrypt.decrypt(s, self.password)
        self.assertTrue(isinstance(m, str))

    def test_py2_hash_returns_string(self):
        """Test Py2 hash return str"""
        h = scrypt.hash(self.input, self.password)
        self.assertTrue(isinstance(h, str))

if __name__ == "__main__":
    testm.main()