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

Moved sector_identifier checks outside #321

Merged
merged 1 commit into from
Apr 21, 2017

Conversation

tpazderka
Copy link
Collaborator

Refactoring of oic.oic.provider.Provider.do_clinet_registration in order to decrease McCabe score.

  • Any changes relevant to users are recorded in the CHANGELOG.md.
  • The documentation has been updated, if necessary.

Copy link
Contributor

@decentral1se decentral1se left a comment

Choose a reason for hiding this comment

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

As always, thanks for working on this!

_cinfo["sector_id"] = si_url
_cinfo["si_redirects"], _cinfo["sector_id"] = self._verify_sector_identifier(request)
except InvalidSectorIdentifier as err:
return error_response("invalid_configuration_parameter",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suppose we can make this all on one line? Could be nitpicking ;)

pass
n_keys = len(self.keyjar.get(client_id, []))
if n_keys:
logger.debug("Found %s keys for client_id=%s", n_keys, client_id)
except Exception as err:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we be more specific than Exception for the self.keyjar.load_keys(request, client_id) failure when we catch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We should, I will look into this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mental note to myself: KeyIOError and UnknownKeyType are clearly visible as raised exceptions from called methods. Other could be possibly hidden.

try:
res = self.server.http_request(si_url)
except ConnectionError as err:
logger.error("{}", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can just be logger.error(err)?

logger.error("{}", err)
res = None

if not res:
Copy link
Contributor

Choose a reason for hiding this comment

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

This raise could be moved into the except block above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably not, if you look at the previous code, it was doing the same thing. This catches the case when the response doesn't raise an exception but returns None.

raise InvalidSectorIdentifier("Error deserializing sector_identifier_uri content")

if "redirect_uris" in request:
logger.debug("redirect_uris: %s". request["redirect_uris"])
Copy link
Contributor

Choose a reason for hiding this comment

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

What's that full stop doing!? Is this some new cool syntax that I didn't know about? 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Typos... typos everywhere...


if "redirect_uris" in request:
logger.debug("redirect_uris: %s". request["redirect_uris"])
for uri in request["redirect_uris"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be just my preference but I like to skip nested fors (feel free to ignore):

if not all([uri in request["redirect_uris"] for uri in si_redirects]):
    raise InvalidSectorIdentifier("redirect_uri missing from sector_identifiers")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I always find dict comprehension unreadable (personal thing) so I will gladly go with the ignore on this one :)

@tpazderka
Copy link
Collaborator Author

Thanks for the review, but I will probably work on this one a little bit anyways. Since the code I am refactoring is completely untested, I would like to add some test to be sure it is working properly.

I will address some of your comments in further commits :)

@decentral1se
Copy link
Contributor

I would like to add some test to be sure it is working properly

🍻 🌈 🍷 🏳️‍🌈 🍻

@tpazderka tpazderka self-assigned this Apr 4, 2017
@tpazderka tpazderka force-pushed the refactor-do-client-registration branch from ecd0808 to b251b08 Compare April 6, 2017 11:51
@tpazderka tpazderka changed the title [WIP] Moved sector_identifier checks outside Moved sector_identifier checks outside Apr 6, 2017
@tpazderka
Copy link
Collaborator Author

Tests for the method added. It is marked as internal since this is something that shouldn't be changed.

The score went down by 7 so some more work is needed...:)

@tpazderka
Copy link
Collaborator Author

@lwm, could you please have a look so we can merge this?

@tpazderka tpazderka merged commit cc4bff3 into master Apr 21, 2017
@tpazderka tpazderka deleted the refactor-do-client-registration branch April 21, 2017 13:18
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.

2 participants