Bird
0
0

Given this pseudocode for API key validation:

medium📝 Analysis Q13 of 15
Microservices - Authentication and Authorization
Given this pseudocode for API key validation:
function validateKey(request) {
  key = request.headers['API-Key']
  if key is null or key not in validKeys:
    return 'Access Denied'
  else:
    return 'Access Granted'
}
What will be the output if the request has no 'API-Key' header?
AAccess Denied
BError: Missing header
CAccess Granted
DAccess Pending
Step-by-Step Solution
Solution:
  1. Step 1: Check header presence condition

    The code checks if the key is null or not in validKeys. If the header is missing, key is null.
  2. Step 2: Determine the return value for missing key

    Since key is null, the condition is true, so the function returns 'Access Denied'.
  3. Final Answer:

    Access Denied -> Option A
  4. Quick Check:

    Missing key = Access Denied [OK]
Quick Trick: No API-Key header means deny access [OK]
Common Mistakes:
MISTAKES
  • Assuming missing key grants access
  • Expecting an error instead of denial
  • Confusing 'null' with empty string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes