Which statement best describes the difference between authorization and authentication?
Think about logging in first, then checking permissions.
Authentication confirms your identity, like entering a password. Authorization checks your rights to access resources after you are identified.
What will be the output of the following Python code simulating a simple authorization check?
user_role = 'editor' resource = 'article' permissions = { 'admin': ['article', 'comment', 'user'], 'editor': ['article', 'comment'], 'viewer': ['article'] } if resource in permissions.get(user_role, []): print('Access granted') else: print('Access denied')
Check if 'article' is in the list for 'editor' role.
The 'editor' role has permission for 'article', so the condition is true and 'Access granted' is printed.
Which assertion correctly tests that a user without 'admin' role cannot delete a user account?
def can_delete_user(user_role): return user_role == 'admin' user_role = 'viewer' result = can_delete_user(user_role)
The function returns True only for 'admin'. For 'viewer', it returns False.
The assertion must confirm the function returns False for a non-admin role, so 'assert result is False' is correct.
What is the bug in this JavaScript authorization check code?
function checkAccess(role) {
if (role == 'admin') {
return true;
} else {
return false;
}
}
console.log(checkAccess('viewer'));Check the condition inside the if statement carefully.
The code uses '=' which assigns 'admin' to role instead of comparing it. This causes the condition to always be true.
In an automated test framework, which approach best ensures authorization rules are tested effectively?
Think about covering different user roles and permissions efficiently.
Parameterized tests allow running the same test logic with different roles and resources, ensuring broad coverage of authorization rules.