Skip to content

Flaky tests in openedx/core/lib/tests/test_jwt.py tests with jwt.exceptions.ExpiredSignatureError #38450

@robrap

Description

@robrap

There are some flaky tests related to our JWTs (i.e. passed on re-run) in edx-platform.

  • Here's a link the failing log.
  • Because this is JWT related, I'm hesitant to follow the ~/Flaky+Test+Process and remove these until they are fixed. So, for now this ticket is for fixing the issue.
  • There is no guarantee that the code itself isn't flaky, and not the test. But typically that is not the case.
  • This was seen at least 3 times. Once above, and @wgu-taylor-payne mentioned seeing it a couple of times.

Other notes:

  • Does test order matter, and is order random or fixed in CI right now?

Here is the list of failures:

FAILED openedx/core/lib/tests/test_jwt.py::TestSign::test_create_jwt - jwt.exceptions.ExpiredSignatureError: Signature has expired
FAILED openedx/core/lib/tests/test_jwt.py::TestSign::test_create_jwt_with_claims - jwt.exceptions.ExpiredSignatureError: Signature has expired
FAILED openedx/core/lib/tests/test_jwt.py::TestUnpack::test_missing_expired_lms_user_id - jwt.exceptions.ExpiredSignatureError: Signature has expired
FAILED openedx/core/lib/tests/test_jwt.py::TestUnpack::test_unpack_jwt - jwt.exceptions.ExpiredSignatureError: Signature has expired
FAILED openedx/core/lib/tests/test_jwt.py::TestUnpack::test_unpack_jwt_with_claims - jwt.exceptions.ExpiredSignatureError: Signature has expired
FAILED openedx/core/lib/tests/test_jwt.py::TestUnpack::test_unpack_token_with_invalid_user - jwt.exceptions.ExpiredSignatureError: Signature has expired

Here is an example failure:

___________________________ TestSign.test_create_jwt ___________________________

self = <openedx.core.lib.tests.test_jwt.TestSign testMethod=test_create_jwt>

    def test_create_jwt(self):
        token = create_jwt(test_user_id, test_timeout, {}, test_now)
    
>       decoded = unpack_and_verify(token)

openedx/core/lib/tests/test_jwt.py:35: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
openedx/core/lib/jwt.py:89: in unpack_and_verify
    decoded = jwt.decode(
/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/jwt/api_jwt.py:365: in decode
    decoded = self.decode_complete(
/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/jwt/api_jwt.py:272: in decode_complete
    self._validate_claims(
/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/jwt/api_jwt.py:405: in _validate_claims
    self._validate_exp(payload, now, leeway)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <jwt.api_jwt.PyJWT object at 0x7f9ec75c7440>
payload = {'exp': 1776957758, 'iat': 1776956758, 'iss': 'token-test-issuer', 'lms_user_id': 121, ...}
now = 1776957784.86637, leeway = 0

    def _validate_exp(
        self,
        payload: dict[str, Any],
        now: float,
        leeway: float,
    ) -> None:
        try:
            exp = int(payload["exp"])
        except ValueError:
            raise DecodeError(
                "Expiration Time claim (exp) must be an integer."
            ) from None
    
        if exp <= (now - leeway):
>           raise ExpiredSignatureError("Signature has expired")
E           jwt.exceptions.ExpiredSignatureError: Signature has expired

/opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/jwt/api_jwt.py:508: ExpiredSignatureError

Metadata

Metadata

Assignees

No one assigned

    Labels

    flaky-testDetails a test removed as part of the flaky test processhelp wantedReady to be picked up by anyone in the community

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions