def test_cli_sign_writes_correct_signature_to_stdout(self): keypair = lamp.generate_keys() msg = 'hey' priv_name = 'test_priv.key' sig_name = 'test_sign.txt' expected_sig = lamp.sign_message(keypair.priv, msg) lamp.export_key(keypair.priv, priv_name) with patch('sys.stdout', new=StringIO()) as fake_out: lamp.cli(['sign', '--priv', priv_name, '--msg', msg]) self.assertEqual(lamp.str_to_sig(fake_out.getvalue()), expected_sig)
def test_cli_verify_signature_with_inline_msg(self): keypair = lamp.generate_keys() msg = 'hey' pub_name = 'test_pub.key' sig_name = 'test_sign.txt' sig = lamp.sign_message(keypair.priv, msg) lamp.export_key(keypair.pub, pub_name) with open(sig_name, 'w') as f: f.write(''.join(sig).strip()) with patch('sys.stdout', new=StringIO()) as fake_out: lamp.cli( ['verify', '--pub', pub_name, '--msg', msg, '--sig', sig_name]) self.assertEqual(fake_out.getvalue().strip(), 'valid')
def test_export_priv_key_creates_file(self): filename = 'test_priv.key' lamp.export_key(key=self.pub, filename=filename) self.assertTrue(os.path.exists(filename))
def test_parse_key_parts_are_same_length(self): filename = 'test_priv.key' lamp.export_key(self.priv, filename) key = lamp.parse_key(filename) self.assertEqual(len(key[0]), len(key[0]))
def test_parse_key_zeropart_is_correct_length(self): filename = 'test_priv.key' lamp.export_key(self.priv, filename) key = lamp.parse_key(filename) self.assertEqual(len(key[0]), 256)