2014-07-25 21:08:46 +00:00
|
|
|
# coding: utf-8
|
|
|
|
|
2014-11-20 02:42:45 +00:00
|
|
|
# Import salt testing libs
|
|
|
|
from salttesting.case import ModuleCase
|
|
|
|
|
|
|
|
# Import Salt libs
|
|
|
|
import salt.loader
|
2014-07-25 21:08:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HashutilTestCase(ModuleCase):
|
|
|
|
the_string = 'get salted'
|
|
|
|
the_string_base64 = 'Z2V0IHNhbHRlZA==\n'
|
|
|
|
the_string_md5 = '2aacf29e92feaf528fb738bcf9d647ac'
|
|
|
|
the_string_sha256 = 'd49859ccbc854fa68d800b5734efc70d72383e6479d545468bc300263164ff33'
|
|
|
|
the_string_sha512 = 'a8c174a7941c64a068e686812a2fafd7624c840fde800f5965fbeca675f2f6e37061ffe41e17728c919bdea290eab7a21e13c04ae71661955a87f2e0e04bb045'
|
|
|
|
the_string_hmac = 'NS2BvKxFRk+rndAlFbCYIFNVkPtI/3KiIYQw4okNKU8='
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.hashutil = salt.loader.raw_mod(self.minion_opts, 'hashutil', None)
|
|
|
|
|
|
|
|
def test_base64_encodestring(self):
|
|
|
|
ret = self.hashutil['hashutil.base64_encodestring'](self.the_string)
|
|
|
|
self.assertEqual(ret, self.the_string_base64)
|
|
|
|
|
|
|
|
def test_base64_decodestring(self):
|
|
|
|
ret = self.hashutil['hashutil.base64_decodestring'](self.the_string_base64)
|
|
|
|
self.assertEqual(ret, self.the_string)
|
|
|
|
|
|
|
|
def test_md5_digest(self):
|
|
|
|
ret = self.hashutil['hashutil.md5_digest'](self.the_string)
|
|
|
|
self.assertEqual(ret, self.the_string_md5)
|
|
|
|
|
|
|
|
def test_sha256_digest(self):
|
|
|
|
ret = self.hashutil['hashutil.sha256_digest'](self.the_string)
|
|
|
|
self.assertEqual(ret, self.the_string_sha256)
|
|
|
|
|
|
|
|
def test_sha512_digest(self):
|
|
|
|
ret = self.hashutil['hashutil.sha512_digest'](self.the_string)
|
|
|
|
self.assertEqual(ret, self.the_string_sha512)
|
|
|
|
|
|
|
|
def test_hmac_signature(self):
|
|
|
|
ret = self.hashutil['hashutil.hmac_signature'](
|
|
|
|
self.the_string,
|
|
|
|
'shared secret',
|
|
|
|
self.the_string_hmac)
|
|
|
|
self.assertTrue(ret)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(HashutilTestCase,
|
|
|
|
needs_daemon=False)
|