230_reg_bad_fail_stale_true.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import inc_sip as sip
  2. import inc_sdp as sdp
  3. # In this test we simulate broken server, where it always sends
  4. # stale=true with all 401 responses. We should expect pjsip to
  5. # retry the authentication until PJSIP_MAX_STALE_COUNT is
  6. # exceeded. When pjsip retries the authentication, it should
  7. # use the new nonce from server
  8. pjsua = "--null-audio --id=sip:CLIENT --registrar sip:127.0.0.1:$PORT " + \
  9. "--realm=python --user=username --password=password"
  10. req1 = sip.RecvfromTransaction("Initial request", 401,
  11. include=["REGISTER sip"],
  12. exclude=["Authorization"],
  13. resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"1\""]
  14. )
  15. req2 = sip.RecvfromTransaction("First retry", 401,
  16. include=["REGISTER sip", "Authorization", "nonce=\"1\""],
  17. exclude=["Authorization:[\\s\\S]+Authorization:"],
  18. resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"2\", stale=true"]
  19. )
  20. req3 = sip.RecvfromTransaction("Second retry retry", 401,
  21. include=["REGISTER sip", "Authorization", "nonce=\"2\""],
  22. exclude=["Authorization:[\\s\\S]+Authorization:"],
  23. resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"3\", stale=true"]
  24. )
  25. req4 = sip.RecvfromTransaction("Third retry", 401,
  26. include=["REGISTER sip", "Authorization", "nonce=\"3\""],
  27. exclude=["Authorization:[\\s\\S]+Authorization:"],
  28. resp_hdr=["WWW-Authenticate: Digest realm=\"python\", nonce=\"4\", stale=true"],
  29. expect="PJSIP_EAUTHSTALECOUNT"
  30. )
  31. recvfrom_cfg = sip.RecvfromCfg("Failed registration retry (server rejects with stale=true) ",
  32. pjsua, [req1, req2, req3, req4])