From 74e7b44f02f6a0556ef28de474fd24f68daa7d20 Mon Sep 17 00:00:00 2001 From: alexstroke1 Date: Mon, 18 Nov 2024 08:29:03 +0100 Subject: [PATCH] add more revoke tamplates and lints Signed-off-by: Far --- pytests/iroha_cli_tests/src/iroha_cli/have.py | 4 +- .../src/iroha_cli/iroha_cli.py | 6 +- pytests/iroha_cli_tests/test/conftest.py | 9 +- .../permissions/test_grant_permissions.py | 47 ++++---- .../permissions/test_revoke_permissions.py | 104 +++++++++++++++++- 5 files changed, 133 insertions(+), 37 deletions(-) diff --git a/pytests/iroha_cli_tests/src/iroha_cli/have.py b/pytests/iroha_cli_tests/src/iroha_cli/have.py index b53c487bb65..c165a8b20c0 100644 --- a/pytests/iroha_cli_tests/src/iroha_cli/have.py +++ b/pytests/iroha_cli_tests/src/iroha_cli/have.py @@ -119,7 +119,9 @@ def check_quantity() -> bool: actual_quantity = None for asset_item in assets: if asset_item == expected_asset_id: - actual_quantity = assets.get(expected_asset_id, {}).get("value", {}).get("Numeric") + actual_quantity = ( + assets.get(expected_asset_id, {}).get("value", {}).get("Numeric") + ) break if actual_quantity is None: raise ValueError(f"Asset with ID {expected_asset_id} not found.") diff --git a/pytests/iroha_cli_tests/src/iroha_cli/iroha_cli.py b/pytests/iroha_cli_tests/src/iroha_cli/iroha_cli.py index bf7a8e7433a..903cd1567bb 100644 --- a/pytests/iroha_cli_tests/src/iroha_cli/iroha_cli.py +++ b/pytests/iroha_cli_tests/src/iroha_cli/iroha_cli.py @@ -287,7 +287,9 @@ def _read_and_update_json(self, template_filename, changes=None): # Traverse each path and update the value element = data[0] # Start from the root element for key in key_path[:-1]: - element = element[key] # Traverse through all keys except the last one + element = element[ + key + ] # Traverse through all keys except the last one element[key_path[-1]] = value # Set the new value at the final key json_temp_file_path = Path(ISI_PATH) / f"isi_{template_filename}" @@ -430,7 +432,7 @@ def _execute_pipe(self, cmd1, cmd2): stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=self.config.env, - text=True # Ensure that stdout and stderr are strings + text=True, # Ensure that stdout and stderr are strings ) as proc2, ): self.stdout, self.stderr = proc2.communicate() diff --git a/pytests/iroha_cli_tests/test/conftest.py b/pytests/iroha_cli_tests/test/conftest.py index a048486e803..b4650eea143 100644 --- a/pytests/iroha_cli_tests/test/conftest.py +++ b/pytests/iroha_cli_tests/test/conftest.py @@ -74,20 +74,21 @@ def GIVEN_registered_account(GIVEN_registered_domain, GIVEN_public_key): iroha_cli.register().account(signatory=account.signatory, domain=account.domain) return account + @pytest.fixture() def GIVEN_registered_account_granted_with_CanSetParameters( - GIVEN_registered_account, GIVEN_currently_authorized_account + GIVEN_registered_account, GIVEN_currently_authorized_account ): """Fixture to create an account granted with CanSetParameter.""" with allure.step( f'GIVEN "{GIVEN_registered_account}" granted with permission CanSetParameters' ): iroha_cli.grant_permission( - destination=GIVEN_registered_account, - permission='CanSetParameters' + destination=GIVEN_registered_account, permission="CanSetParameters" ) return GIVEN_registered_account + @pytest.fixture() def GIVEN_currently_authorized_account(): """Fixture to get the currently authorized account.""" @@ -231,7 +232,6 @@ def GIVEN_registered_asset_definition_with_store_type( return asset_def - # Fixtures for generating various types of data (strings, keys, names, etc.) @pytest.fixture() def GIVEN_fake_name(): @@ -287,6 +287,7 @@ def GIVEN_random_invalid_base64_character(): with allure.step(f'GIVEN a "{letter}" name'): return letter + # Fixtures for providing specific values or conditions (e.g., name length, string with spaces) @pytest.fixture() def GIVEN_key_with_invalid_character_in_key( diff --git a/pytests/iroha_cli_tests/test/permissions/test_grant_permissions.py b/pytests/iroha_cli_tests/test/permissions/test_grant_permissions.py index a73c44205d5..e0aad1c27ef 100644 --- a/pytests/iroha_cli_tests/test/permissions/test_grant_permissions.py +++ b/pytests/iroha_cli_tests/test/permissions/test_grant_permissions.py @@ -9,19 +9,16 @@ def story_account_unregisters_asset(): allure.dynamic.story("Account grant permission") + @allure.label("sdk_test_id", "grant_permission") @allure.label("permission", "no_permission_required") -def test_grant_permission( - GIVEN_registered_account, - GIVEN_currently_authorized_account -): +def test_grant_permission(GIVEN_registered_account, GIVEN_currently_authorized_account): with allure.step( f'WHEN "{GIVEN_currently_authorized_account}" grants ' f'the account "{GIVEN_registered_account}" with permission CanSetParameters' ): iroha_cli.grant_permission( - destination=GIVEN_registered_account, - permission='CanSetParameters' + destination=GIVEN_registered_account, permission="CanSetParameters" ) with allure.step( @@ -29,61 +26,57 @@ def test_grant_permission( ): assert iroha_cli.should(have.transaction_hash()) + @allure.label("sdk_test_id", "grant_not_permitted_permission") @allure.label("permission", "no_permission_required") def test_grant_not_permitted_permission( - GIVEN_registered_account, - GIVEN_currently_authorized_account + GIVEN_registered_account, GIVEN_currently_authorized_account ): - with ((allure.step( + with allure.step( f'WHEN "{GIVEN_currently_authorized_account}" grants ' f'the account "{GIVEN_registered_account}" with not permitted CanRegisterDomain permission' - ))): + ): iroha_cli.grant_permission( - destination=GIVEN_registered_account, - permission='CanRegisterDomain') + destination=GIVEN_registered_account, permission="CanRegisterDomain" + ) with allure.step( - f'THEN get an error Operation is not permitted: This operation is only allowed inside the genesis block' + f"THEN get an error Operation is not permitted: This operation is only allowed inside the genesis block" ): assert iroha_cli.should(have.error(Stderr.NOT_PERMITTED.value)) + @allure.label("sdk_test_id", "grant_invalid_permission") @allure.label("permission", "no_permission_required") def test_grant_invalid_permission( - GIVEN_registered_account, - GIVEN_currently_authorized_account + GIVEN_registered_account, GIVEN_currently_authorized_account ): with allure.step( f'WHEN "{GIVEN_currently_authorized_account}" attempts to grant ' f'an invalid permission NonExistentPermission to "{GIVEN_registered_account}"' ): iroha_cli.grant_permission( - destination=GIVEN_registered_account, - permission='NonExistentPermission' + destination=GIVEN_registered_account, permission="NonExistentPermission" ) - with allure.step( - 'THEN get an error stating that the permission is invalid' - ): + with allure.step("THEN get an error stating that the permission is invalid"): assert iroha_cli.should(have.error(Stderr.UNKNOWN_PERMISSION.value)) + @allure.label("sdk_test_id", "grant_permission_to_nonexistent_account") @allure.label("permission", "no_permission_required") -def test_grant_permission_to_nonexistent_account( - GIVEN_currently_authorized_account -): +def test_grant_permission_to_nonexistent_account(GIVEN_currently_authorized_account): with allure.step( f'WHEN "{GIVEN_currently_authorized_account}" attempts to grant ' - f'permission to non existent account' + f"permission to non existent account" ): iroha_cli.grant_permission( - destination='ed01200A303A7FBEDE8FC3D48F46681FF52D533F8B29E564412FA015A68D720C492777@wonderland', - permission='CanSetParameters' + destination="ed01200A303A7FBEDE8FC3D48F46681FF52D533F8B29E564412FA015A68D720C492777@wonderland", + permission="CanSetParameters", ) with allure.step( - 'THEN get an error stating that the destination account does not exist' + "THEN get an error stating that the destination account does not exist" ): assert iroha_cli.should(have.error(Stderr.FAILED_TO_FIND_ACCOUNT.value)) diff --git a/pytests/iroha_cli_tests/test/permissions/test_revoke_permissions.py b/pytests/iroha_cli_tests/test/permissions/test_revoke_permissions.py index 803ac4c071d..615b6fc6ee9 100644 --- a/pytests/iroha_cli_tests/test/permissions/test_revoke_permissions.py +++ b/pytests/iroha_cli_tests/test/permissions/test_revoke_permissions.py @@ -9,11 +9,13 @@ def story_account_unregisters_asset(): allure.dynamic.story("Account revoke permission") + @allure.label("sdk_test_id", "revoke_permission") @allure.label("permission", "no_permission_required") +@pytest.mark.xfail(reason="wait for #3036") def test_revoke_permission( GIVEN_registered_account_granted_with_CanSetParameters, - GIVEN_currently_authorized_account + GIVEN_currently_authorized_account, ): with allure.step( f'WHEN "{GIVEN_currently_authorized_account}" revokes CanSetParameters' @@ -21,10 +23,106 @@ def test_revoke_permission( ): iroha_cli.revoke_permission( destination=GIVEN_registered_account_granted_with_CanSetParameters, - permission='CanSetParameters' + permission="CanSetParameters", ) with allure.step( f'THEN the account "{GIVEN_registered_account_granted_with_CanSetParameters}" should be revoked' ): - assert iroha_cli.should(have.transaction_hash()) \ No newline at end of file + assert iroha_cli.should(have.transaction_hash()) + + +@allure.label("sdk_test_id", "revoke_permission_not_granted") +@allure.label("permission", "no_permission_required") +@pytest.mark.xfail(reason="wait for #3036") +def test_revoke_not_granted_permission( + GIVEN_registered_account, GIVEN_currently_authorized_account +): + with allure.step( + f'WHEN "{GIVEN_currently_authorized_account}" tries to revoke permission ' + f'CanSetParameters from "{GIVEN_registered_account}" which was not granted' + ): + iroha_cli.revoke_permission( + destination=GIVEN_registered_account, permission="CanSetParameters" + ) + + with allure.step(f"THEN the system should handle the operation appropriately"): + assert iroha_cli.should(have.transaction_hash()) + + +@allure.label("sdk_test_id", "revoke_permission_nonexistent_account") +@allure.label("permission", "no_permission_required") +@pytest.mark.xfail(reason="wait for #3036") +def test_revoke_permission_nonexistent_account(GIVEN_currently_authorized_account): + with allure.step( + f'WHEN "{GIVEN_currently_authorized_account}" tries to revoke permission ' + f"CanSetParameters from non-existent account nonexistent@domain" + ): + iroha_cli.revoke_permission( + destination="nonexistent@domain", permission="CanSetParameters" + ) + + with allure.step( + "THEN the system should return an error indicating the account does not exist" + ): + assert iroha_cli.should(have.error(Stderr.ACCOUNT_NOT_FOUND.value)) + + +@allure.label("sdk_test_id", "revoke_permission_without_rights") +@allure.label("permission", "no_permission_required") +@pytest.mark.xfail(reason="wait for #3036") +def test_revoke_permission_without_rights( + GIVEN_registered_account_granted_with_CanSetParameters, + GIVEN_account_without_revoke_rights, +): + with allure.step( + f'WHEN "{GIVEN_account_without_revoke_rights}" tries to revoke permission ' + f'CanSetParameters from "{GIVEN_registered_account_granted_with_CanSetParameters}"' + ): + iroha_cli.revoke_permission( + destination=GIVEN_registered_account_granted_with_CanSetParameters, + permission="CanSetParameters", + ) + + with allure.step( + "THEN the system should return an error indicating insufficient permissions" + ): + assert iroha_cli.should(have.error(Stderr.NOT_PERMITTED.value)) + + +@allure.label("sdk_test_id", "revoke_permission_from_self") +@allure.label("permission", "no_permission_required") +@pytest.mark.xfail(reason="wait for #3036") +def test_revoke_permission_from_self( + GIVEN_currently_authorized_account_granted_with_CanSetParameters, +): + with allure.step( + f'WHEN "{GIVEN_currently_authorized_account_granted_with_CanSetParameters}" tries to revoke ' + f"permission CanSetParameters from itself" + ): + iroha_cli.revoke_permission( + destination=GIVEN_currently_authorized_account_granted_with_CanSetParameters, + permission="CanSetParameters", + ) + + with allure.step( + "THEN the operation should be processed according to the system logic" + ): + assert iroha_cli.should(have.transaction_hash()) + + +@allure.label("sdk_test_id", "revoke_permission_invalid_data_format") +@allure.label("permission", "no_permission_required") +@pytest.mark.xfail(reason="wait for #3036") +def test_revoke_permission_invalid_data_format(GIVEN_registered_account): + with allure.step( + f'WHEN attempting to revoke permission with invalid data format from "{GIVEN_registered_account}"' + ): + iroha_cli.revoke_permission( + destination=GIVEN_registered_account, permission=12345 + ) + + with allure.step( + "THEN the system should return an error due to invalid data format" + ): + assert iroha_cli.should(have.error(Stderr.INVALID_INPUT.value))