Skip to content

Commit

Permalink
Fix handling invalid SSL certificate (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hubert Jaworski authored Jul 23, 2019
1 parent 89fe915 commit 9cff63e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion neptune/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def __init__(self, api_address, api_token, proxies=None):
)

self.authenticator = NeptuneAuthenticator(
self.backend_swagger_client.api.exchangeApiToken(X_Neptune_Api_Token=api_token).response().result
self.backend_swagger_client.api.exchangeApiToken(X_Neptune_Api_Token=api_token).response().result,
ssl_verify
)
self._http_client.authenticator = self.authenticator

Expand Down
19 changes: 10 additions & 9 deletions neptune/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

import time

import jwt
Expand Down Expand Up @@ -57,7 +56,7 @@ def _refresh_token(self):

class NeptuneAuthenticator(Authenticator):

def __init__(self, auth_tokens):
def __init__(self, auth_tokens, ssl_verify):
super(NeptuneAuthenticator, self).__init__(host='')
decoded_json_token = jwt.decode(auth_tokens.accessToken, verify=False)
expires_at = decoded_json_token.get(u'exp')
Expand All @@ -68,13 +67,15 @@ def __init__(self, auth_tokens):
u'refresh_token': auth_tokens.refreshToken,
u'expires_in': expires_at - time.time()
}
self.auth = NeptuneAuth(
OAuth2Session(
client_id=client_name,
token=token,
auto_refresh_url=refresh_url,
auto_refresh_kwargs={'client_id': client_name},
token_updater=_no_token_updater))
session = OAuth2Session(
client_id=client_name,
token=token,
auto_refresh_url=refresh_url,
auto_refresh_kwargs={'client_id': client_name},
token_updater=_no_token_updater
)
session.verify = ssl_verify
self.auth = NeptuneAuth(session)

def matches(self, url):
return True
Expand Down
2 changes: 1 addition & 1 deletion tests/neptune/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_apply_oauth2_session_to_request(self, time_mock, session_mock):
session.token = dict()

# and
neptune_authenticator = NeptuneAuthenticator(auth_tokens)
neptune_authenticator = NeptuneAuthenticator(auth_tokens, False)
request = a_request()

# when
Expand Down

0 comments on commit 9cff63e

Please sign in to comment.