Skip to content

Commit

Permalink
fix: Credentials are checked when user login
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertin committed Apr 2, 2024
1 parent 78249c5 commit d582037
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
10 changes: 1 addition & 9 deletions copernicusmarine/core_functions/credentials_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,8 @@ def _check_credentials_with_cas(username: str, password: str) -> bool:
logger.debug(f"POSTing credentials to {cmems_cas_login_url}...")
login_response = conn_session.post(cmems_cas_login_url, data=playload)
login_success = 'class="success"' in login_response.text

if login_success:
get_profile_url = (
login_response.history[-1]
.headers["Location"]
.replace("login?", f"serviceValidate?service={service}&")
)
logger.debug(f"Getting profile to {get_profile_url}...")
logger.debug("User credentials checked")
return True
return login_success


@cachier(stale_after=timedelta(hours=48), cache_dir=CACHE_BASE_DIRECTORY)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_command_line_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def test_subset_output_file_as_netcdf(self, tmp_path):
assert output.returncode == 0
assert is_file

def test_process_is_not_stopped_when_credentials_are_invalid(self):
def test_process_is_stopped_when_credentials_are_invalid(self):
dataset_id = "cmems_mod_ibi_phy_my_0.083deg-3D_P1Y-m"

command = [
Expand All @@ -786,8 +786,8 @@ def test_process_is_not_stopped_when_credentials_are_invalid(self):

output = subprocess.run(command, capture_output=True)

assert output.returncode == 0
assert b"Invalid username or password" not in output.stdout
assert output.returncode == 1
assert b"Invalid username or password" in output.stdout

def test_login_is_prompt_when_configuration_file_doest_not_exist(
self, tmp_path
Expand Down
6 changes: 3 additions & 3 deletions tests/test_python_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_login_ok(self, tmp_path):
)
assert is_valid_with_skip is True

def test_login_ok_with_wrong_credentials(self, tmp_path):
def test_login_not_ok_with_wrong_credentials(self, tmp_path):
non_existing_directory = Path(tmp_path, "i_dont_exist")
is_valid = login(
username=os.getenv("COPERNICUS_MARINE_SERVICE_USERNAME"),
Expand All @@ -112,8 +112,8 @@ def test_login_ok_with_wrong_credentials(self, tmp_path):
overwrite_configuration_file=True,
)

assert is_valid is True
assert non_existing_directory.is_dir() is True
assert is_valid is False
assert non_existing_directory.is_dir() is False

def test_signature_inspection_is_working(self):
assert inspect.signature(describe).parameters[
Expand Down

0 comments on commit d582037

Please sign in to comment.