def test_error_default():
    e = errors.AuthError()

    assert e.message == 'AuthError: None'
    assert e.code == 13
    assert e.data is None
    assert repr(e) == '[13] AuthError: None'
def test_error_custom():
    e = errors.AuthError('SSL AUTH', data={'cert': '/tmp/cert.pem'})

    assert e.message == 'AuthError: SSL AUTH'
    assert e.code == 13
    assert e.data == {'cert': '/tmp/cert.pem'}
    assert repr(e) == '[13] AuthError: SSL AUTH'
Beispiel #3
0
def session_setup(opts: Dict[Any, Any]) -> Any:  #TODO
    """
  Build the correct session object and login to a koji-hub server.

  Raises an `errors.BaseError` (subclasses) in case of unexpected problems.
  """
    stype = ''
    if 'serverca' in opts and 'cert' in opts:
        stype = 'ssl'
    s = session.get(stype, **opts)
    if s is None:
        raise errors.KojiError('Unable to idenify authentication type.')
    s.login()
    if not s.is_ok():
        raise errors.AuthError('Unable to validate session')
    return s
Beispiel #4
0
 def logout(self) -> None:
     """
 Destroys the current session.
 Raises an AuthError in case of failure.
 """
     if self.session is None:
         raise errors.KojiError(
             'Session was not initialized or is already terminated')
     try:
         self.session.logout()
     except koji.AuthError as e:
         raise errors.AuthError(str(e),
                                data={
                                    'ca_cert': self.opts['serverca'],
                                    'cert': self.opts['cert']
                                })
     self.session = None
Beispiel #5
0
 def login(self) -> None:
     """
 Authenticates to a koji-hub instance.
 Raises an AuthError in case of failure.
 """
     self.session = koji.ClientSession(self.opts['server'], self.opts)
     try:
         self.session.ssl_login(self.opts['cert'], None,
                                self.opts['serverca'])
     except requests.exceptions.RequestException as e:
         raise errors.KojiError(str(e))
     except koji.AuthError as e:
         raise errors.AuthError(str(e),
                                data={
                                    'ca_cert': self.opts['serverca'],
                                    'cert': self.opts['cert']
                                })