Bird
0
0

Consider this RBAC microservice snippet:

medium📝 Analysis Q5 of 15
Microservices - Authentication and Authorization
Consider this RBAC microservice snippet:
role_permissions = {"editor": ["edit", "publish"], "viewer": ["view"]}
user_roles = ["viewer", "editor"]
print(any("publish" in role_permissions.get(role, []) for role in user_roles))

What will be printed?
ATrue
BFalse
CError: any() not defined
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Check roles and permissions

    User has roles 'viewer' and 'editor'; 'editor' has 'publish' permission.
  2. Step 2: Evaluate any() expression

    Since 'publish' is in 'editor' permissions, any() returns True.
  3. Final Answer:

    True -> Option A
  4. Quick Check:

    any() finds permission = True [OK]
Quick Trick: any() returns True if any role has the permission [OK]
Common Mistakes:
MISTAKES
  • Ignoring multiple roles
  • Assuming 'viewer' has 'publish' permission
  • Misunderstanding any() function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes