Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for None before decoding alt subject name #1606

Closed
wants to merge 1 commit into from

Conversation

daviddavis
Copy link

@daviddavis daviddavis commented Apr 25, 2017

Looks like when F25 upgraded from python-rhsm 1.19.0 to 1.19.4, our tests started failing:

rhsm.https: DEBUG: Using standard libs to provide httplib and ssl
rhsm.certificate2: ERROR: 'NoneType' object has no attribute 'decode'
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/rhsm/certificate2.py", line 99, in _read_x509
    return self._create_v1_cert(version, extensions, x509, path)
  File "/usr/lib64/python2.7/site-packages/rhsm/certificate2.py", line 114, in _create_v1_cert
    return self._create_identity_cert(version, extensions, x509, path)
  File "/usr/lib64/python2.7/site-packages/rhsm/certificate2.py", line 137, in _create_identity_cert
    alt_name=self._read_alt_name(x509),
  File "/usr/lib64/python2.7/site-packages/rhsm/certificate2.py", line 121, in _read_alt_name
    return x509.get_extension(name='subjectAltName').decode('utf-8')
AttributeError: 'NoneType' object has no attribute 'decode'

Looks like the following change was introduced in that timeframe:

candlepin/python-rhsm@f3164e3#diff-b89afd85b4d5ab2767749c609cab6374R118

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1445511

@candlepin-bot
Copy link

Can one of the admins verify this patch?

@awood
Copy link
Contributor

awood commented Apr 26, 2017

bot, okay to test ok to test

@@ -118,7 +118,8 @@ def _create_v1_cert(self, version, extensions, x509, path):
return self._create_v1_prod_cert(version, extensions, x509, path)

def _read_alt_name(self, x509):
return x509.get_extension(name='subjectAltName').decode('utf-8')
alt_name = x509.get_extension(name='subjectAltName')
return alt_name if alt_name is None else alt_name.decode('utf-8')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How un-pythonic... How about:

if alt_name is None:
    return None
else:
    return alt_name.decode('utf-8')

or similar?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @kahowell. I prefer to avoid Python's ersatz ternary operator.

@daviddavis
Copy link
Author

@kahowell @awood updated. thanks for the review.

@jirihnidek
Copy link
Contributor

Damn, I should read properly an remember what others do: #1608

@daviddavis
Copy link
Author

daviddavis commented Apr 27, 2017

@jirihnidek Your change looks better. I'll close this out.

@daviddavis daviddavis closed this Apr 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants