Skip to content

Commit

Permalink
fix: make Client(insecure=True) affect login & logout (#384)
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Léobal <[email protected]>
  • Loading branch information
oleobal authored Sep 6, 2023
1 parent 19e5476 commit b592a13
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- typo in exception ([#377](https://github.com/Substra/substra/pull/377))
- Client.login breaking when Client was instanciated with `insecure=True` ([#384](https://github.com/Substra/substra/pull/384))

## [0.46.0](https://github.com/Substra/substra/releases/tag/0.46.0) - 2023-07-25

Expand Down
7 changes: 5 additions & 2 deletions substra/sdk/backends/remote/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def login(self, username, password):
"password": password,
}
try:
r = requests.post(f"{self._base_url}/api-token-auth/", data=data, headers=headers)
r = requests.post(f"{self._base_url}/api-token-auth/", data=data, headers=headers, **self._default_kwargs)
r.raise_for_status()
except requests.exceptions.RequestException as e:
if isinstance(e, requests.exceptions.HTTPError):
Expand Down Expand Up @@ -110,7 +110,10 @@ def logout(self) -> None:
return
try:
r = requests.delete(
f"{self._base_url}/active-api-tokens/", params={"id": self._token["id"]}, headers=self._headers
f"{self._base_url}/active-api-tokens/",
params={"id": self._token["id"]},
headers=self._headers,
**self._default_kwargs,
)
r.raise_for_status()
self._token = None
Expand Down
19 changes: 19 additions & 0 deletions tests/sdk/test_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ def test_post_success(mocker, config):
assert len(m.call_args_list) == 1


@pytest.mark.parametrize("config", CONFIGS)
def test_verify_login(mocker, config):
"""
check "insecure" configuration results in endpoints being called with verify=False
"""
m_post = mock_requests(mocker, "post", response={"id": "a", "token": "a", "expires_at": "3000-01-01T00:00:00Z"})
m_delete = mock_requests(mocker, "delete", response={})

c = _client_from_config(config)
c.login("foo", "bar")
c.logout()
if config.get("insecure", None):
assert m_post.call_args.kwargs["verify"] == False
assert m_delete.call_args.kwargs["verify"] == False
else:
assert "verify" not in m_post.call_args.kwargs or m_post.call_args.kwargs["verify"]
assert "verify" not in m_post.call_args.kwargs or m_delete.call_args.kwargs["verify"]


@pytest.mark.parametrize(
"status_code, http_response, sdk_exception",
[
Expand Down

0 comments on commit b592a13

Please sign in to comment.