Skip to content

Commit

Permalink
fix: updater pipeline - raise error if update type is not correct
Browse files Browse the repository at this point in the history
  • Loading branch information
renatav committed Dec 5, 2023
1 parent e8312b0 commit f1f324c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
10 changes: 4 additions & 6 deletions taf/tests/test_updater/test_repo_update/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,26 +385,24 @@ def test_older_last_validated_commit(updater_repositories, origin_dir, client_di
_update_and_check_commit_shas(client_repos, repositories, origin_dir, client_dir)


# TODO
def test_update_test_repo_no_flag(updater_repositories, origin_dir, client_dir):
repositories = updater_repositories["test-updater-test-repo"]
origin_dir = origin_dir / "test-updater-test-repo"
# try to update a test repo, set update type to official
_update_invalid_repos_and_check_if_repos_exist(
client_dir, repositories, IS_A_TEST_REPO, UpdateType.OFFICIAL
client_dir, repositories, IS_A_TEST_REPO, False, UpdateType.OFFICIAL
)


# TODO
def test_update_repo_wrong_flag(updater_repositories, origin_dir, client_dir):
repositories = updater_repositories["test-updater-valid"]
origin_dir = origin_dir / "test-updater-valid"
# try to update without setting the last validated commit
_update_invalid_repos_and_check_if_repos_exist(
client_dir, repositories, NOT_A_TEST_REPO, UpdateType.TEST
client_dir, repositories, NOT_A_TEST_REPO, False, UpdateType.TEST
)

# TODO

def test_update_repo_target_in_indeterminate_state(
updater_repositories, origin_dir, client_dir
):
Expand All @@ -424,7 +422,7 @@ def test_update_repo_target_in_indeterminate_state(
index_lock.touch()

_update_invalid_repos_and_check_if_repos_exist(
client_dir, repositories, UNCOMMITTED_TARGET_CHANGES, True
client_dir, repositories, INDEX_LOCKED, True
)


Expand Down
56 changes: 25 additions & 31 deletions taf/updater/updater_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,41 +212,35 @@ def clone_remote_and_run_tuf_updater(self):

@log_on_start(INFO, "Validating out of band commit and update type", logger=taf_logger)
def _validate_out_of_band_and_update_type(self):
try:
# this is the repository cloned inside the temp directory
# we validate it before updating the actual authentication repository
if (
self.out_of_band_authentication is not None
and self.state.users_auth_repo.last_validated_commit is None
and self.state.auth_commits_since_last_validated[0] != self.out_of_band_authentication
# this is the repository cloned inside the temp directory
# we validate it before updating the actual authentication repository
if (
self.out_of_band_authentication is not None
and self.state.users_auth_repo.last_validated_commit is None
and self.state.auth_commits_since_last_validated[0] != self.out_of_band_authentication
):
raise UpdateFailedError(
f"First commit of repository {self.state.auth_repo_name} does not match "
"out of band authentication commit"
)

if self.expected_repo_type != UpdateType.EITHER:
# check if the repository being updated is a test repository
if self.state.validation_auth_repo.is_test_repo and self.expected_repo_type != UpdateType.TEST:
raise UpdateFailedError(
f"Repository {self.state.users_auth_repo.name} is a test repository. "
'Call update with "--expected-repo-type" test to update a test '
"repository"
)
elif (
not self.state.validation_auth_repo.is_test_repo
and self.expected_repo_type == UpdateType.TEST
):
raise UpdateFailedError(
f"First commit of repository {self.state.auth_repo_name} does not match "
"out of band authentication commit"
f"Repository {self.state.users_auth_repo.name} is not a test repository,"
' but update was called with the "--expected-repo-type" test'
)

if self.expected_repo_type != UpdateType.EITHER:
# check if the repository being updated is a test repository
if self.state.validation_auth_repo.is_test_repo and self.expected_repo_type != UpdateType.TEST:
raise UpdateFailedError(
f"Repository {self.state.users_auth_repo.name} is a test repository. "
'Call update with "--expected-repo-type" test to update a test '
"repository"
)
elif (
not self.state.validation_auth_repo.is_test_repo
and self.expected_repo_type == UpdateType.TEST
):
raise UpdateFailedError(
f"Repository {self.state.users_auth_repo.name} is not a test repository,"
' but update was called with the "--expected-repo-type" test'
)
return UpdateStatus.SUCCESS
except Exception as e:
self.state.error = e
self.state.event = Event.FAILED
taf_logger.error(e)
return UpdateStatus.FAILED

@log_on_start(INFO, "Cloning or updating user's authentication repository...", logger=taf_logger)
def clone_or_fetch_users_auth_repo(self):
Expand Down

0 comments on commit f1f324c

Please sign in to comment.