Skip to content
CodeKruPro

auth().basic() versus auth().preemptive().basic()

QuizMedium-HardJava onlyAsked in: Accenture, Capgemini, Infosys

An API expects the Basic auth header on the first request and never sends a 401 challenge. A test using given().auth().basic("admin", "secret") gets 403. (A 401 challenge is an answer that asks the client for credentials.) What is the likely fix?

  • Use given().auth().preemptive().basic("admin", "secret") so the header is sent on the first request
  • Use auth().oauth2("admin")
  • Put the password in a query parameter
  • Basic auth cannot be automated in REST Assured

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in