Skip to content

OAuth Token Handling Bug #40

@gh-ppolk

Description

@gh-ppolk

Describe the bug

You aren't handling Unauthorized Token Access properly. Your api raises a TypeError when it should be raising an UnauthorizedTokenException.

To Reproduce
Try to access the api with invalid credentials. A TypeError will occur.

Expected behavior
An UnauthorizedTokenException should be raised.

Screenshots
I am too lazy for screenshots.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Not Browser Related
  • Version: Version of what?

Additional context
The bug actually happens here.

headers['Authorization'] = 'Bearer ' + self.__token

core.py
headers['Authorization'] = 'Bearer ' + self.__token
https://github.com/jamasoftware-ps/py-jama-rest-client|jamasoftware-ps/py-jama-rest-clientjamasoftware-ps/py-jama-rest-client | Added by GitHub

because self.__token is defaulted to None here

core.py
self.__token = None
https://github.com/jamasoftware-ps/py-jama-rest-client|jamasoftware-ps/py-jama-rest-clientjamasoftware-ps/py-jama-rest-client | Added by GitHub

This requests.post will respond without raising a 400 because the request processed, it just processed and returned Unauthorized. But you don’t raise an exception.

response = requests.post(self.__token_host, auth=self.__credentials, data=data, verify=self.__verify)

core.py
response = requests.post(self.__token_host, auth=self.__credentials, data=data, verify=self.__verify)
https://github.com/jamasoftware-ps/py-jama-rest-client|jamasoftware-ps/py-jama-rest-clientjamasoftware-ps/py-jama-rest-client | Added by GitHub

And instead just log it

py_jama_rest_client_logger.error('Failed to retrieve OAuth Token')

core.py
py_jama_rest_client_logger.error('Failed to retrieve OAuth Token')
https://github.com/jamasoftware-ps/py-jama-rest-client|jamasoftware-ps/py-jama-rest-clientjamasoftware-ps/py-jama-rest-client | Added by GitHub

resulting in the method completing without updating the token

And allowing for the type error to occur.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions