Kojira throw exception when auth failed

Fixes: https://pagure.io/koji/issue/2852
This commit is contained in:
Jana Cupova 2021-10-26 12:29:16 +02:00 committed by Yu Ming Zhu
parent 3fc4b4a64e
commit 2118a24e7a
2 changed files with 15 additions and 11 deletions

View file

@ -273,7 +273,7 @@ class Session(object):
if not isinstance(password, str) or len(password) == 0:
raise koji.AuthError('invalid username or password')
if self.logged_in:
raise koji.GenericError("Already logged in")
raise koji.AuthError("Already logged in")
hostip = self.get_remote_ip(override=opts.get('hostip'))
# check passwd

View file

@ -1317,16 +1317,20 @@ if __name__ == "__main__":
session_opts = koji.grab_session_options(options)
session = koji.ClientSession(options.server, session_opts)
if options.cert is not None and os.path.isfile(options.cert):
# authenticate using SSL client certificates
session.ssl_login(options.cert, None, options.serverca)
elif options.user:
# authenticate using user/password
session.login()
elif koji.reqgssapi and options.principal and options.keytab:
session.gssapi_login(options.principal, options.keytab, options.ccache)
else:
quit("No username/password/certificate supplied and Kerberos missing or not configured")
try:
if options.cert is not None and os.path.isfile(options.cert):
# authenticate using SSL client certificates
session.ssl_login(options.cert, None, options.serverca)
elif options.user:
# authenticate using user/password
session.login()
elif koji.reqgssapi and options.principal and options.keytab:
session.gssapi_login(options.principal, options.keytab, options.ccache)
else:
quit("No username/password/certificate supplied and Kerberos missing or "
"not configured")
except koji.AuthError as ex:
quit(str(ex))
# get an exclusive session
try:
session.exclusiveSession(force=options.force_lock)