Skip to content

Commit

Permalink
Add condition to check for secret key and return correct uri
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Nov 13, 2019
1 parent f55f563 commit e0579d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ jobs:
TOXENV: py36-ethpm
# Please don't use this key for any shenanigans
WEB3_INFURA_PROJECT_ID: 7707850c2fb7465ebe6f150d67182e22
WEB3_INFURA_API_SECRET: 1955838f22ac4d858434f41498557130

py36-integration-goethereum-ipc-1.7.2:
<<: *geth_steps
Expand Down Expand Up @@ -290,7 +289,6 @@ jobs:
TOXENV: py37-ethpm
# Please don't use this key for any shenanigans
WEB3_INFURA_PROJECT_ID: 7707850c2fb7465ebe6f150d67182e22
WEB3_INFURA_API_SECRET: 1955838f22ac4d858434f41498557130

py37-integration-goethereum-ipc-1.7.2:
<<: *geth_steps
Expand Down Expand Up @@ -399,7 +397,6 @@ jobs:
TOXENV: py38-ethpm
# Please don't use this key for any shenanigans
WEB3_INFURA_PROJECT_ID: 7707850c2fb7465ebe6f150d67182e22
WEB3_INFURA_API_SECRET: 1955838f22ac4d858434f41498557130

py38-integration-goethereum-ipc-1.7.2:
<<: *geth_steps
Expand Down
11 changes: 11 additions & 0 deletions tests/core/providers/test_auto_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ def test_web3_auto_infura_websocket_with_secret(monkeypatch, caplog, environ_nam
assert getattr(w3.provider, 'endpoint_uri') == expected_url


def test_web3_auto_infura_websocket_without_secret(monkeypatch):
monkeypatch.setenv('WEB3_INFURA_PROJECT_ID', 'test')

importlib.reload(infura)

w3 = infura.w3
assert isinstance(w3.provider, WebsocketProvider)
expected_url = 'wss://%s/ws/v3/test' % (infura.INFURA_MAINNET_DOMAIN)
assert getattr(w3.provider, 'endpoint_uri') == expected_url


@pytest.mark.parametrize('environ_name', ['WEB3_INFURA_API_KEY', 'WEB3_INFURA_PROJECT_ID'])
def test_web3_auto_infura_with_secret(monkeypatch, caplog, environ_name):
monkeypatch.setenv('WEB3_INFURA_SCHEME', 'https')
Expand Down
4 changes: 3 additions & 1 deletion web3/auto/infura/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ def build_infura_url(domain):
key = load_api_key()
secret = load_secret()

if scheme == WEBSOCKET_SCHEME:
if scheme == WEBSOCKET_SCHEME and secret != '':
return "%s://:%s@%s/ws/v3/%s" % (scheme, secret, domain, key)
elif scheme == WEBSOCKET_SCHEME and secret == '':
return "%s://%s/ws/v3/%s" % (scheme, domain, key)
elif scheme == HTTP_SCHEME:
return "%s://%s/v3/%s" % (scheme, domain, key)
else:
Expand Down

0 comments on commit e0579d4

Please sign in to comment.