Skip to content

ci: run tests of Python client in CI before deploying containers and packages

Marc-Olivier Andrez requested to merge run-python-tests-before-deploying into develop

The Python tests now run in the CI job test-services-linux-debug. These tests need a new token because using the token contained in standalone_token.txt was making the call consumer.get_stream_list() fail:

>>> consumer.get_stream_list()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "asapo_consumer.pyx", line 323, in asapo_consumer.PyConsumer.get_stream_list
  File "asapo_consumer.pyx", line 102, in asapo_consumer.throw_exception
asapo_consumer.AsapoWrongInputError: error: wrong input, message: authorizer rejected to authorize: wrong or expired JWT token, details: api:/v0.6/beamtime/asapo_test/source_20240611T_103617/0/streams, host:localhost:8413

See for example https://gitlab.desy.de/asapo/asapo/-/jobs/462815.

Instead, the tests use a new token contained in local_dev_token.txt that was generated using PyJWT 2.8.0:

import jwt

key = "12ljzgneasfd"
beamtimetext="asapo_test"
new_token=jwt.encode({
    "exp": 9571710216, #FIXME: will break on 25.04.2273
    "jti": "wtfisthis",
    "sub": "bt_"+beamtimetext,
    "ExtraClaims": {
        "AccessTypes": [
            "write",
            "writeraw",
            "read",
        ],
    },
}, key, algorithm="HS256")
print(new_token)  # This prints the value of the token to put into `local_dev_token.txt`

# Just to check that the token was correctly generated:
print(jwt.decode(new_token, key, algorithms=["HS256"]))
Edited by Marc-Olivier Andrez

Merge request reports

Loading