Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Anule la dependencia de JWTBearer Auth en FastAPI durante la prueba

Tengo problemas para intentar anular la validación de JWT desde mi etapa de prueba.

La validación funciona bien cuando llamo a los puntos finales de la API o cuando los llamo usando la interfaz de usuario de Swagger.

Todos mis puntos finales se declaran de la siguiente manera:

 @router.get("/some-path/{id}", response_model=SomeModel, dependencies=[Depends(JWTBearer())]) async def read_card_basic(*, db: Session = Depends(get_db), id: int): # do something

Y la clase JWTBearer tiene un método __call__ que realiza la validación:

 async def __call__(self, request: Request): credentials: HTTPAuthorizationCredentials = await super(JWTBearer, self).__call__(request) if credentials: if not credentials.scheme == "Bearer": raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Invalid authentication scheme.") if not self.verify_jwt(credentials.credentials): raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Invalid or expired token.") return credentials.credentials else: raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Invalid authorization code.")

Estoy usando Pytest y ya estoy anulando las dependencias en el archivo conftest.py de esta manera:

 def pytest_configure() -> None: """ Pytest will identify this function automatically and will run it before running any test """ initialize_testing_db() initialize_other_testing_db() create_data() create_other_data() app.dependency_overrides[get_db] = get_test_db app.dependency_overrides[get_other_db] = get_other_test_db

Traté de seguir los ejemplos en la documentación, pero no puedo encontrar una forma de eliminarlo, ya que obtenemos el token de un servicio externo y no lo necesitamos durante la prueba.

Cualquier ayuda sería apreciada y puedo agregar más información si es necesario.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!