fix perms checking
Signed-off-by: Tiago Garcia <tiago.rgarcia@ua.pt>
This commit is contained in:
parent
fab60873c8
commit
75ac6cd045
|
@ -43,19 +43,19 @@ def assumeRole(args):
|
|||
with open(BASE_DIR + args.session, 'r') as f:
|
||||
args.session = json.load(f)
|
||||
|
||||
# Get roles in session
|
||||
try:
|
||||
req = requests.get(f'http://{state['REP_ADDRESS']}/role/session/list', headers={'Authorization': args.session['token']})
|
||||
req.raise_for_status()
|
||||
except requests.exceptions.RequestException as errex:
|
||||
logger.error("Failed to obtain response from server.")
|
||||
sys.exit(-1)
|
||||
|
||||
# Validate role name
|
||||
roles = req.json()
|
||||
if args.role not in roles.items():
|
||||
logger.error("Role does not exist.")
|
||||
sys.exit(1)
|
||||
# # Get roles in session
|
||||
# try:
|
||||
# req = requests.get(f'http://{state['REP_ADDRESS']}/role/session/list', headers={'Authorization': args.session['token']})
|
||||
# req.raise_for_status()
|
||||
# except requests.exceptions.RequestException as errex:
|
||||
# logger.error("Failed to obtain response from server.")
|
||||
# sys.exit(-1)
|
||||
#
|
||||
# # Validate role name
|
||||
# roles = req.json()
|
||||
# if args.role not in roles.items():
|
||||
# logger.error("Role does not exist.")
|
||||
# sys.exit(1)
|
||||
|
||||
|
||||
# TODO:
|
||||
|
|
|
@ -45,6 +45,13 @@ def test_rep_create_session():
|
|||
assert process.returncode == 0
|
||||
|
||||
|
||||
def test_rep_assume_role():
|
||||
# Test the rep_assume_role command
|
||||
process = subprocess.Popen(f"{DELIVERY_PATH}/client/bin/rep_assume_role session.json manager", shell=True)
|
||||
process.wait()
|
||||
assert process.returncode == 0
|
||||
|
||||
|
||||
def test_rep_list_subjects():
|
||||
#Test the rep_list_subjects command
|
||||
process = subprocess.Popen(f"{DELIVERY_PATH}/client/bin/rep_list_subjects session.json", shell=True)
|
||||
|
|
|
@ -261,7 +261,9 @@ def role_session_assume(role):
|
|||
if not session:
|
||||
return jsonify({"error": "Not authenticated"}), 401
|
||||
|
||||
if not RoleService.get_role(session.org_id, role):
|
||||
org = OrganizationService.get_organization(session.org_id)
|
||||
|
||||
if not RoleService.get_role(org, role):
|
||||
return jsonify({"error": "Role not found"}), 404
|
||||
|
||||
session = SessionService.change_role(session, role, "add")
|
||||
|
@ -281,7 +283,9 @@ def role_session_drop(role):
|
|||
if not session:
|
||||
return jsonify({"error": "Not authenticated"}), 401
|
||||
|
||||
if not RoleService.get_role(session.org_id, role):
|
||||
org = OrganizationService.get_organization(session.org_id)
|
||||
|
||||
if not RoleService.get_role(org, role):
|
||||
return jsonify({"error": "Role not found"}), 404
|
||||
|
||||
session = SessionService.change_role(session, role, "drop")
|
||||
|
|
|
@ -47,6 +47,7 @@ class SessionService:
|
|||
session.verified = True
|
||||
db.commit()
|
||||
db.refresh(session)
|
||||
return session
|
||||
|
||||
@staticmethod
|
||||
def get_session(token: str) -> Session | None:
|
||||
|
@ -102,7 +103,7 @@ class SessionService:
|
|||
return jsonify({"error": f"Role {role} does not exist in organization {org.name}"}), 404
|
||||
|
||||
if operation == "add":
|
||||
if role not in user.roles[org.id]:
|
||||
if role not in user.roles[str(org.id)]:
|
||||
return jsonify({"error": f"User {user.username} does not have role {role}"}), 400
|
||||
|
||||
if role in session.roles:
|
||||
|
@ -110,7 +111,7 @@ class SessionService:
|
|||
|
||||
session.roles.append(role)
|
||||
elif operation == "drop":
|
||||
if role not in user.roles[org.id]:
|
||||
if role not in user.roles[str(org.id)]:
|
||||
return jsonify({"error": f"User {user.username} does not have role {role}"}), 400
|
||||
|
||||
if role not in session.roles:
|
||||
|
|
|
@ -44,8 +44,8 @@ class Perm(Enum):
|
|||
return perms.value if isinstance(perms, Perm) else 0
|
||||
|
||||
@staticmethod
|
||||
def check_perm(perm, bit_array: int):
|
||||
return perm.value & bit_array == perm.value
|
||||
def check_perm(perms_array: int, perm_to_check: int):
|
||||
return perms_array & perm_to_check == perm_to_check
|
||||
|
||||
class PermOperation(Enum):
|
||||
ADD = 0
|
||||
|
|
Loading…
Reference in New Issue