#276 Some automated code style fixes related to py3
Merged 4 years ago by puiterwijk. Opened 4 years ago by puiterwijk.
puiterwijk/ipsilon py3  into  master

file modified
+3 -3
@@ -179,7 +179,7 @@ 

                          if cur_enabled[i] != new_order[i]:

                              changed[cur_enabled[i]] = 'reordered'

  

-                 except ValueError, e:

+                 except ValueError as e:

                      message = str(e)

                      message_type = ADMIN_STATUS_ERROR

  
@@ -260,7 +260,7 @@ 

          msg = None

          try:

              obj = self._get_plugin_obj(plugin)

-         except AdminError, e:

+         except AdminError as e:

              return self.root_with_msg(str(e), ADMIN_STATUS_WARN)

          if not obj.is_enabled:

              try:
@@ -278,7 +278,7 @@ 

          msg = None

          try:

              obj = self._get_plugin_obj(plugin)

-         except AdminError, e:

+         except AdminError as e:

              return self.root_with_msg(str(e), ADMIN_STATUS_WARN)

          if obj.is_enabled:

              try:

file modified
+1 -1
@@ -62,7 +62,7 @@ 

              self.domain = ipaconfig.config.get_domain()

              self.server = ipaconfig.config.get_server()

  

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              logger.info('IPA tools installation found: [%s]', e)

              if opts['ipa'] == 'yes':

                  raise Exception('No IPA installation found!')

file modified
+1 -1
@@ -149,7 +149,7 @@ 

              reply = userattrs

              reply['_groups'] = groups

              reply['_extras'] = {'ldap': extras}

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              self.error('Error fetching/mapping LDAP user data: %s' % e)

  

          return reply

@@ -67,7 +67,7 @@ 

              r = requests.get(args['saml_idp_metadata'])

              r.raise_for_status()

              idpmeta = r.content

-     except Exception, e:  # pylint: disable=broad-except

+     except Exception as e:  # pylint: disable=broad-except

          logger.error("Failed to retrieve IDP Metadata file!\n" +

                       "Error: [%s]" % repr(e))

          raise
@@ -270,13 +270,13 @@ 

      if os.path.exists(path):

          try:

              shutil.rmtree(path)

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              log_exception(e)

  

      if os.path.exists(CONFFILE % 'saml'):

          try:

              os.remove(CONFFILE % 'saml')

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              log_exception(e)

  

  
@@ -383,7 +383,7 @@ 

          r = requests.get(discovery_url, **requests_args)

          r.raise_for_status()

          discovered_info = r.json()

-     except Exception, e:  # pylint: disable=broad-except

+     except Exception as e:  # pylint: disable=broad-except

          logger.error("Failed to retrieve IdP configuration!\n" +

                       "Error: [%s]" % repr(e))

          raise
@@ -417,7 +417,7 @@ 

                            json=client_info, **requests_args)

          r.raise_for_status()

          registration_response = r.json()

-     except Exception, e:  # pylint: disable=broad-except

+     except Exception as e:  # pylint: disable=broad-except

          logger.error("Failed to register with the IdP!\n" +

                       "Error: [%s]" % repr(e))

          raise
@@ -589,7 +589,7 @@ 

                  saml2()

              elif service_type == 'openidc':

                  openidc()

-     except Exception, e:  # pylint: disable=broad-except

+     except Exception as e:  # pylint: disable=broad-except

          log_exception(e)

          if 'uninstall' in args and args['uninstall'] is True:

              logging.info('Uninstallation aborted.')

@@ -58,7 +58,7 @@ 

      config = {}

  

      for section in default_sections:

-         print 'Handling section %s' % section

+         print('Handling section %s' % section)

          config[section] = adminstore.load_options(section)

          plugins = config[section].get('global',

                                        {}).get('enabled',
@@ -91,8 +91,8 @@ 

      args = parser.parse_args()

  

      if os.path.exists(args.output) and not args.force:

-         print 'Output file %s already exists. Please delete it or use --force' \

-               % args.output

+         print('Output file %s already exists. Please delete it or use --force' \

+               % args.output)

          sys.exit(1)

  

      config = get_config(args.cfgfile)
@@ -100,4 +100,4 @@ 

      with open(args.output, 'w') as output:

          config_to_file(config, output)

  

-     print 'Configuration file %s written' % args.output

+     print('Configuration file %s written' % args.output)

@@ -60,7 +60,7 @@ 

      logger = logging.getLogger()

      try:

          lh = logging.FileHandler(LOGFILE)

-     except IOError, e:

+     except IOError as e:

          sys.exit('Unable to open %s (%s)' % (LOGFILE, str(e)))

      formatter = logging.Formatter('[%(asctime)s] %(message)s')

      lh.setFormatter(formatter)
@@ -524,7 +524,7 @@ 

              uninstall(fplugins, opts)

          else:

              install(fplugins, opts)

-     except Exception, e:  # pylint: disable=broad-except

+     except Exception as e:  # pylint: disable=broad-except

          logger.info(str(e))         # emit message to console

          logger.debug(e, exc_info=1) # add backtrace information to logfile

  

file modified
+2 -2
@@ -26,10 +26,10 @@ 

              data = None

              try:

                  _, data = self.lm.fpc.login(username, password)

-             except AuthError, e:

+             except AuthError as e:

                  cherrypy.log.error("Authentication error [%s]" % str(e),

                                     severity=logging.ERROR)

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  cherrypy.log.error("Unknown Error [%s]" % str(e),

                                     severity=logging.ERROR)

  

@@ -30,7 +30,7 @@ 

                      self.trans.cookie.value != self.trans.provider):

                  self.debug('Invalid transaction, %s != %s' % (

                             self.trans.cookie.value, self.trans.provider))

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              self.debug('Transaction initialization failed: %s' % repr(e))

              raise cherrypy.HTTPError(400, 'Invalid transaction id')

  
@@ -55,9 +55,9 @@ 

          try:

              request = self._parse_request(**kwargs)

              return self._openid_checks(request, form, **kwargs)

-         except InvalidRequest, e:

+         except InvalidRequest as e:

              raise cherrypy.HTTPError(e.code, e.message)

-         except UnauthorizedRequest, e:

+         except UnauthorizedRequest as e:

              if request is None:

                  raise cherrypy.HTTPError(e.code, e.message)

              return self._respond(request.answer(False))
@@ -79,7 +79,7 @@ 

          request = None

          try:

              request = self.cfg.server.decodeRequest(kwargs)

-         except ProtocolError, openid_error:

+         except ProtocolError as openid_error:

              self.debug('ProtocolError: %s' % openid_error)

              raise InvalidRequest('Invalid OpenID request')

  
@@ -241,7 +241,7 @@ 

              cherrypy.response.headers.update(webresponse.headers)

              cherrypy.response.status = webresponse.code

              return webresponse.body

-         except EncodingError, encoding_error:

+         except EncodingError as encoding_error:

              self.debug('Unable to respond because: %s' % encoding_error)

              cherrypy.response.headers = {

                  'Content-Type': 'text/plain; charset=UTF-8'

@@ -41,7 +41,7 @@ 

                      self.trans.cookie.value != self.trans.provider):

                  self.debug('Invalid transaction, %s != %s' % (

                             self.trans.cookie.value, self.trans.provider))

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              self.debug('Transaction initialization failed: %s' % repr(e))

              raise cherrypy.HTTPError(400, 'Invalid transaction id')

  
@@ -319,7 +319,7 @@ 

          # Build the "claims" values from scopes

          try:

              request_data['claims'] = json.loads(request_data['claims'])

-         except Exception, ex:  # pylint: disable=broad-except

+         except Exception as ex:  # pylint: disable=broad-except

              return self._respond_error(request_data,

                                         'invalid_request',

                                         'claims malformed: %s' % ex)

@@ -65,7 +65,7 @@ 

          try:

              self.key = M2Crypto.RSA.load_key(self.idp_key_file,

                                               lambda *args: None)

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              self.debug('Failed to init Persona provider: %r' % e)

              return None

  

@@ -101,7 +101,7 @@ 

                              r = requests.get(value)

                              r.raise_for_status()

                              meta = r.content

-                         except Exception, e:  # pylint: disable=broad-except

+                         except Exception as e:  # pylint: disable=broad-except

                              self.debug("Failed to fetch metadata: " + repr(e))

                              message = "Failed to fetch metadata: " + repr(e)

                              message_type = ADMIN_STATUS_ERROR
@@ -116,10 +116,10 @@ 

                      message = "SP Successfully added"

                      message_type = ADMIN_STATUS_OK

                      return sp_page.root_with_msg(message, message_type)

-                 except InvalidProviderId, e:

+                 except InvalidProviderId as e:

                      message = str(e)

                      message_type = ADMIN_STATUS_ERROR

-                 except Exception, e:  # pylint: disable=broad-except

+                 except Exception as e:  # pylint: disable=broad-except

                      self.debug(repr(e))

                      message = "Failed to create Service Provider!"

                      message_type = ADMIN_STATUS_ERROR
@@ -284,15 +284,15 @@ 

                          validate_sp_metadata(value)

                          self.sp.metadata = value

  

-             except InvalidProviderMetadata, e:

+             except InvalidProviderMetadata as e:

                  message = str(e)

                  message_type = ADMIN_STATUS_WARN

                  return self.root_with_msg(message, message_type)

-             except InvalidValueFormat, e:

+             except InvalidValueFormat as e:

                  message = str(e)

                  message_type = ADMIN_STATUS_WARN

                  return self.root_with_msg(message, message_type)

-             except UnauthorizedUser, e:

+             except UnauthorizedUser as e:

                  message = str(e)

                  message_type = ADMIN_STATUS_ERROR

                  return self.root_with_msg(message, message_type)
@@ -352,7 +352,7 @@ 

              page = getattr(self.sp, name)

              self.providers.remove(page.sp)

              self.sp.del_subtree(name)

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              self.debug("Failed to remove provider %s: %s" % (name, str(e)))

  

      def add_sps(self):
@@ -362,7 +362,7 @@ 

                      sp = ServiceProvider(self.cfg, p)

                      self.del_sp(sp.name)

                      self.add_sp(sp.name, sp)

-                 except Exception, e:  # pylint: disable=broad-except

+                 except Exception as e:  # pylint: disable=broad-except

                      self.debug("Failed to find provider %s: %s" % (p, str(e)))

  

      def mount(self, page):

file modified
+11 -11
@@ -53,7 +53,7 @@ 

                  if self.trans.cookie.value != self.trans.provider:

                      self.debug('Invalid transaction, %s != %s' % (

                          self.trans.cookie.value, self.trans.provider))

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              self.debug('Transaction initialization failed: %s' % repr(e))

              raise cherrypy.HTTPError(400, 'Invalid transaction id')

  
@@ -66,7 +66,7 @@ 

      def auth(self, login):

          try:

              self.saml2checks(login)

-         except AuthenticationError, e:

+         except AuthenticationError as e:

              self.saml2error(login, e.code, e.message)

          return self.reply(login)

  
@@ -93,20 +93,20 @@ 

              )

              raise InvalidRequest(msg)

          except (lasso.ProfileInvalidMsgError,

-                 lasso.ProfileMissingIssuerError), e:

+                 lasso.ProfileMissingIssuerError) as e:

  

              msg = 'Malformed Request %r [%r]' % (e, message)

              raise InvalidRequest(msg)

  

          except (lasso.ProfileInvalidProtocolprofileError,

-                 lasso.DsError), e:

+                 lasso.DsError) as e:

  

              msg = 'Invalid SAML Request: %r (%r [%r])' % (login.request,

                                                            e, message)

              raise InvalidRequest(msg)

  

          except (lasso.ServerProviderNotFoundError,

-                 lasso.ProfileUnknownProviderError), e:

+                 lasso.ProfileUnknownProviderError) as e:

  

              msg = 'Invalid SP [%s] (%r [%r])' % (login.remoteProviderId,

                                                   e, message)
@@ -160,19 +160,19 @@ 

                  login = self._idp_initiated_login(spidentifier, relaystate)

              except lasso.ServerProviderNotFoundError:

                  raise cherrypy.HTTPError(400, 'Unknown Service Provider')

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.debug(str(e))

                  raise cherrypy.HTTPError(500)

          else:

              try:

                  login = self._parse_request(request)

-             except InvalidRequest, e:

+             except InvalidRequest as e:

                  self.debug(str(e))

                  raise cherrypy.HTTPError(400, 'Invalid SAML request token')

-             except UnknownProvider, e:

+             except UnknownProvider as e:

                  self.debug(str(e))

                  raise cherrypy.HTTPError(400, 'Unknown Service Provider')

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.debug(str(e))

                  raise cherrypy.HTTPError(500)

  
@@ -213,10 +213,10 @@ 

          try:

              provider = ServiceProvider(self.cfg, login.remoteProviderId)

              nameidfmt = provider.get_valid_nameid(login.request.nameIdPolicy)

-         except NameIdNotAllowed, e:

+         except NameIdNotAllowed as e:

              raise AuthenticationError(

                  str(e), lasso.SAML2_STATUS_CODE_INVALID_NAME_ID_POLICY)

-         except InvalidProviderId, e:

+         except InvalidProviderId as e:

              raise AuthenticationError(

                  str(e), lasso.SAML2_STATUS_CODE_AUTHN_FAILED)

  

@@ -79,7 +79,7 @@ 

  

          try:

              logout.validateRequest()

-         except lasso.ProfileSessionNotFoundError, e:

+         except lasso.ProfileSessionNotFoundError as e:

              self.error('Logout failed. No sessions for %s' %

                         logout.remoteProviderId)

              return self._not_logged_in(logout, message)
@@ -87,7 +87,7 @@ 

              self.error('Logout failed. Unsupported profile %s' %

                         logout.remoteProviderId)

              raise cherrypy.HTTPError(400, 'Profile does not support logout')

-         except lasso.Error, e:

+         except lasso.Error as e:

              self.error('SLO validation failed: %s' % e)

              raise cherrypy.HTTPError(400, 'Failed to validate logout request')

  
@@ -96,7 +96,7 @@ 

          except lasso.ProfileUnsupportedProfileError:

              self.error('Unsupported profile for %s' % logout.remoteProviderId)

              raise cherrypy.HTTPError(400, 'Profile does not support logout')

-         except lasso.Error, e:

+         except lasso.Error as e:

              self.error('SLO failed to build logout response: %s' % e)

  

          for ind in session_indexes:
@@ -184,12 +184,12 @@ 

              self.error(msg)

              raise UnknownProvider(msg)

          except (lasso.ProfileInvalidProtocolprofileError,

-                 lasso.DsError), e:

+                 lasso.DsError) as e:

              msg = 'Invalid SAML Request: %r (%r [%r])' % (logout.request,

                                                            e, message)

              self.error(msg)

              raise InvalidRequest(msg)

-         except lasso.Error, e:

+         except lasso.Error as e:

              self.error('SLO unknown error: %s' % message)

              raise cherrypy.HTTPError(400, 'Invalid logout request')

  
@@ -307,7 +307,7 @@ 

  

              try:

                  logout.buildRequestMsg()

-             except lasso.Error, e:

+             except lasso.Error as e:

                  self.error('failure to build logout request msg: %s' % e)

                  raise cherrypy.HTTPRedirect(400, 'Failed to log out user: %s '

                                              % e)

@@ -106,7 +106,7 @@ 

          except (InvalidProviderId, ServerAddProviderFailedError) as e:

              self.debug(repr(e))

              return rest_error(400, str(e))

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              self.debug(repr(e))

              return rest_error(500, "Failed to create Service Provider")

  

@@ -127,7 +127,7 @@ 

  

          try:

              login = self.cfg.idp.get_login_handler(dump)

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              self.error('Failed to load login status from dump: %r' % e)

  

          if not login:
@@ -366,7 +366,7 @@ 

          try:

              idp = IdentityProvider(self,

                                     sessionfactory=self.sessionfactory)

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              self.error('Failed to init SAML2 provider: %r' % e)

              return None

  
@@ -382,7 +382,7 @@ 

                  continue

              try:

                  idp.add_provider(sp)

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error('Failed to add SP %s: %r' % (sp['name'], e))

  

          return idp
@@ -433,7 +433,7 @@ 

              return self.idp_initiated_logout()

          try:

              logout.buildRequestMsg()

-         except lasso.Error, e:

+         except lasso.Error as e:

              self.error('failure to build logout request msg: %s' % e)

              raise cherrypy.HTTPRedirect(400, 'Failed to log out user: %s '

                                          % e)

@@ -169,9 +169,9 @@ 

          idp.output(md_file)

          with open(md_file) as fd:

              text = fd.read()

-         print '==================== IDP ===================='

-         print text

-         print '============================================='

+         print('==================== IDP ====================')

+         print(text)

+         print('=============================================')

  

          # Test SP generation

          sign_cert = Certificate(tmpdir)
@@ -188,9 +188,9 @@ 

          sp.output(md_file)

          with open(md_file) as fd:

              text = fd.read()

-         print '===================== SP ===================='

-         print text

-         print '============================================='

+         print('===================== SP ====================')

+         print(text)

+         print('=============================================')

  

      finally:

          shutil.rmtree(tmpdir)

file modified
+12 -12
@@ -286,7 +286,7 @@ 

      def get_config(self):

          try:

              stat = os.stat(self._filename)

-         except OSError, e:

+         except OSError as e:

              self.error("Unable to check config file %s: [%s]" % (

                  self._filename, e))

              self._config = None
@@ -922,7 +922,7 @@ 

          with q:

              try:

                  rows = q.select(kvfilter)

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error("Failed to load data for table %s for store %s:[%s]"

                             % (table, self.__class__.__name__, e))

          return self._rows_to_dict_tree(rows)
@@ -961,7 +961,7 @@ 

                      if opt not in options:

                          q.delete({'name': name, 'option': opt})

  

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error("Failed to save options: [%s]" % e)

                  raise

  
@@ -976,7 +976,7 @@ 

                      for opt in options:

                          kvfilter['option'] = opt

                          q.delete(kvfilter)

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error("Failed to delete from %s: [%s]" % (table, e))

                  raise

  
@@ -996,7 +996,7 @@ 

                      q.insert((newid, name, data[name]), ttl)

                  if expiration_time:

                      q.insert((newid, 'expiration_time', expiration_time), ttl)

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error("Failed to store %s data: [%s]" % (table, e))

                  raise

          return newid
@@ -1042,7 +1042,7 @@ 

                              if datum[name] is not None:

                                  q.insert((uid, name, datum[name]), ttl)

  

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error("Failed to store data in %s: [%s]" % (table, e))

                  raise

  
@@ -1052,7 +1052,7 @@ 

          with q:

              try:

                  q.delete(kvfilter)

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error("Failed to delete data from %s: [%s]" % (table, e))

  

      def _reset_data(self, table):
@@ -1061,7 +1061,7 @@ 

              try:

                  q.drop()

                  q.create()

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  if q:

                      q.rollback()

                  self.error("Failed to erase all data from %s: [%s]"
@@ -1169,7 +1169,7 @@ 

                                                       'option': key})

                  else:

                      q.insert((user, key, parameters))

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error('Failed to store consent: [%s]' % e)

                  raise

  
@@ -1179,7 +1179,7 @@ 

              try:

                  q.delete({'name': user,

                            'option': self._cons_key(provider, clientid)})

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error('Failed to delete consent: [%s]' % e)

                  raise

  
@@ -1195,7 +1195,7 @@ 

                      return data[0][0]

                  else:

                      return None

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error('Failed to get consent: [%s]' % e)

                  raise

  
@@ -1208,7 +1208,7 @@ 

                  for r in rows:

                      prov, clientid = self._split_cons_key(r[0])

                      d.append((prov, clientid, r[1]))

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error('Failed to get consents: [%s]' % e)

                  raise

          return d

file modified
+1 -1
@@ -250,7 +250,7 @@ 

  

      string = f.getvalue()

      f.close()

-     print string

+     print(string)

  

  

  cherrypy.tools.log_request_response = cherrypy.Tool('on_end_resource',

file modified
+3 -3
@@ -25,7 +25,7 @@ 

              #    mod = imp.load_compiled(name, file_name)

              else:

                  return

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              cherrypy.log.error('Failed to load "%s" module: [%s]' % (name, e),

                                 severity=logging.ERROR)

              return
@@ -41,7 +41,7 @@ 

          files = None

          try:

              files = os.listdir(path)

-         except Exception, e:  # pylint: disable=broad-except

+         except Exception as e:  # pylint: disable=broad-except

              cherrypy.log.error('No modules in %s: [%s]' % (path, e),

                                 severity=logging.ERROR)

              return
@@ -192,7 +192,7 @@ 

          if config:

              try:

                  self.import_config(config)

-             except Exception, e:  # pylint: disable=broad-except

+             except Exception as e:  # pylint: disable=broad-except

                  self.error('Failed to refresh config for %s (%s)' %

                             (self.name, e))

          self.on_reconfigure()

file modified
+19 -19
@@ -392,21 +392,21 @@ 

      # test defaults first

      p = Policy()

  

-     print 'Default attribute mapping'

+     print('Default attribute mapping')

      m, n = p.map_attributes(t_attributes)

      if m == t_attributes and n is None:

-         print 'SUCCESS'

+         print('SUCCESS')

      else:

          ret += 1

-         print 'FAIL: Expected %s\nObtained %s' % (t_attributes, m)

+         print('FAIL: Expected %s\nObtained %s' % (t_attributes, m))

  

-     print 'Default attribute filtering'

+     print('Default attribute filtering')

      f = p.filter_attributes(t_attributes)

      if f == t_attributes:

-         print 'SUCCESS'

+         print('SUCCESS')

      else:

          ret += 1

-         print 'Expected %s\nObtained %s' % (t_attributes, f)

+         print('Expected %s\nObtained %s' % (t_attributes, f))

  

      # test custom mappings and filters

      t_mappings = [[['onenameone'], 'onemappedone'],
@@ -444,21 +444,21 @@ 

  

      p = Policy(t_mappings, t_allowed)

  

-     print 'Custom attribute mapping'

+     print('Custom attribute mapping')

      m, n = p.map_attributes(t_attributes)

      if m == m_result and n == n_result:

-         print 'SUCCESS'

+         print('SUCCESS')

      else:

          ret += 1

-         print 'Expected %s\nObtained %s' % (m_result, m)

+         print('Expected %s\nObtained %s' % (m_result, m))

  

-     print 'Custom attribute filtering'

+     print('Custom attribute filtering')

      f = p.filter_attributes(m)

      if f == f_result:

-         print 'SUCCESS'

+         print('SUCCESS')

      else:

          ret += 1

-         print 'Expected %s\nObtained %s' % (f_result, f)

+         print('Expected %s\nObtained %s' % (f_result, f))

  

      t2_allowed = ['onemappedone', 'twonametwo', 'threemappedone',

                    ['listfive', 'two']]
@@ -473,14 +473,14 @@ 

  

      p = Policy(t_mappings, t2_allowed)

  

-     print 'Custom attribute filtering 2'

+     print('Custom attribute filtering 2')

      m, _ = p.map_attributes(t_attributes)

      f = p.filter_attributes(m, whitelist=False)

      if f == f2_result:

-         print 'SUCCESS'

+         print('SUCCESS')

      else:

          ret += 1

-         print 'Expected %s\nObtained %s' % (f2_result, f)

+         print('Expected %s\nObtained %s' % (f2_result, f))

  

      # Case Insensitive matching

      tci_attributes = {'oneNameone': 'onevalueone',
@@ -518,13 +518,13 @@ 

                    'six': ['two', 'three']}

  

      p = Policy(tci_mappings)

-     print 'Case insensitive attribute mapping'

+     print('Case insensitive attribute mapping')

      m, n = p.map_attributes(tci_attributes, ignore_case=True)

      if m == mci_result and n == nci_result:

-         print 'SUCCESS'

+         print('SUCCESS')

      else:

          ret += 1

-         print 'FAIL: Expected %s // %s\nObtained %s // %s' % \

-             (mci_result, nci_result, m, n)

+         print('FAIL: Expected %s // %s\nObtained %s // %s' %

+               (mci_result, nci_result, m, n))

  

      sys.exit(ret)

file modified
+18 -16
@@ -2,6 +2,8 @@ 

  #

  # Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING

  

+ from __future__ import print_function

+ 

  from helpers.common import IpsilonTestBase  # pylint: disable=relative-import

  from helpers.http import HttpSessions  # pylint: disable=relative-import

  import os
@@ -85,17 +87,17 @@ 

          super(IpsilonTest, self).__init__('attrs', __file__)

  

      def setup_servers(self, env=None):

-         print "Installing IDP server"

+         print("Installing IDP server")

          name = 'idp1'

          addr = '127.0.0.10'

          port = '45080'

          idp = self.generate_profile(idp_g, idp_a, name, addr, port)

          conf = self.setup_idp_server(idp, name, addr, port, env)

  

-         print "Starting IDP's httpd server"

+         print("Starting IDP's httpd server")

          self.start_http_server(conf, env)

  

-         print "Installing SP server"

+         print("Installing SP server")

          name = 'sp1'

          addr = '127.0.0.11'

          port = '45081'
@@ -103,7 +105,7 @@ 

          conf = self.setup_sp_server(sp, name, addr, port, env)

          fixup_sp_httpd(os.path.dirname(conf))

  

-         print "Starting SP's httpd server"

+         print("Starting SP's httpd server")

          self.start_http_server(conf, env)

  

  
@@ -117,28 +119,28 @@ 

      sess.add_server(idpname, 'https://127.0.0.10:45080', user, 'ipsilon')

      sess.add_server(spname, 'https://127.0.0.11:45081')

  

-     print "attrs: Authenticate to IDP ...",

+     print("attrs: Authenticate to IDP ...", end=' ')

      try:

          sess.auth_to_idp(idpname)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "attrs: Add SP Metadata to IDP ...",

+     print("attrs: Add SP Metadata to IDP ...", end=' ')

      try:

          sess.add_sp_metadata(idpname, spname)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "attrs: Access SP Protected Area Variables...",

+     print("attrs: Access SP Protected Area Variables...", end=' ')

      try:

          page = sess.fetch_page(idpname,

                                 'https://127.0.0.11:45081/sp/index.shtml')

          page.expected_value('text()', 'Test User %s' % user)

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

file modified
+51 -48
@@ -2,6 +2,8 @@ 

  #

  # Copyright (C) 2016 Ipsilon project Contributors, for license see COPYING

  

+ from __future__ import print_function

+ 

  from helpers.common import IpsilonTestBase  # pylint: disable=relative-import

  from helpers.http import HttpSessions  # pylint: disable=relative-import

  import os
@@ -91,17 +93,17 @@ 

          super(IpsilonTest, self).__init__('authz', __file__)

  

      def setup_servers(self, env=None):

-         print "Installing IDP server"

+         print("Installing IDP server")

          name = 'idp1'

          addr = '127.0.0.10'

          port = '45080'

          idp = self.generate_profile(idp_g, idp_a, name, addr, port)

          conf = self.setup_idp_server(idp, name, addr, port, env)

  

-         print "Starting IDP's httpd server"

+         print("Starting IDP's httpd server")

          self.start_http_server(conf, env)

  

-         print "Installing first SP server"

+         print("Installing first SP server")

          name = 'sp1'

          addr = '127.0.0.11'

          port = '45081'
@@ -109,10 +111,10 @@ 

          conf = self.setup_sp_server(sp, name, addr, port, env)

          fixup_sp_httpd(os.path.dirname(conf))

  

-         print "Starting first SP's httpd server"

+         print("Starting first SP's httpd server")

          self.start_http_server(conf, env)

  

-         print "Installing second SP server"

+         print("Installing second SP server")

          name = 'sp2'

          addr = '127.0.0.12'

          port = '45082'
@@ -120,7 +122,7 @@ 

          conf = self.setup_sp_server(sp, name, addr, port, env)

          fixup_sp_httpd(os.path.dirname(conf))

  

-         print "Starting second SP's httpd server"

+         print("Starting second SP's httpd server")

          self.start_http_server(conf, env)

  

  
@@ -136,106 +138,107 @@ 

      sess.add_server(sp1name, 'https://127.0.0.11:45081')

      sess.add_server(sp2name, 'https://127.0.0.12:45082')

  

-     print "authz: Authenticate to IDP ...",

+     print("authz: Authenticate to IDP ...", end=' ')

      try:

          sess.auth_to_idp(idpname)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "authz: Add SP1 Metadata to IDP ...",

+     print("authz: Add SP1 Metadata to IDP ...", end=' ')

      try:

          sess.add_sp_metadata(idpname, sp1name)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "authz: Add SP2 Metadata to IDP ...",

+     print("authz: Add SP2 Metadata to IDP ...", end=' ')

      try:

          sess.add_sp_metadata(idpname, sp2name)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "authz: Access SP1 when authz stack set to allow ...",

+     print("authz: Access SP1 when authz stack set to allow ...", end=' ')

      try:

          page = sess.fetch_page(idpname, 'https://127.0.0.11:45081/sp/')

          page.expected_value('text()', 'WORKS!')

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "authz: Set IDP authz stack to deny ...",

+     print("authz: Set IDP authz stack to deny ...", end=' ')

      try:

          sess.disable_plugin(idpname, 'authz', 'allow')

          sess.enable_plugin(idpname, 'authz', 'deny')

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

      sess2 = HttpSessions()

      sess2.add_server(idpname, 'https://127.0.0.10:45080', user, 'ipsilon')

      sess2.add_server(sp1name, 'https://127.0.0.11:45081')

  

-     print "authz: Fail access SP1 when authz stack set to deny, with " \

-         "pre-auth ...",

+     print("authz: Fail access SP1 when authz stack set to deny, with "

+           "pre-auth ...", end=' ')

      try:

          sess2.auth_to_idp(idpname)

          page = sess2.fetch_page(idpname, 'https://127.0.0.11:45081/sp/')

          page.expected_status(401)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

      sess3 = HttpSessions()

      sess3.add_server(idpname, 'https://127.0.0.10:45080', user, 'ipsilon')

      sess3.add_server(sp1name, 'https://127.0.0.11:45081')

  

-     print "authz: Fail access SP1 when authz stack set to deny, without " \

-         "pre-auth ...",

+     print("authz: Fail access SP1 when authz stack set to deny, without "

+           "pre-auth ...", end=' ')

      try:

          page = sess3.fetch_page(idpname, 'https://127.0.0.11:45081/sp/')

          page.expected_status(401)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "authz: Set IDP authz stack to spgroup ...",

+     print("authz: Set IDP authz stack to spgroup ...", end=' ')

      try:

          sess.disable_plugin(idpname, 'authz', 'deny')

          sess.enable_plugin(idpname, 'authz', 'spgroup')

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

      sess4 = HttpSessions()

      sess4.add_server(idpname, 'https://127.0.0.10:45080', user, 'ipsilon')

      sess4.add_server(sp1name, 'https://127.0.0.11:45081')

      sess4.add_server(sp2name, 'https://127.0.0.12:45082')

  

-     print "authz: Access SP1 when authz stack set to spgroup ...",

+     print("authz: Access SP1 when authz stack set to spgroup ...", end=' ')

      try:

          sess4.auth_to_idp(idpname)

          page = sess4.fetch_page(idpname, 'https://127.0.0.11:45081/sp/')

          page.expected_value('text()', 'WORKS!')

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "authz: Fail to access SP2 when authz stack set to spgroup ...",

+     print("authz: Fail to access SP2 when authz stack set to spgroup ...",

+           end=' ')

      try:

          page = sess4.fetch_page(idpname, 'https://127.0.0.12:45082/sp/')

          page.expected_status(401)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

file modified
+9 -6
@@ -2,6 +2,8 @@ 

  #

  # Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING

  

+ from __future__ import print_function

+ 

  from helpers.common import IpsilonTestBase  # pylint: disable=relative-import

  from helpers.http import HttpSessions  # pylint: disable=relative-import

  import os
@@ -46,13 +48,13 @@ 

                               stdout=subprocess.PIPE)

          output, _ = p.communicate()

          if p.returncode:

-             print 'Sqlite dump failed'

+             print('Sqlite dump failed')

              sys.exit(1)

          return output

  

      def test_upgrade_from(self, env, old_version):

          # Setup IDP Server

-         print "Installing IDP server to test upgrade from %i" % old_version

+         print("Installing IDP server to test upgrade from %i" % old_version)

          name = 'idp_v%i' % old_version

          addr = '127.0.0.%i' % (10 + old_version)

          port = str(45080 + old_version)
@@ -146,10 +148,11 @@ 

      sess.add_server(idpname, 'https://%s' % url, user,

                      'ipsilon')

  

-     print "dbupgrades: From v%s: Authenticate to IDP ..." % from_version,

+     print("dbupgrades: From v%s: Authenticate to IDP ..." % from_version,

+           end=' ')

      try:

          sess.auth_to_idp(idpname)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

file modified
+15 -13
@@ -2,6 +2,8 @@ 

  #

  # Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING

  

+ from __future__ import print_function

+ 

  from helpers.common import IpsilonTestBase  # pylint: disable=relative-import

  from helpers.http import HttpSessions  # pylint: disable=relative-import

  import ConfigParser
@@ -139,18 +141,18 @@ 

          super(IpsilonTest, self).__init__('fconf', __file__)

  

      def setup_servers(self, env=None):

-         print "Installing IDP server"

+         print("Installing IDP server")

          idp = self.generate_profile(idp_g, idp_a, idpname, idpaddr, idpport)

          idpconf = self.setup_idp_server(idp, idpname, idpaddr, idpport, env)

  

-         print "Installing SP server"

+         print("Installing SP server")

          sp = self.generate_profile(sp_g, sp_a, spname, spaddr, spport)

          spconf = self.setup_sp_server(sp, spname, spaddr, spport, env)

          fixup_sp_httpd(os.path.dirname(spconf))

  

          fixup_idp_conf(self.testdir)

  

-         print "Testing database upgrade"

+         print("Testing database upgrade")

          cfgfile = os.path.join(self.testdir, 'etc', idpname, 'ipsilon.conf')

          cmd = [os.path.join(self.rootdir,

                              'ipsilon/install/ipsilon-upgrade-database'),
@@ -159,10 +161,10 @@ 

                                cwd=os.path.join(self.testdir, 'lib', idpname),

                                env=env)

  

-         print "Starting IDP's httpd server"

+         print("Starting IDP's httpd server")

          self.start_http_server(idpconf, env)

  

-         print "Starting SP's httpd server"

+         print("Starting SP's httpd server")

          self.start_http_server(spconf, env)

  

  
@@ -174,20 +176,20 @@ 

      sess.add_server(idpname, 'https://127.0.0.10:45080', user, 'ipsilon')

      sess.add_server(spname, 'https://127.0.0.11:45081')

  

-     print "fconf: Access IdP Homepage ... ",

+     print("fconf: Access IdP Homepage ... ", end=' ')

      try:

          page = sess.fetch_page(idpname, 'https://127.0.0.10:45080/idp1/')

          page.expected_value('//title/text()', 'Ipsilon')

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "fconf: Access SP Protected Area ...",

+     print("fconf: Access SP Protected Area ...", end=' ')

      try:

          page = sess.fetch_page(idpname, 'https://127.0.0.11:45081/sp/')

          page.expected_value('text()', 'WORKS!')

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

file modified
+20 -18
@@ -2,6 +2,8 @@ 

  #

  # Copyright (C) 2015 Ipsilon project Contributors, for license see COPYING

  

+ from __future__ import print_function

+ 

  from helpers.common import IpsilonTestBase  # pylint: disable=relative-import

  from helpers.http import HttpSessions  # pylint: disable=relative-import

  import os
@@ -90,25 +92,25 @@ 

  

      def setup_servers(self, env=None):

  

-         print "Installing IDP's ldap server"

+         print("Installing IDP's ldap server")

          addr = '127.0.0.10'

          port = '45389'

          conf = self.setup_ldap(env)

  

-         print "Starting IDP's ldap server"

+         print("Starting IDP's ldap server")

          self.start_ldap_server(conf, addr, port, env)

  

-         print "Installing IDP server"

+         print("Installing IDP server")

          name = 'idp1'

          addr = '127.0.0.10'

          port = '45080'

          idp = self.generate_profile(idp_g, idp_a, name, addr, port)

          conf = self.setup_idp_server(idp, name, addr, port, env)

  

-         print "Starting IDP's httpd server"

+         print("Starting IDP's httpd server")

          self.start_http_server(conf, env)

  

-         print "Installing SP server"

+         print("Installing SP server")

          name = 'sp1'

          addr = '127.0.0.11'

          port = '45081'
@@ -116,7 +118,7 @@ 

          conf = self.setup_sp_server(sp, name, addr, port, env)

          fixup_sp_httpd(os.path.dirname(conf))

  

-         print "Starting SP's httpd server"

+         print("Starting SP's httpd server")

          self.start_http_server(conf, env)

  

  
@@ -130,28 +132,28 @@ 

      sess.add_server(idpname, 'https://127.0.0.10:45080', user, 'tuser')

      sess.add_server(spname, 'https://127.0.0.11:45081')

  

-     print "ldap: Authenticate to IDP ...",

+     print("ldap: Authenticate to IDP ...", end=' ')

      try:

          sess.auth_to_idp(idpname)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "ldap: Add SP Metadata to IDP ...",

+     print("ldap: Add SP Metadata to IDP ...", end=' ')

      try:

          sess.add_sp_metadata(idpname, spname)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "ldap: Access SP Protected Area ...",

+     print("ldap: Access SP Protected Area ...", end=' ')

      try:

          page = sess.fetch_page(idpname,

                                 'https://127.0.0.11:45081/sp/index.shtml')

          page.expected_value('text()', 'Test Group;Test Group 2')

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

file modified
+12 -10
@@ -4,6 +4,8 @@ 

  

  # Test that we get a reasonable error back when the LDAP backend is down

  

+ from __future__ import print_function

+ 

  from helpers.common import IpsilonTestBase  # pylint: disable=relative-import

  from helpers.http import HttpSessions  # pylint: disable=relative-import

  import os
@@ -92,24 +94,24 @@ 

  

      def setup_servers(self, env=None):

  

-         print "Installing IDP's ldap server"

+         print("Installing IDP's ldap server")

          addr = '127.0.0.10'

          port = '45389'

          conf = self.setup_ldap(env)

  

-         print "Not starting IDP's ldap server"

+         print("Not starting IDP's ldap server")

  

-         print "Installing IDP server"

+         print("Installing IDP server")

          name = 'idp1'

          addr = '127.0.0.10'

          port = '45080'

          idp = self.generate_profile(idp_g, idp_a, name, addr, port)

          conf = self.setup_idp_server(idp, name, addr, port, env)

  

-         print "Starting IDP's httpd server"

+         print("Starting IDP's httpd server")

          self.start_http_server(conf, env)

  

-         print "Installing SP server"

+         print("Installing SP server")

          name = 'sp1'

          addr = '127.0.0.11'

          port = '45081'
@@ -117,7 +119,7 @@ 

          conf = self.setup_sp_server(sp, name, addr, port, env)

          fixup_sp_httpd(os.path.dirname(conf))

  

-         print "Starting SP's httpd server"

+         print("Starting SP's httpd server")

          self.start_http_server(conf, env)

  

  
@@ -131,14 +133,14 @@ 

      sess.add_server(idpname, 'https://127.0.0.10:45080', user, 'tuser')

      sess.add_server(spname, 'https://127.0.0.11:45081')

  

-     print "ldapdown: Authenticate to IDP with no LDAP backend...",

+     print("ldapdown: Authenticate to IDP with no LDAP backend...", end=' ')

      try:

          sess.auth_to_idp(

              idpname,

              rule='//div[@class="alert alert-danger"]/p/text()',

              expected="Internal system error"

          )

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

file modified
+37 -33
@@ -2,6 +2,8 @@ 

  #

  # Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING

  

+ from __future__ import print_function

+ 

  from helpers.common import IpsilonTestBase  # pylint: disable=relative-import

  from helpers.http import HttpSessions  # pylint: disable=relative-import

  import os
@@ -60,17 +62,17 @@ 

          super(IpsilonTest, self).__init__('openid', __file__)

  

      def setup_servers(self, env=None):

-         print "Installing IDP server"

+         print("Installing IDP server")

          name = 'idp1'

          addr = '127.0.0.10'

          port = '45080'

          idp = self.generate_profile(idp_g, idp_a, name, addr, port)

          conf = self.setup_idp_server(idp, name, addr, port, env)

  

-         print "Starting IDP's httpd server"

+         print("Starting IDP's httpd server")

          self.start_http_server(conf, env)

  

-         print "Installing first SP server"

+         print("Installing first SP server")

          name = 'sp1'

          addr = '127.0.0.11'

          port = '45081'
@@ -79,7 +81,7 @@ 

              inspect.currentframe())))

          fixup_sp_httpd(os.path.dirname(conf), testdir)

  

-         print "Starting SP's httpd server"

+         print("Starting SP's httpd server")

          self.start_http_server(conf, env)

  

  
@@ -93,56 +95,56 @@ 

      sess.add_server(idpname, 'https://127.0.0.10:45080', user, 'ipsilon')

      sess.add_server(sp1name, 'https://127.0.0.11:45081')

  

-     print "openid: Authenticate to IDP ...",

+     print("openid: Authenticate to IDP ...", end=' ')

      try:

          sess.auth_to_idp(idpname)

      except Exception as e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openid: Run OpenID Protocol ...",

+     print("openid: Run OpenID Protocol ...", end=' ')

      try:

          page = sess.fetch_page(idpname,

                                 'https://127.0.0.11:45081/?extensions=NO',

                                 require_consent=True)

          page.expected_value('text()', 'SUCCESS, WITHOUT EXTENSIONS')

      except ValueError as e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openid: Run OpenID Protocol without consent ...",

+     print("openid: Run OpenID Protocol without consent ...", end=' ')

      try:

          page = sess.fetch_page(idpname,

                                 'https://127.0.0.11:45081/?extensions=NO',

                                 require_consent=False)

          page.expected_value('text()', 'SUCCESS, WITHOUT EXTENSIONS')

      except ValueError as e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openid: Revoking SP consent ...",

+     print("openid: Revoking SP consent ...", end=' ')

      try:

          page = sess.revoke_all_consent(idpname)

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openid: Run OpenID Protocol without consent ...",

+     print("openid: Run OpenID Protocol without consent ...", end=' ')

      try:

          page = sess.fetch_page(idpname,

                                 'https://127.0.0.11:45081/?extensions=NO',

                                 require_consent=True)

          page.expected_value('text()', 'SUCCESS, WITHOUT EXTENSIONS')

      except ValueError as e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openid: Run OpenID Protocol with extensions ...",

+     print("openid: Run OpenID Protocol with extensions ...", end=' ')

      try:

          # We expect consent again because we added more attributes

          page = sess.fetch_page(idpname,
@@ -150,44 +152,46 @@ 

                                 require_consent=True)

          page.expected_value('text()', 'SUCCESS, WITH EXTENSIONS')

      except ValueError as e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openid: Set IDP authz stack to deny ...",

+     print("openid: Set IDP authz stack to deny ...", end=' ')

      try:

          sess.disable_plugin(idpname, 'authz', 'allow')

          sess.enable_plugin(idpname, 'authz', 'deny')

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

      sess2 = HttpSessions()

      sess2.add_server(idpname, 'https://127.0.0.10:45080', user, 'ipsilon')

      sess2.add_server(sp1name, 'https://127.0.0.11:45081')

  

-     print "openid: Run OpenID Protocol with IDP deny, with pre-auth ...",

+     print("openid: Run OpenID Protocol with IDP deny, with pre-auth ...",

+           end=' ')

      try:

          sess2.auth_to_idp(idpname)

          page = sess2.fetch_page(idpname,

                                  'https://127.0.0.11:45081/?extensions=NO')

          page.expected_value('text()', 'ERROR: Cancelled')

      except ValueError as e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

      sess3 = HttpSessions()

      sess3.add_server(idpname, 'https://127.0.0.10:45080', user, 'ipsilon')

      sess3.add_server(sp1name, 'https://127.0.0.11:45081')

  

-     print "openid: Run OpenID Protocol with IDP deny, without pre-auth ...",

+     print("openid: Run OpenID Protocol with IDP deny, without pre-auth ...",

+           end=' ')

      try:

          page = sess3.fetch_page(idpname,

                                  'https://127.0.0.11:45081/?extensions=NO')

          page.expected_value('text()', 'ERROR: Cancelled')

      except ValueError as e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

file modified
+78 -75
@@ -2,6 +2,8 @@ 

  #

  # Copyright (C) 2016 Ipsilon project Contributors, for license see COPYING

  

+ from __future__ import print_function

+ 

  from helpers.common import IpsilonTestBase  # pylint: disable=relative-import

  from helpers.http import HttpSessions  # pylint: disable=relative-import

  import os
@@ -157,17 +159,17 @@ 

          super(IpsilonTest, self).__init__('openidc', __file__)

  

      def setup_servers(self, env=None):

-         print "Installing IDP server"

+         print("Installing IDP server")

          name = 'idp1'

          addr = '127.0.0.10'

          port = '45080'

          idp = self.generate_profile(idp_g, idp_a, name, addr, port)

          conf = self.setup_idp_server(idp, name, addr, port, env)

  

-         print "Starting IDP's httpd server"

+         print("Starting IDP's httpd server")

          self.start_http_server(conf, env)

  

-         print "Installing first SP server"

+         print("Installing first SP server")

          name = 'sp1'

          addr = '127.0.0.11'

          port = '45081'
@@ -175,10 +177,10 @@ 

          conf = self.setup_sp_server(sp, name, addr, port, env)

          fixup_sp_httpd(os.path.dirname(conf))

  

-         print "Starting first SP's httpd server"

+         print("Starting first SP's httpd server")

          self.start_http_server(conf, env)

  

-         print "Installing second SP server"

+         print("Installing second SP server")

          name = 'sp2'

          addr = '127.0.0.12'

          port = '45082'
@@ -186,10 +188,10 @@ 

          conf = self.setup_sp_server(sp, name, addr, port, env)

          fixup_sp_httpd(os.path.dirname(conf))

  

-         print "Starting second SP's httpd server"

+         print("Starting second SP's httpd server")

          self.start_http_server(conf, env)

  

-         print "Installing third SP server"

+         print("Installing third SP server")

          name = 'sp3'

          addr = '127.0.0.13'

          port = '45083'
@@ -197,7 +199,7 @@ 

          conf = self.setup_sp_server(sp, name, addr, port, env)

          fixup_sp_httpd(os.path.dirname(conf))

  

-         print "Starting third SP's httpd server"

+         print("Starting third SP's httpd server")

          self.start_http_server(conf, env)

  

  
@@ -215,15 +217,15 @@ 

      sess.add_server(sp2name, 'https://127.0.0.12:45082')

      sess.add_server(sp3name, 'https://127.0.0.13:45083')

  

-     print "openidc: Authenticate to IDP ...",

+     print("openidc: Authenticate to IDP ...", end=' ')

      try:

          sess.auth_to_idp(idpname)

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openidc: Registering test client ...",

+     print("openidc: Registering test client ...", end=' ')

      try:

          client_info = {

              'redirect_uris': ['https://invalid/'],
@@ -238,12 +240,12 @@ 

                            json=client_info)

          r.raise_for_status()

          reg_resp = r.json()

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openidc: Registering test client with none auth ...",

+     print("openidc: Registering test client with none auth ...", end=' ')

      try:

          client_info = {

              'redirect_uris': ['https://invalid/'],
@@ -258,12 +260,12 @@ 

                            json=client_info)

          r.raise_for_status()

          reg_resp_none = r.json()

-     except Exception, e:  # pylint: disable=broad-except

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except Exception as e:  # pylint: disable=broad-except

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openidc: Access first SP Protected Area ...",

+     print("openidc: Access first SP Protected Area ...", end=' ')

      try:

          page = sess.fetch_page(idpname, 'https://127.0.0.11:45081/sp/',

                                 require_consent=True)
@@ -278,32 +280,33 @@ 

              'acr': '0'

          }

          old_token = check_info_results(page.text, expect)

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openidc: Log back in to first SP Protected Area without consent" \

-         " ...",

+     print("openidc: Log back in to first SP Protected Area without consent"

+           " ...", end=' ')

      try:

          page = sess.fetch_page(idpname,

                                 'https://127.0.0.11:45081/sp/redirect_uri?log'

                                 'out=https%3A%2F%2F127.0.0.11%3A45081%2Fsp%2F',

                                 require_consent=False)

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openidc: Revoking SP consent ...",

+     print("openidc: Revoking SP consent ...", end=' ')

      try:

          page = sess.revoke_all_consent(idpname)

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openidc: Log back in to first SP Protected Area with consent ...",

+     print("openidc: Log back in to first SP Protected Area with consent ...",

+           end=' ')

      try:

          page = sess.fetch_page(idpname,

                                 'https://127.0.0.11:45081/sp/redirect_uri?log'
@@ -320,23 +323,23 @@ 

              'acr': '0'

          }

          new_token = check_info_results(page.text, expect)

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openidc: Update first SP client name ...",

+     print("openidc: Update first SP client name ...", end=' ')

      try:

          sess.update_options(

              idpname,

              'providers/openidc/admin/client/%s' % reg_resp['client_id'],

              {'Client Name': 'Test suite client updated'})

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openidc: Retrieving token info ...",

+     print("openidc: Retrieving token info ...", end=' ')

      try:

          # Testing token without client auth

          r = requests.post('https://127.0.0.10:45080/idp1/openidc/TokenInfo',
@@ -413,12 +416,12 @@ 

                                  'client_secret': reg_resp['client_secret']})

          if r.status_code != 400:

              raise Exception('Deleted client accepted')

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openidc: Using none-authenticated client ...",

+     print("openidc: Using none-authenticated client ...", end=' ')

      try:

          # Test that none-authed clients don't have access to token info

          r = requests.post(
@@ -475,12 +478,12 @@ 

                    'client_secret': reg_resp_none['client_secret']})

          if r.status_code != 200:

              raise Exception('Authed client not accepted')

-     except ValueError, e:

-         print >> sys.stderr, " ERROR: %s" % repr(e)

+     except ValueError as e:

+         print(" ERROR: %s" % repr(e), file=sys.stderr)

          sys.exit(1)

-     print " SUCCESS"

+     print(" SUCCESS")

  

-     print "openidc: Checking user info ...",

+     print("openidc: Checking user info ...", end=' ')

      try:

          # Testing user info without token

          r = requests.post('https://127.0.0.10:45080/idp1/openidc/UserInfo')
@@ -500,12 +503,12 @@