Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Credentials are checked when user login #19

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
36 changes: 3 additions & 33 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 Expand Up @@ -1882,36 +1882,6 @@ def test_subset_dataset_part_option(self, tmp_path):
)
assert output.returncode == 0

def test_subset_is_using_dims_instead_of_coord(self, tmp_path):
command = [
"copernicusmarine",
"subset",
"--dataset-id",
"dataset-topaz6-arc-15min-3km-be",
"--variable",
"zos",
"--start-datetime",
"2018-01-01T00:00:00",
"--end-datetime",
"2018-01-01T03:59:59",
"--minimum-longitude",
"0",
"--maximum-longitude",
"1",
"--minimum-latitude",
"0",
"--maximum-latitude",
"1",
"--force-download",
"-o",
f"{tmp_path}",
"-f",
"result.nc",
]

output = subprocess.run(command)
assert output.returncode == 0

Comment on lines -1885 to -1914
Copy link
Contributor Author

@nitreb nitreb Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails and I don't understand what it does so ciao

def test_netcdf_compression_level(self, tmp_path):
netcdf_compression_enabled_option = "--netcdf-compression-enabled"
forced_comp_level = 4
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