Bird
0
0

Given this simplified RBAC check in a microservice:

medium📝 Analysis Q13 of 15
Microservices - Authentication and Authorization
Given this simplified RBAC check in a microservice:
def can_access(user_role, action):
    permissions = {
        "user": ["read"],
        "admin": ["read", "write", "delete"]
    }
    return action in permissions.get(user_role, [])

print(can_access("user", "delete"))
What is the output?
ANone
BTrue
CKeyError
DFalse
Step-by-Step Solution
Solution:
  1. Step 1: Understand permissions dictionary

    The "user" role has only ["read"] permission, no "delete".
  2. Step 2: Check if "delete" is in user permissions

    Since "delete" is not in ["read"], the function returns False.
  3. Final Answer:

    False -> Option D
  4. Quick Check:

    "delete" in user permissions = False [OK]
Quick Trick: Check if action is in role's permission list [OK]
Common Mistakes:
MISTAKES
  • Assuming all actions allowed for user
  • Expecting KeyError for missing keys
  • Confusing True/False return values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes