From 0a90965efcb018f00eabe9040cb994032ef0fd5c Mon Sep 17 00:00:00 2001 From: Michal Konečný Date: Jun 09 2023 11:43:41 +0000 Subject: [PATCH 1/2] Fix linting issues This fixes all the issues that were found by `make lint` and `make flake8` tests. The make was run inside vagrant dev environment. Introduces new dependency `filetype`, because `imghdr` module is deprecated in python >= 3. Signed-off-by: Michal Konečný --- diff --git a/contrib/fedora/ipsilon.spec b/contrib/fedora/ipsilon.spec index bd79223..52e51ea 100644 --- a/contrib/fedora/ipsilon.spec +++ b/contrib/fedora/ipsilon.spec @@ -20,6 +20,7 @@ BuildRequires: make Requires: python3-setuptools Requires: python3-requests +Requires: python3-filetype Requires: %{name}-base = %{version}-%{release} %description diff --git a/devel/ansible/roles/dev/tasks/main.yml b/devel/ansible/roles/dev/tasks/main.yml index 9dd278f..636347b 100644 --- a/devel/ansible/roles/dev/tasks/main.yml +++ b/devel/ansible/roles/dev/tasks/main.yml @@ -29,9 +29,11 @@ - python3-dbus - python3-ipalib - python3-psycopg2 + - python3-filetype - bandit - python3-pylint - python3-flake8 + - python3-psycopg2 - make - httpd - mod_auth_mellon diff --git a/ipsilon/helpers/ipa.py b/ipsilon/helpers/ipa.py index 7f14b1d..19b2aea 100644 --- a/ipsilon/helpers/ipa.py +++ b/ipsilon/helpers/ipa.py @@ -47,7 +47,7 @@ class Installer(EnvHelpersInstaller): if not os.path.exists(IPA_CONFIG_FILE): logger.info('No IPA configuration file. Skipping ipa helper...') if opts['ipa'] == 'yes': - raise Exception('No IPA installation found!') + raise RuntimeError('No IPA installation found!') return def _check_output(self, args, **kwargs): @@ -65,7 +65,7 @@ class Installer(EnvHelpersInstaller): if not os.path.exists(IPA_GETKEYTAB): logger.info('ipa-getkeytab missing. Will skip keytab creation.') if opts['ipa'] == 'yes': - raise Exception('No IPA tools found!') + raise RuntimeError('No IPA tools found!') # Check if we already have a keytab for HTTP if 'gssapi_httpd_keytab' in opts: @@ -93,7 +93,7 @@ class Installer(EnvHelpersInstaller): self._check_output([IPA_COMMAND, 'ping']) except subprocess.CalledProcessError as e: logger.error('Cannot connect to server: %s', e) - raise Exception('Unable to connect to IPA server: %s' % e) + raise RuntimeError('Unable to connect to IPA server: %s' % e) else: logger.debug("... Succeeded!") @@ -108,7 +108,7 @@ class Installer(EnvHelpersInstaller): logger.debug('Principal %s already exists', princ) else: logger.error('%s', e) - raise Exception(e.output) + raise RuntimeError(e.output) msg = "Trying to fetch keytab[%s] for %s" % ( opts['gssapi_httpd_keytab'], princ) @@ -123,7 +123,7 @@ class Installer(EnvHelpersInstaller): logger.error(FAILED_TO_GET_KEYTAB) logger.info('Error trying to get HTTP keytab:') logger.info('Cmd> %s\n%s', gktcmd, e.output) - raise Exception( + raise RuntimeError( 'Missing keytab: [Command \'%s\' returned non-zero' ' exit status %d]' % (gktcmd, e.returncode) ) diff --git a/ipsilon/info/infoldap.py b/ipsilon/info/infoldap.py index 203eaf6..3ba9af1 100644 --- a/ipsilon/info/infoldap.py +++ b/ipsilon/info/infoldap.py @@ -117,9 +117,9 @@ Info plugin that uses LDAP to retrieve user data. """ def _get_user_data(self, conn, dn): result = conn.search_s(dn, ldap.SCOPE_BASE) if result is None or result == []: - raise Exception('User object could not be found!') + raise RuntimeError('User object could not be found!') elif len(result) > 1: - raise Exception('No unique user object could be found!') + raise RuntimeError('No unique user object could be found!') data = dict() for name, value in six.iteritems(result[0][1]): if isinstance(value, list) and len(value) == 1: diff --git a/ipsilon/info/infosssd.py b/ipsilon/info/infosssd.py index 8ce779b..733d27c 100644 --- a/ipsilon/info/infosssd.py +++ b/ipsilon/info/infosssd.py @@ -108,7 +108,9 @@ Info plugin that uses DBus to retrieve user data from SSSd.""" for attr_name in user_attrs: attr_name = self._unwrap_dbus_str(attr_name) if len(user_attrs[attr_name]) == 1: - reply[attr_name] = self._unwrap_dbus_str(user_attrs[attr_name][0]) + reply[attr_name] = self._unwrap_dbus_str( + user_attrs[attr_name][0] + ) else: reply[attr_name] = [] for attr_val in user_attrs[attr_name]: @@ -139,7 +141,7 @@ Info plugin that uses DBus to retrieve user data from SSSd.""" def enable(self): self.refresh_plugin_config() if not self.get_config_value('preconfigured'): - raise Exception("SSSD Can be enabled only if pre-configured") + raise RuntimeError("SSSD Can be enabled only if pre-configured") self.bus = dbus.SystemBus() super(InfoProvider, self).enable() diff --git a/ipsilon/login/authform.py b/ipsilon/login/authform.py index 7ae9a7b..cf79ff3 100644 --- a/ipsilon/login/authform.py +++ b/ipsilon/login/authform.py @@ -118,7 +118,7 @@ class Installer(LoginManagerInstaller): tmpl = Template(CONF_TEMPLATE) hunk = tmpl.substitute(**confopts) - with open(opts['httpd_conf'], 'a') as httpd_conf: + with open(opts['httpd_conf'], 'a', encoding='utf-8') as httpd_conf: httpd_conf.write(hunk) # Add configuration data to database diff --git a/ipsilon/login/authgssapi.py b/ipsilon/login/authgssapi.py index 3eebb7f..a1d4828 100644 --- a/ipsilon/login/authgssapi.py +++ b/ipsilon/login/authgssapi.py @@ -131,7 +131,7 @@ class Installer(LoginManagerInstaller): if os.path.exists(opts['gssapi_httpd_keytab']): confopts['keytab'] = opts['gssapi_httpd_keytab'] else: - raise Exception('Keytab not found') + raise RuntimeError('Keytab not found') if opts['secure'] == 'no': confopts['gssapisslonly'] = 'Off' @@ -140,7 +140,7 @@ class Installer(LoginManagerInstaller): tmpl = Template(CONF_TEMPLATE) hunk = tmpl.substitute(**confopts) - with open(opts['httpd_conf'], 'a') as httpd_conf: + with open(opts['httpd_conf'], 'a', encoding='utf-8') as httpd_conf: httpd_conf.write(hunk) # Add configuration data to database diff --git a/ipsilon/login/authldap.py b/ipsilon/login/authldap.py index 8ca918d..9ad1e0b 100644 --- a/ipsilon/login/authldap.py +++ b/ipsilon/login/authldap.py @@ -74,7 +74,7 @@ class LDAP(LoginFormBase, Log): try: userattrs = self._authenticate(username, password) authok = True - except ldap.INVALID_CREDENTIALS as e: + except ldap.INVALID_CREDENTIALS: errmsg = "Authentication failed" self.error(errmsg) except ldap.LDAPError as e: diff --git a/ipsilon/providers/openid/auth.py b/ipsilon/providers/openid/auth.py index 1a1ef20..24e80e1 100644 --- a/ipsilon/providers/openid/auth.py +++ b/ipsilon/providers/openid/auth.py @@ -44,7 +44,10 @@ class AuthenticateRequest(ProviderPageBase): form = None if args is not None: first = args[0] if len(args) > 0 else None - second = first[0] if len(first) > 0 else None + if isinstance(first, tuple) and len(first) > 0: + second = first[0] # pylint: disable=unsubscriptable-object + else: + second = None if isinstance(second, dict): form = second.get('form', None) return form diff --git a/ipsilon/providers/openid/store.py b/ipsilon/providers/openid/store.py index 3b36e25..dde5084 100644 --- a/ipsilon/providers/openid/store.py +++ b/ipsilon/providers/openid/store.py @@ -18,7 +18,9 @@ class OpenIDStore(Store, OpenIDStoreInterface): def storeAssociation(self, server_url, association): iden = '%s-%s' % (server_url, association.handle) - datum = {'secret': oidutil.toBase64(association.secret).decode('utf-8'), + datum = {'secret': oidutil.toBase64( + association.secret + ).decode('utf-8'), 'issued': str(association.issued), 'lifetime': str(association.lifetime), 'assoc_type': association.assoc_type} diff --git a/ipsilon/providers/openidc/admin.py b/ipsilon/providers/openidc/admin.py index 201a11e..4bda292 100644 --- a/ipsilon/providers/openidc/admin.py +++ b/ipsilon/providers/openidc/admin.py @@ -177,7 +177,7 @@ class ClientAdminPage(AdminPage): raise cherrypy.HTTPError(403) if not self.parent.cfg.datastore.deleteClient(self.client.client_id): - raise Exception('Deleting the client did not work') + raise RuntimeError('Deleting the client did not work') raise cherrypy.HTTPRedirect(self.parent.url) delete.public_function = True diff --git a/ipsilon/providers/openidc/auth.py b/ipsilon/providers/openidc/auth.py index 98c4539..9c69be8 100644 --- a/ipsilon/providers/openidc/auth.py +++ b/ipsilon/providers/openidc/auth.py @@ -228,7 +228,9 @@ class Authorization(AuthenticateRequest): try: # FIXME: MAY cache this at client registration time and # cache permanently until client registration is changed. - jwt_object = requests.get(arguments['request_uri']).text + jwt_object = requests.get( + arguments['request_uri'], timeout=30 + ).text except Exception as ex: # pylint: disable=broad-except self.debug('Unable to get request: %s' % ex) return self._respond_error(request_data, @@ -242,9 +244,9 @@ class Authorization(AuthenticateRequest): if client['request_object_signing_alg'] != 'none': # Client told us we need to check signature if decoded.token.jose_header['alg'] != \ - client['request_object_signing_alg']: - raise Exception('Invalid algorithm used: %s' - % decoded.token.jose_header['alg']) + client['request_object_signing_alg']: + raise RuntimeError('Invalid algorithm used: %s' + % decoded.token.jose_header['alg']) if client['request_object_signing_alg'] == 'none': jwt_request = json.loads( @@ -254,7 +256,9 @@ class Authorization(AuthenticateRequest): if client['jwks']: keys = json.loads(client['jkws']) else: - keys = requests.get(client['jwks_uri']).json() + keys = requests.get( + client['jwks_uri'], timeout=30 + ).json() keyset = JWKSet() for key in keys['keys']: keyset.add(JWK(**key)) @@ -579,7 +583,7 @@ class Continue(AuthenticateRequest): # Since we have openidc_stage continue or consent, request is sane try: request_data = json.loads(request_data) - except: + except Exception: raise InvalidRequest('Unable to re-parse stored request') client = self.cfg.datastore.getClient(request_data['client_id']) diff --git a/ipsilon/providers/openidc/provider.py b/ipsilon/providers/openidc/provider.py index a8a0ba2..ff7ce6b 100644 --- a/ipsilon/providers/openidc/provider.py +++ b/ipsilon/providers/openidc/provider.py @@ -22,7 +22,7 @@ def get_url_hostpart(url): try: o = urlparse(url) return o.hostname - except: # pylint: disable=bare-except + except ValueError: return url @@ -35,7 +35,7 @@ class Registration(APIRequest): try: client_metadata = json.loads(cherrypy.request.rfile.read()) - except: + except Exception: raise APIError(400, 'invalid_client_metadata', 'unable to parse metadata') self.debug('Received client registration request: %s' @@ -177,7 +177,7 @@ class Client(pconfig.ConfigHelper): raise InvalidMetadata('Sector identifier URI must be https') try: - resp = requests.get(si_uri) + resp = requests.get(si_uri, timeout=30) resp = resp.json() for redirect_uri in conf['Redirect URIs'].get_value(): if redirect_uri not in resp: diff --git a/ipsilon/providers/openidcp.py b/ipsilon/providers/openidcp.py index fc85d9e..529ca59 100644 --- a/ipsilon/providers/openidcp.py +++ b/ipsilon/providers/openidcp.py @@ -178,7 +178,7 @@ Provides OpenID Connect authentication infrastructure. """ def init_idp(self): self.keyset = JWKSet() - with open(self.idp_key_file, 'r') as keyfile: + with open(self.idp_key_file, 'r', encoding='utf-8') as keyfile: loaded_keys = json.loads(keyfile.read()) for key in loaded_keys['keys']: self.keyset.add(JWK(**key)) @@ -288,7 +288,7 @@ class Installer(ProviderInstaller): kid='%s-enc' % keyid) keyset.add(rsasig) - with open(keyfile, 'w') as m: + with open(keyfile, 'w', encoding='utf-8') as m: m.write(keyset.export()) proto = 'https' diff --git a/ipsilon/providers/saml2/admin.py b/ipsilon/providers/saml2/admin.py index bb1ea20..1a83557 100644 --- a/ipsilon/providers/saml2/admin.py +++ b/ipsilon/providers/saml2/admin.py @@ -99,7 +99,7 @@ class NewSPAdminPage(AdminPage): elif key == 'metaurl': if len(value) > 0: try: - r = requests.get(value) + r = requests.get(value, timeout=30) r.raise_for_status() meta = r.content except Exception as e: # pylint: disable=broad-except diff --git a/ipsilon/providers/saml2/logout.py b/ipsilon/providers/saml2/logout.py index 74ce37f..c42610b 100644 --- a/ipsilon/providers/saml2/logout.py +++ b/ipsilon/providers/saml2/logout.py @@ -42,7 +42,7 @@ class LogoutRequest(ProviderPageBase): e, message) self.error(msg) raise UnknownProvider(msg) - except lasso.DsInvalidSigalgError as e: + except lasso.DsInvalidSigalgError: msg = 'Invalid SAML Request: missing or invalid signature ' \ 'algorithm' self.error(msg) @@ -53,7 +53,7 @@ class LogoutRequest(ProviderPageBase): e, message) self.error(msg) raise InvalidRequest(msg) - except lasso.Error as e: + except lasso.Error: self.error('SLO unknown error: %s' % message) raise cherrypy.HTTPError(400, 'Invalid logout request') @@ -79,7 +79,7 @@ class LogoutRequest(ProviderPageBase): try: logout.validateRequest() - except lasso.ProfileSessionNotFoundError as e: + except lasso.ProfileSessionNotFoundError: self.error('Logout failed. No sessions for %s' % logout.remoteProviderId) return self._not_logged_in(logout, message) @@ -189,7 +189,7 @@ class LogoutRequest(ProviderPageBase): e, message) self.error(msg) raise InvalidRequest(msg) - except lasso.Error as e: + except lasso.Error: self.error('SLO unknown error: %s' % message) raise cherrypy.HTTPError(400, 'Invalid logout request') @@ -205,7 +205,7 @@ class LogoutRequest(ProviderPageBase): headers = {'Content-Type': SOAP_MEDIA_TYPE} try: response = requests.post(logout.msgUrl, data=logout.msgBody, - headers=headers) + headers=headers, timeout=30) except Exception as e: # pylint: disable=broad-except self.error('SOAP HTTP request failed: (%s) (on %s)' % (e, logout.msgUrl)) diff --git a/ipsilon/providers/saml2/sessions.py b/ipsilon/providers/saml2/sessions.py index fc3c68c..cffc6c9 100644 --- a/ipsilon/providers/saml2/sessions.py +++ b/ipsilon/providers/saml2/sessions.py @@ -308,41 +308,41 @@ if __name__ == '__main__': # Test finding sessions by provider ids = factory.get_session_id_by_provider_id(provider2, user='admin') - assert(len(ids) == 1) + assert len(ids) == 1 sess3 = factory.add_session('_345678', provider2, "testuser", "", '_3456', [SAML2_METADATA_BINDING_REDIRECT]) ids = factory.get_session_id_by_provider_id(provider2, user='testuser') - assert(len(ids) == 2) + assert len(ids) == 2 # Test finding sessions by session ID test1 = factory.get_session_by_id('_123456') - assert(test1.user == 'admin') - assert(test1.provider_id == provider1) + assert test1.user == 'admin' + assert test1.provider_id == provider1 # Log out and remove the first session test1.set_logoutstate('http://www.example.com/idp') factory.start_logout(test1, initial=True) test1 = factory.get_session_by_id('_123456') - assert(test1.relaystate == 'http://www.example.com/idp') + assert test1.relaystate == 'http://www.example.com/idp' factory.remove_session_by_session_id('_123456') # Make sure it is gone from the db test1 = factory.get_session_by_id('_123456') - assert(test1 is None) + assert test1 is None test2 = factory.get_session_by_id('_789012') factory.start_logout(test2, initial=True) (lmech, test3) = factory.get_next_logout(user='admin') - assert(test3.session_id == '_345678') + assert test3.session_id == '_345678' test4 = factory.get_initial_logout(user='admin') - assert(test4.session_id == '_789012') + assert test4.session_id == '_789012' # Even though we've started logout, make sure we can still find # all sessions for a provider. ids = factory.get_session_id_by_provider_id(provider2, user='admin') - assert(len(ids) == 2) + assert len(ids) == 2 diff --git a/ipsilon/providers/saml2idp.py b/ipsilon/providers/saml2idp.py index fcd0996..b327138 100644 --- a/ipsilon/providers/saml2idp.py +++ b/ipsilon/providers/saml2idp.py @@ -188,7 +188,7 @@ class Metadata(ProviderPageBase): if os.path.isfile(self.cfg.idp_metadata_file): s = os.stat(self.cfg.idp_metadata_file) if s.st_mtime > time.time() - METADATA_RENEW_INTERVAL: - with open(self.cfg.idp_metadata_file) as m: + with open(self.cfg.idp_metadata_file, encoding='utf-8') as m: return m.read() # Otherwise generate and save @@ -200,7 +200,7 @@ class Metadata(ProviderPageBase): meta = IdpMetadataGenerator(self.instance_base_url(), idp_cert, timedelta(validity)) body = meta.output() - with open(self.cfg.idp_metadata_file, 'w+') as m: + with open(self.cfg.idp_metadata_file, 'w+', encoding='utf-8') as m: m.write(body) return body diff --git a/ipsilon/tools/certs.py b/ipsilon/tools/certs.py index 39cdeab..175052a 100644 --- a/ipsilon/tools/certs.py +++ b/ipsilon/tools/certs.py @@ -33,7 +33,7 @@ class Certificate(object): def get_cert(self): if not self.cert: raise ValueError('Certificate unavailable') - with open(self.cert, 'r') as f: + with open(self.cert, 'r', encoding='utf-8') as f: cert = f.readlines() # Find the beginning of the certificate diff --git a/ipsilon/tools/dbupgrade.py b/ipsilon/tools/dbupgrade.py index 423c473..acbcb41 100644 --- a/ipsilon/tools/dbupgrade.py +++ b/ipsilon/tools/dbupgrade.py @@ -57,7 +57,7 @@ def _upgrade_database(datastore): def upgrade_failed(): logger.error('Upgrade failed. Please fix errors above and retry') - raise Exception('Upgrading failed') + raise RuntimeError('Upgrading failed') def execute_upgrade(cfgfile): @@ -118,7 +118,7 @@ def execute_upgrade(cfgfile): 'authz_config']: for plugin in root._site[facility].enabled: logger.info('Handling plugin %s', plugin) - if not plugin in root._site[facility].available: + if plugin not in root._site[facility].available: logger.error('Plugin was unavailable') continue plugin = root._site[facility].available[plugin] diff --git a/ipsilon/tools/files.py b/ipsilon/tools/files.py index 154b496..728a286 100644 --- a/ipsilon/tools/files.py +++ b/ipsilon/tools/files.py @@ -22,8 +22,8 @@ def fix_user_dirs(path, user=None, mode=0o700): def write_from_template(destfile, template, opts): - with open(template) as f: + with open(template, encoding='utf-8') as f: t = Template(f.read()) text = t.substitute(**opts) - with open(destfile, 'w+') as f: + with open(destfile, 'w+', encoding='utf-8') as f: f.write(text) diff --git a/ipsilon/tools/saml2metadata.py b/ipsilon/tools/saml2metadata.py index 3b792b6..e7bfb42 100755 --- a/ipsilon/tools/saml2metadata.py +++ b/ipsilon/tools/saml2metadata.py @@ -168,7 +168,7 @@ if __name__ == '__main__': idp.add_allowed_name_format(SAML2_NAMEID_MAP[k]) md_file = os.path.join(tmpdir, 'metadata.xml') idp.output(md_file) - with open(md_file) as fd: + with open(md_file, encoding='utf-8') as fd: text = fd.read() print('==================== IDP ====================') print(text) @@ -187,7 +187,7 @@ if __name__ == '__main__': 'https://ipsilon.example.com/samlsp/postResponse') md_file = os.path.join(tmpdir, 'metadata.xml') sp.output(md_file) - with open(md_file) as fd: + with open(md_file, encoding='utf-8') as fd: text = fd.read() print('===================== SP ====================') print(text) diff --git a/ipsilon/user/common.py b/ipsilon/user/common.py index 2d89028..d19504e 100644 --- a/ipsilon/user/common.py +++ b/ipsilon/user/common.py @@ -28,7 +28,7 @@ class UserPortalConsent(UserPortalPage): None) if provmod is not None: if not provmod.revoke_consent(user.name, clientid): - raise Exception('Provider refused to revoke') + raise RuntimeError('Provider refused to revoke') user.revoke_consent(provider, clientid) raise cherrypy.HTTPRedirect(self._master.url) revoke.public_function = True diff --git a/ipsilon/util/config.py b/ipsilon/util/config.py index 1707daf..de080b2 100644 --- a/ipsilon/util/config.py +++ b/ipsilon/util/config.py @@ -4,17 +4,19 @@ from ipsilon.util.log import Log import os import json import base64 -import imghdr import hashlib import cherrypy import six +import filetype + def name_from_image(image): if image is None: return None - fext = imghdr.what(None, base64.b64decode(image)) + _type = filetype.image_match(image) + fext = _type.mime.split("/")[1] if _type else None m = hashlib.sha1() # nosec: This file is admin-provided m.update(base64.b64decode(image)) @@ -488,7 +490,7 @@ class Condition(Pick): readonly=False): # We're not too picky about what data we get, but we make sure it's a # boolean by the time we're done with it - if default_value in [u'1', 'True', True]: + if default_value in ['1', 'True', True]: default_value = True else: default_value = False diff --git a/ipsilon/util/cookies.py b/ipsilon/util/cookies.py index f9b0889..fb1bde0 100644 --- a/ipsilon/util/cookies.py +++ b/ipsilon/util/cookies.py @@ -40,7 +40,7 @@ class SecureCookie(Log): def _store(self): if self.value is None: raise ValueError('Cookie has no value') - if self.maxage is None and self.expires is not 0: + if self.maxage is None and self.expires != 0: # 5 minutes should be enough ... self.maxage = 300 cherrypy.response.cookie[self.name] = str(self.value) diff --git a/ipsilon/util/data.py b/ipsilon/util/data.py index 64cd218..1e8c855 100644 --- a/ipsilon/util/data.py +++ b/ipsilon/util/data.py @@ -526,7 +526,7 @@ class EtcdQuery(BaseQuery): levels_unused = len(self._primary_key) - pkeys_used if levels_unused != 0 and update: - raise Exception('Fully qualified object required for updates') + raise RuntimeError('Fully qualified object required for updates') return path, levels_unused @@ -883,11 +883,11 @@ class Store(Log): self.debug('Upgrading from schema version %i' % old_schema_version) new_version = self._upgrade_schema(old_schema_version) if not new_version: - error = ('Schema upgrade error: %s did not provide a ' + + error = ('Schema upgrade error: %s did not provide a ' 'new schema version number!' % self.__class__.__name__) self.error(error) - raise Exception(error) + raise RuntimeError(error) self._store_new_schema_version(new_version) # Check if we are now up-to-date self.upgrade_database() diff --git a/ipsilon/util/plugin.py b/ipsilon/util/plugin.py index 8d4b8db..dfbf03e 100644 --- a/ipsilon/util/plugin.py +++ b/ipsilon/util/plugin.py @@ -81,8 +81,8 @@ class PluginLoader(Log): @property def _data(self): if not self.uses_store: - raise Exception('Tried to get plugin data while ' + - 'uses_store=False (%s)' % self.facility) + raise RuntimeError('Tried to get plugin data while ' + + 'uses_store=False (%s)' % self.facility) if not self.__data: self.__data = AdminStore() return self.__data From f38c15d388bb0e15556c3b9a9b8268da1b0dd34d Mon Sep 17 00:00:00 2001 From: Michal Konečný Date: Jun 09 2023 11:43:46 +0000 Subject: [PATCH 2/2] Fix unittests One of the tests suites didn't run because of the missing etcd library in vagrant. The tests were run using `make tests` in vagrant F38 machine. Signed-off-by: Michal Konečný --- diff --git a/devel/ansible/roles/dev/tasks/main.yml b/devel/ansible/roles/dev/tasks/main.yml index 636347b..e1d2db1 100644 --- a/devel/ansible/roles/dev/tasks/main.yml +++ b/devel/ansible/roles/dev/tasks/main.yml @@ -3,6 +3,7 @@ dnf: state: present name: + - etcd - git - vim - python3-pip diff --git a/ipsilon/util/config.py b/ipsilon/util/config.py index de080b2..2c2d6f3 100644 --- a/ipsilon/util/config.py +++ b/ipsilon/util/config.py @@ -15,7 +15,7 @@ def name_from_image(image): if image is None: return None - _type = filetype.image_match(image) + _type = filetype.image_match(base64.b64decode(image)) fext = _type.mime.split("/")[1] if _type else None m = hashlib.sha1() # nosec: This file is admin-provided m.update(base64.b64decode(image))