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 pull request hyperledger#1145 from anikitinDSR/public/indy-1963
[INDY-1963] Make auth error messages more cleanly
- Loading branch information
Showing
18 changed files
with
256 additions
and
29 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from indy_common.roles import Roles | ||
|
||
|
||
def get_named_role(role_code): | ||
try: | ||
return Roles.nameFromValue(role_code) | ||
except ValueError: | ||
return "Unknown role" |
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from indy_common.authorize.auth_constraints import AuthConstraint, AuthConstraintOr, AuthConstraintAnd | ||
from plenum.common.constants import TRUSTEE, STEWARD | ||
|
||
|
||
def test_str_not_any_7_sig_owner(): | ||
constraint = AuthConstraint(role=TRUSTEE, | ||
sig_count=7, | ||
need_to_be_owner=True) | ||
assert str(constraint) == '7 TRUSTEE signatures are required and needs to be owner' | ||
|
||
|
||
def test_str_not_any_7_sig_not_owner(): | ||
constraint = AuthConstraint(role=TRUSTEE, | ||
sig_count=7, | ||
need_to_be_owner=False) | ||
assert str(constraint) == '7 TRUSTEE signatures are required' | ||
|
||
|
||
def test_str_not_any_1_sig_not_owner(): | ||
constraint = AuthConstraint(role=TRUSTEE, | ||
sig_count=1, | ||
need_to_be_owner=False) | ||
assert str(constraint) == '1 TRUSTEE signature is required' | ||
|
||
|
||
def test_str_not_any_1_sig_owner(): | ||
constraint = AuthConstraint(role=TRUSTEE, | ||
sig_count=1, | ||
need_to_be_owner=True) | ||
assert str(constraint) == '1 TRUSTEE signature is required and needs to be owner' | ||
|
||
|
||
def test_str_any_1_sig_owner(): | ||
constraint = AuthConstraint(role="*", | ||
sig_count=1, | ||
need_to_be_owner=True) | ||
assert str(constraint) == '1 signature of any role is required and needs to be owner' | ||
|
||
|
||
def test_str_any_1_sig_not_owner(): | ||
constraint = AuthConstraint(role='*', | ||
sig_count=1, | ||
need_to_be_owner=False) | ||
assert str(constraint) == '1 signature of any role is required' | ||
|
||
|
||
def test_str_any_several_sig_not_owner(): | ||
constraint = AuthConstraint(role='*', | ||
sig_count=7, | ||
need_to_be_owner=False) | ||
assert str(constraint) == '7 signatures of any role are required' | ||
|
||
|
||
def test_str_any_several_sig_owner(): | ||
constraint = AuthConstraint(role='*', | ||
sig_count=7, | ||
need_to_be_owner=True) | ||
assert str(constraint) == '7 signatures of any role are required and needs to be owner' | ||
|
||
|
||
def test_str_for_auth_constraint_or(): | ||
constraint = AuthConstraintOr([AuthConstraint(role=TRUSTEE, | ||
sig_count=1, | ||
need_to_be_owner=True), | ||
AuthConstraint(role=STEWARD, | ||
sig_count=1, | ||
need_to_be_owner=True)]) | ||
assert str(constraint) == '1 TRUSTEE signature is required and needs to be owner ' \ | ||
'OR ' \ | ||
'1 STEWARD signature is required and needs to be owner' | ||
|
||
|
||
def test_str_for_auth_constraint_and(): | ||
constraint = AuthConstraintAnd([AuthConstraint(role=TRUSTEE, | ||
sig_count=1, | ||
need_to_be_owner=True), | ||
AuthConstraint(role=STEWARD, | ||
sig_count=1, | ||
need_to_be_owner=True)]) | ||
assert str(constraint) == '1 TRUSTEE signature is required and needs to be owner ' \ | ||
'AND ' \ | ||
'1 STEWARD signature is required and needs to be owner' |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from indy_common.authorize.helper import get_named_role | ||
from plenum.common.constants import TRUSTEE_STRING, TRUSTEE | ||
|
||
|
||
def test_for_known_role(): | ||
assert get_named_role(TRUSTEE) == TRUSTEE_STRING | ||
|
||
|
||
def test_for_unknown_role(): | ||
assert get_named_role("SomeOtherRole") == "Unknown role" |
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
Oops, something went wrong.