commitcloud: strip whitespace from tokens

Summary:
If tokens are stored with whitespace around them, sending them as OAuth headers
may fail.  Make sure we strip them.

Reviewed By: mitrandir77

Differential Revision: D8160309

fbshipit-source-id: b403be6b11f25087ebc1ecdbe9a58b7f9dbda2f8
This commit is contained in:
Mark Thomas 2018-05-25 07:42:34 -07:00 committed by Facebook Github Bot
parent cfd7a429ae
commit b22cc19d0a

View File

@ -134,15 +134,22 @@ class TokenLocator(object):
"""
if pycompat.isdarwin and not self.ui.config(
'commitcloud', 'user_token_path'):
return self._gettokenosx()
token = self._gettokenosx()
else:
return self._gettokenfromfile()
token = self._gettokenfromfile()
# Ensure token doesn't have any extraneous whitespace around it.
if token is not None:
token = token.strip()
return token
def settoken(self, token):
"""Public API
set token
it can throw only in case of unexpected error
"""
# Ensure token doesn't have any extraneous whitespace around it.
if token is not None:
token = token.strip()
if pycompat.isdarwin and not self.ui.config(
'commitcloud', 'user_token_path'):
self._settokenosx(token)