Skip to content

Commit

Permalink
test(plugin): plugins FAIL(!) on conjecutive hashes
Browse files Browse the repository at this point in the history
Currently plugins install digester-instances when initialized.
The SAME-DIGESTERSs are re-used multiple times, 
corrupting hashes for all but the 1st input!

- Installed TCs to detect this bug.
  • Loading branch information
ankostis committed Dec 16, 2016
1 parent dc202e0 commit a21bf38
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ python:
# command to install dependencies
install:
# - "pip install -r requirements.txt"
- "pip install setuptools --upgrade; python setup.py install; pip install nose"
- "pip install setuptools --upgrade; pip install -e .[sha3,pyblake2]; pip install nose"
# command to run tests
script: nosetests
61 changes: 49 additions & 12 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from omnihash.omnihash import main
import os
import re
import sys
import unittest

Expand Down Expand Up @@ -33,13 +34,13 @@ def hello(name):
def test_empty(self):
runner = CliRunner()
result = runner.invoke(main, catch_exceptions=False)
print(result.output)
#print(result.output)
self.assertEqual(result.exit_code, 0)

def test_omnihash(self):
runner = CliRunner()
result = runner.invoke(main, ['hashme'], catch_exceptions=False)
print(result.output)
#print(result.output)
self.assertEqual(result.exit_code, 0)
self.assertIn('fb78992e561929a6967d5328f49413fa99048d06', result.output)

Expand All @@ -57,7 +58,6 @@ def test_omnihashfile(self):
self.assertIn('941c986ff0f3e90543dc5e2a0687ee99b19bff67', result.output)

def test_omnihashfile_conjecutive(self):
import re
runner = CliRunner()
result = runner.invoke(main, 'LICENSE LICENSE -f sha1'.split(), catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_omnihashf(self):
SHA512: 45ca55ccaa72b98b86c697fdf73fd364d4815a586f76cd326f1785bb816ff7f1f88b46fb8448b19356ee\
788eb7d300b9392709a289428070b5810d9b5c2d440d
"""
assert result.output.endswith(out)
self.assertIn(out, result.output)

result = runner.invoke(main, 'Hi -c -f sha2 -c -f ITU'.split(), catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
Expand All @@ -104,8 +104,8 @@ def test_omnihashf(self):
SHA256: 3639efcd08abb273b1619e82e78c29a7df02c1051b1820e99fc395dcaa3326b8
CRC-8-ITU: 0xbe
"""
print(out)
assert result.output.endswith(out)
#print(out)
self.assertIn(out, result.output)

def test_omnihashs(self):
runner = CliRunner()
Expand All @@ -117,29 +117,34 @@ def test_omnihashcrc(self):
runner = CliRunner()
result = runner.invoke(main, ['hashme', 'README.md', '-sc'], catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
print(result.output)
#print(result.output)
self.assertIn('fb78992e561929a6967d5328f49413fa99048d06', result.output)
self.assertIn('5d20a7c38be78000', result.output)

def test_url(self):
runner = CliRunner()
result = runner.invoke(main, ['hashme', 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', '-c']) # noqa
result = runner.invoke(main, ['hashme',
'https://www.google.com/images/branding/googlelogo/'
'2x/googlelogo_color_272x92dp.png', '-c'],
catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
print(result.output)
#print(result.output)
self.assertIn('26f471f6ebe3b11557506f6ae96156e0a3852e5b', result.output)
self.assertIn('809089', result.output)

result = runner.invoke(main, ['hashme', 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', '-sc']) # noqa
result = runner.invoke(main, ['hashme', 'https://www.google.com/images/branding/googlelogo/'
'2x/googlelogo_color_272x92dp.png', '-sc'],
catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
print(result.output)
#print(result.output)
self.assertIn('b61bad1cb3dfad6258bef11b12361effebe597a8c80131cd2d6d07fce2206243', result.output)
self.assertIn('20d9c2bbdbaf669b', result.output)

def test_json(self):
runner = CliRunner()
result = runner.invoke(main, ["correct horse battery staple", "-j", "-m", "9cc2"], catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
print(result.output)
#print(result.output)
self.assertIn('"MD5": "9cc2ae8a1ba7a93da39b46fc1019c481"', result.output)

def test_omnihashfile_git(self):
Expand All @@ -151,5 +156,37 @@ def test_omnihashfile_git(self):
self.assertIn('25063c5229e9e558e3207413a1fa56c6262eedc2', result.output)
self.assertIn('2c97833c235648e752a00f8ef709fbe2f3523ca4', result.output)

def test_sha3_conjecutive(self):
runner = CliRunner()
result = runner.invoke(main, 'hashme hashme -f sha3_'.split(), catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
if 'SHA3_' not in result.output:
return # SHA3 not installed.

self.assertEqual(len(re.findall('d1d3e0dafeecb8536c608305715380396486d0566fdca5e104e469c6',
result.output)), 2, 'SHA3_224' + result.output)
self.assertEqual(len(re.findall('80d3abe0d26ba5f08e231bb7787b1df7c007df6d4490e52654bf8566abcea81f',
result.output)), 2, 'SHA3_256' + result.output)
self.assertEqual(len(re.findall('d1d3e0dafeecb8536c608305715380396486d0566fdca5e104e469c6',
result.output)), 2, 'SHA3_384' + result.output)
self.assertEqual(len(re.findall('80d3abe0d26ba5f08e231bb7787b1df7c007df6d4490e52654bf8566abcea81f',
result.output)), 2, 'SHA3_512' + result.output)

def test_blake2_conjecutive(self):
runner = CliRunner()
result = runner.invoke(main, 'hashme hashme -f BLAKE2'.split(), catch_exceptions=False)
self.assertEqual(result.exit_code, 0)
if 'BLAKE2' not in result.output:
return # BLAKE2 not installed.

## NOTE: PY352+ added also BLAKE2 algos,
# so check matches >= 2.
#
self.assertGreaterEqual(len(re.findall('4bb3e5bffb04cd659f791cd4d36cf3f31c0950c916402a871d47e180f47491e8',
result.output)), 2, 'BLAKE2s' + result.output)
self.assertGreaterEqual(len(re.findall('827d2797e521f0bff107cabe1babe0860e4c0ab43dd06476b970cbe2711702bc0'
'99534b8dfa13df74fab8548eedea26763d0f4c3879c4fe514acb0eda69eb68a',
result.output)), 2, 'BLAKE2b' + result.output)

if __name__ == '__main__':
unittest.main()

0 comments on commit a21bf38

Please sign in to comment.