fix bug in test_lan_learn and handle errors better in encryption plugin

This commit is contained in:
Kevin 2020-06-23 16:48:04 -05:00
parent 8d33e1a188
commit 03608960c0
2 changed files with 12 additions and 2 deletions

View File

@ -22,12 +22,17 @@
import logger, config, threading, time, datetime, sys import logger, config, threading, time, datetime, sys
import ujson as json import ujson as json
from nacl.exceptions import TypeError as NaclTypeError
from onionrutils import stringvalidators, bytesconverter from onionrutils import stringvalidators, bytesconverter
from onionrcrypto import encryption, keypair, signing, getourkeypair from onionrcrypto import encryption, keypair, signing, getourkeypair
import onionrexceptions, onionrusers import onionrexceptions, onionrusers
import locale import locale
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
import binascii
plugin_name = 'encrypt' plugin_name = 'encrypt'
class PlainEncryption: class PlainEncryption:
@ -110,7 +115,12 @@ class PlainEncryption:
return return
def on_decrypt_cmd(api, data=None): def on_decrypt_cmd(api, data=None):
PlainEncryption(api).decrypt() try:
PlainEncryption(api).decrypt()
except binascii.Error:
logger.error("Invalid ciphertext padding", terminal=True)
except NaclTypeError:
logger.error("Ciphertext too short.", terminal=True)
def on_encrypt_cmd(api, data=None): def on_encrypt_cmd(api, data=None):
PlainEncryption(api).encrypt() PlainEncryption(api).encrypt()

View File

@ -40,7 +40,7 @@ class TestLanLearn(unittest.TestCase):
sock.close() sock.close()
test_list = [test_ip] test_list = [test_ip]
Thread(target=learn_services, args=[test_list], daemon=True).start() Thread(target=learn_services, daemon=True).start()
bettersleep.better_sleep(3) bettersleep.better_sleep(3)
multicast() multicast()
self.assertIn(test_ip, test_list) self.assertIn(test_ip, test_list)