From fdfded7916fd5ee2dea8dfb0dd4ea92c49254070 Mon Sep 17 00:00:00 2001 From: Alex Jaramillo Date: Thu, 1 Nov 2018 10:33:28 -0700 Subject: [PATCH] Check http return code from license server This change verifies that the HTTP returning code from license server is a 200 otherwise any code returned by the server will be accepted as a successful response and the returned error page will be interpreted as a valid license hash. Additonally this change narrows the exception emitted by pycurl perform method from Exception to pycurl.error. Signed-off-by: Alex Jaramillo --- autospec/license.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/autospec/license.py b/autospec/license.py index ead17b6..25189c9 100644 --- a/autospec/license.py +++ b/autospec/license.py @@ -97,13 +97,17 @@ def license_from_copying_hash(copying, srcdir): c.setopt(c.FOLLOWLOCATION, 1) try: c.perform() - except Exception as excep: + code = c.getinfo(pycurl.HTTP_CODE) + if code != 200: + print_fatal("Fetching license from {} returned {}" + .format(config.license_fetch, code)) + exit(1) + except pycurl.error as excep: print_fatal("Failed to fetch license from {}: {}" .format(config.license_fetch, excep)) + exit(1) + finally: c.close() - sys.exit(1) - - c.close() response = buffer.getvalue() page = response.decode('utf-8').strip()