forked from hyperledger/indy-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into extend-upgrade-command
- Loading branch information
Showing
11 changed files
with
317 additions
and
41 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
indy_client/test/cli/test_send_claim_def_permission_all.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import json | ||
import pytest | ||
|
||
from indy_common.auth import Authoriser | ||
from plenum.test.helper import sdk_sign_request_from_dict, sdk_send_and_check | ||
|
||
from indy_node.test.anon_creds.conftest import claim_def | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tconf(tconf): | ||
# We need to reset authorization map to set new authorization rules | ||
Authoriser.auth_map = None | ||
OLD_WRITES_REQUIRE_TRUST_ANCHOR = tconf.WRITES_REQUIRE_TRUST_ANCHOR | ||
tconf.WRITES_REQUIRE_TRUST_ANCHOR = False | ||
|
||
yield tconf | ||
|
||
tconf.WRITES_REQUIRE_TRUST_ANCHOR = OLD_WRITES_REQUIRE_TRUST_ANCHOR | ||
Authoriser.auth_map = None | ||
|
||
|
||
def test_client_can_send_claim_def(looper, | ||
txnPoolNodeSet, | ||
sdk_wallet_client, | ||
sdk_wallet_trust_anchor, | ||
sdk_pool_handle, | ||
claim_def, | ||
tconf): | ||
# Trust anchor can create claim_def in any case | ||
req = sdk_sign_request_from_dict(looper, sdk_wallet_trust_anchor, claim_def) | ||
sdk_send_and_check([json.dumps(req)], looper, txnPoolNodeSet, sdk_pool_handle) | ||
|
||
# Client can create claim_def if WRITES_REQUIRE_TRUST_ANCHOR flag set to False | ||
req = sdk_sign_request_from_dict(looper, sdk_wallet_client, claim_def) | ||
sdk_send_and_check([json.dumps(req)], looper, txnPoolNodeSet, sdk_pool_handle) |
39 changes: 39 additions & 0 deletions
39
indy_client/test/cli/test_send_claim_def_permission_no_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import json | ||
import pytest | ||
|
||
from indy_common.auth import Authoriser | ||
from plenum.common.exceptions import RequestRejectedException | ||
from plenum.test.helper import sdk_sign_request_from_dict, sdk_send_and_check, sdk_send_signed_requests, \ | ||
sdk_get_bad_response | ||
|
||
from indy_node.test.anon_creds.conftest import claim_def | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tconf(tconf): | ||
# We need to reset authorization map to set new authorization rules | ||
Authoriser.auth_map = None | ||
OLD_WRITES_REQUIRE_TRUST_ANCHOR = tconf.WRITES_REQUIRE_TRUST_ANCHOR | ||
tconf.WRITES_REQUIRE_TRUST_ANCHOR = True | ||
|
||
yield tconf | ||
|
||
tconf.WRITES_REQUIRE_TRUST_ANCHOR = OLD_WRITES_REQUIRE_TRUST_ANCHOR | ||
Authoriser.auth_map = None | ||
|
||
|
||
def test_client_cant_send_claim_def(looper, | ||
txnPoolNodeSet, | ||
sdk_wallet_client, | ||
sdk_wallet_trust_anchor, | ||
sdk_pool_handle, | ||
claim_def, | ||
tconf): | ||
# Trust anchor can create claim_def in any case | ||
req = sdk_sign_request_from_dict(looper, sdk_wallet_trust_anchor, claim_def) | ||
sdk_send_and_check([json.dumps(req)], looper, txnPoolNodeSet, sdk_pool_handle) | ||
|
||
# Client cant send create if WRITES_REQUIRE_TRUST_ANCHOR flag set to True | ||
req = sdk_sign_request_from_dict(looper, sdk_wallet_client, claim_def) | ||
req = sdk_send_signed_requests(sdk_pool_handle, [json.dumps(req)]) | ||
sdk_get_bad_response(looper, req, RequestRejectedException, 'None role cannot add claim def') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import json | ||
|
||
import pytest | ||
from indy.anoncreds import issuer_create_schema | ||
from indy.ledger import build_schema_request | ||
|
||
from indy_common.auth import Authoriser | ||
from plenum.test.helper import sdk_get_and_check_replies, sdk_sign_and_submit_req | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tconf(tconf): | ||
# We need to reset authorization map to set new authorization rules | ||
Authoriser.auth_map = None | ||
OLD_WRITES_REQUIRE_TRUST_ANCHOR = tconf.WRITES_REQUIRE_TRUST_ANCHOR | ||
tconf.WRITES_REQUIRE_TRUST_ANCHOR = False | ||
|
||
yield tconf | ||
|
||
tconf.WRITES_REQUIRE_TRUST_ANCHOR = OLD_WRITES_REQUIRE_TRUST_ANCHOR | ||
Authoriser.auth_map = None | ||
|
||
|
||
def test_client_can_send_schema(looper, | ||
txnPoolNodeSet, | ||
sdk_wallet_client, | ||
sdk_wallet_trust_anchor, | ||
sdk_pool_handle, | ||
tconf): | ||
# Trust anchor can create schema in any case | ||
_, identifier = sdk_wallet_trust_anchor | ||
_, schema_json = looper.loop.run_until_complete( | ||
issuer_create_schema(identifier, "name", "1.0", json.dumps(["first", "last"]))) | ||
request = looper.loop.run_until_complete(build_schema_request(identifier, schema_json)) | ||
sdk_get_and_check_replies(looper, [sdk_sign_and_submit_req(sdk_pool_handle, sdk_wallet_trust_anchor, request)]) | ||
|
||
# Client can create schema if WRITES_REQUIRE_TRUST_ANCHOR flag set to False | ||
_, identifier = sdk_wallet_client | ||
_, schema_json = looper.loop.run_until_complete( | ||
issuer_create_schema(identifier, "name", "1.0", json.dumps(["first", "last"]))) | ||
request = looper.loop.run_until_complete(build_schema_request(identifier, schema_json)) | ||
sdk_get_and_check_replies(looper, [sdk_sign_and_submit_req(sdk_pool_handle, sdk_wallet_client, request)]) |
45 changes: 45 additions & 0 deletions
45
indy_client/test/cli/test_send_schema_permission_no_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import json | ||
|
||
import pytest | ||
from indy.anoncreds import issuer_create_schema | ||
from indy.ledger import build_schema_request | ||
|
||
from indy_common.auth import Authoriser | ||
from plenum.common.exceptions import RequestRejectedException | ||
|
||
from plenum.test.helper import sdk_get_bad_response, sdk_sign_and_submit_req, sdk_get_and_check_replies | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tconf(tconf): | ||
# We need to reset authorization map to set new authorization rules | ||
Authoriser.auth_map = None | ||
OLD_WRITES_REQUIRE_TRUST_ANCHOR = tconf.WRITES_REQUIRE_TRUST_ANCHOR | ||
tconf.WRITES_REQUIRE_TRUST_ANCHOR = True | ||
|
||
yield tconf | ||
|
||
tconf.WRITES_REQUIRE_TRUST_ANCHOR = OLD_WRITES_REQUIRE_TRUST_ANCHOR | ||
Authoriser.auth_map = None | ||
|
||
|
||
def test_client_cant_send_schema(looper, | ||
txnPoolNodeSet, | ||
sdk_wallet_client, | ||
sdk_wallet_trust_anchor, | ||
sdk_pool_handle, | ||
tconf): | ||
# Trust anchor can create schema in any case | ||
_, identifier = sdk_wallet_trust_anchor | ||
_, schema_json = looper.loop.run_until_complete( | ||
issuer_create_schema(identifier, "another_name", "2.0", json.dumps(["first", "last"]))) | ||
request = looper.loop.run_until_complete(build_schema_request(identifier, schema_json)) | ||
sdk_get_and_check_replies(looper, [sdk_sign_and_submit_req(sdk_pool_handle, sdk_wallet_trust_anchor, request)]) | ||
|
||
# Client cant create schema if WRITES_REQUIRE_TRUST_ANCHOR flag set to True | ||
_, identifier = sdk_wallet_client | ||
_, schema_json = looper.loop.run_until_complete( | ||
issuer_create_schema(identifier, "another_name", "2.0", json.dumps(["first", "last"]))) | ||
request = looper.loop.run_until_complete(build_schema_request(identifier, schema_json)) | ||
sdk_get_bad_response(looper, [sdk_sign_and_submit_req(sdk_pool_handle, sdk_wallet_client, request)], | ||
RequestRejectedException, 'None role cannot add schema') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,37 @@ | ||
from plenum.common.constants import TRUSTEE, STEWARD | ||
|
||
from indy_common.auth import Authoriser | ||
from indy_common.auth import Authoriser, generate_auth_map | ||
from indy_common.constants import NAME, TGB, TRUST_ANCHOR, SCHEMA | ||
|
||
|
||
def test_schema_adding(): | ||
def test_schema_adding(initialized_auth_map): | ||
roles = {TRUSTEE, STEWARD, TRUST_ANCHOR} | ||
for role in roles: | ||
r, msg = _authorised_for_schemas(role) | ||
assert r and not msg | ||
|
||
|
||
def test_schema_adding_without_permission(): | ||
def test_schema_adding_without_permission(initialized_auth_map): | ||
roles = {TGB, None} | ||
for role in roles: | ||
r, msg = _authorised_for_schemas(role) | ||
assert not r and msg | ||
|
||
|
||
def test_client_can_send_claim_def(): | ||
Authoriser.auth_map = generate_auth_map(Authoriser.ValidRoles, False) | ||
|
||
r, msg = _authorised_for_schemas(None) | ||
assert r and not msg | ||
|
||
|
||
def test_client_cant_send_claim_def(): | ||
Authoriser.auth_map = generate_auth_map(Authoriser.ValidRoles, True) | ||
|
||
r, msg = _authorised_for_schemas(None) | ||
assert not r and "None role not in allowed roles" in msg | ||
|
||
|
||
def _authorised_for_schemas(role): | ||
return Authoriser.authorised(typ=SCHEMA, | ||
actorRole=role) |
Oops, something went wrong.