Skip to content

Commit

Permalink
add more revoke tamplates and lints
Browse files Browse the repository at this point in the history
Signed-off-by: Far <[email protected]>
  • Loading branch information
alexstroke1 authored and Far committed Nov 18, 2024
1 parent 2e6564f commit 74e7b44
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 37 deletions.
4 changes: 3 additions & 1 deletion pytests/iroha_cli_tests/src/iroha_cli/have.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
6 changes: 4 additions & 2 deletions pytests/iroha_cli_tests/src/iroha_cli/iroha_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 5 additions & 4 deletions pytests/iroha_cli_tests/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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(
Expand Down
47 changes: 20 additions & 27 deletions pytests/iroha_cli_tests/test/permissions/test_grant_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,74 @@
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(
f'THEN the account "{GIVEN_registered_account}" should have the granted 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))
104 changes: 101 additions & 3 deletions pytests/iroha_cli_tests/test/permissions/test_revoke_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,120 @@
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'
f'from the "{GIVEN_registered_account_granted_with_CanSetParameters}"'
):
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())
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))

0 comments on commit 74e7b44

Please sign in to comment.