From: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> Date: Sat, 20 Nov 2021 08:34:14 +0000 (+0100) Subject: Avoid assert statement outside of tests X-Git-Tag: v9.00~62^2~4 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1c26f10ebd7d80bb0fcc46d7f6bc4798f1f563de;p=users%2Fdwmw2%2Fopenconnect.git Avoid assert statement outside of tests This fixes DeepSource alerts: Assert statement used outside of tests Usage of assert statement in application logic is discouraged. assert is removed with compiling to optimized byte code. Consider raising an exception instead. Ideally, assert statement should be used only in tests. Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> --- diff --git a/trojans/tncc-emulate.py b/trojans/tncc-emulate.py index dd443e0d..88a8d6cd 100755 --- a/trojans/tncc-emulate.py +++ b/trojans/tncc-emulate.py @@ -570,16 +570,17 @@ class tncc: for cert in self.avail_certs: fail = False for dn_name, dn_vals in req_dns.items(): - for name, val in dn_vals.items(): - try: - if dn_name == 'IssuerDN': - assert val in cert.issuer[name] - else: - logging.warning('Unknown DN type %s', str(dn_name)) - raise Exception() - except Exception: - fail = True - break + if dn_name == 'IssuerDN': + for name, val in dn_vals.items(): + if ( + name not in cert.issuer + or val not in cert.issuer[name] + ): + fail = True + break + else: + logging.warning('Unknown DN type %s', str(dn_name)) + fail = True if fail: break if not fail: @@ -678,10 +679,11 @@ if __name__ == "__main__": for iface in netifaces.interfaces(): try: mac = netifaces.ifaddresses(iface)[netifaces.AF_LINK][0]['addr'] - assert mac != '00:00:00:00:00:00' - mac_addrs.append(mac) - except Exception: + except (IndexError, KeyError): pass + else: + if mac != '00:00:00:00:00:00': + mac_addrs.append(mac) hostname = os.environ.get('TNCC_HOSTNAME', socket.gethostname())