Bird
0
0

Identify the error in this API key validation pseudocode:

medium📝 Analysis Q6 of 15
Microservices - Authentication and Authorization
Identify the error in this API key validation pseudocode:
function validateKey(request) {
  key = request.headers['Authorization']
  if (key = 'valid-key') {
    return 'Access granted'
  } else {
    return 'Access denied'
  }
}
ANo error, code is correct
BMissing return statement in else block
CIncorrect header name 'Authorization' used
DUsing assignment '=' instead of comparison '==' in if condition
Step-by-Step Solution
Solution:
  1. Step 1: Check if condition syntax

    The code uses '=' which assigns value instead of '==' to compare.
  2. Step 2: Understand impact of assignment in condition

    Assignment always evaluates to true, so 'Access granted' always returns.
  3. Final Answer:

    Using assignment '=' instead of comparison '==' in if condition -> Option D
  4. Quick Check:

    Use '==' for comparison, not '=' [OK]
Quick Trick: Use '==' to compare, '=' assigns [OK]
Common Mistakes:
MISTAKES
  • Confusing assignment with comparison
  • Ignoring syntax errors in conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes