|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Creates the standalone test users used by the Kosli CLI integration tests. |
| 4 | +# |
| 5 | +# This script is owned by the CLI repo (the test users are CLI test data). It is |
| 6 | +# mounted into the server container at /app/test via docker-compose and executed |
| 7 | +# there, so it relies on the server's `lib` and `model` packages being importable |
| 8 | +# via PYTHONPATH=/app/src. |
| 9 | + |
| 10 | +import hashlib |
| 11 | + |
| 12 | +from lib import Sku |
| 13 | +from model import Organizations, Users |
| 14 | + |
| 15 | +# key == person-id, value == api-key |
| 16 | +CLI_TEST_USERS = { |
| 17 | + "docs-cmd-test-user": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImNkNzg4OTg5In0.e8i_lA_QrEhFncb05Xw6E_tkCHU9QfcY4OLTVUCHffY", |
| 18 | + "acme-org": "v3OWZiYWu9G2IMQStYg9BcPQUQ88lJNNnTJTNq8jfvmkR1C5wVpHSs7F00JcB5i6OGeUzrKt3CwRq7ndcN4TTfMeo8ASVJ5NdHpZT7DkfRfiFvm8s7GbsIHh2PtiQJYs2UoN13T8DblV5C4oKb6-yWH73h67OhotPlKfVKazR-c", |
| 19 | + "iu-org": "qM9u2_grv6pJLbACwsMMMT5LIQy82tQj2k1zjZnlXti1smnFaGwCKW4jzk0La7ae9RrSYvEwCXSsXknD6YZqd-onLaaIUUKtEn6-B6yh53vWIe9EC5u85FCbKZjFbaicp_d0Me0Zcqq_KcCgrAZRX9xggl_pBb2oaCsNdllqNjk", |
| 20 | + "system-tests-user": "95-IeGBfyKdTteLdKidiAnXk6uMmV6jTkGM9v3DEtrQ", |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +def create_standalone_test_users(test_users): |
| 25 | + users = Users() |
| 26 | + orgs = Organizations() |
| 27 | + |
| 28 | + for user_name, api_key in test_users.items(): |
| 29 | + uid = hashlib.sha256(user_name.encode("utf-8")).hexdigest()[0:24] |
| 30 | + login_data = { |
| 31 | + "userId": uid, |
| 32 | + "name": user_name, |
| 33 | + "email": "default@example.com", |
| 34 | + "picture": "", |
| 35 | + } |
| 36 | + users.create("descope", login_data) |
| 37 | + user = users.find_by_auth_user_id(login_data["userId"]) |
| 38 | + user.completed_signup = True |
| 39 | + user.add_api_key(api_key=api_key, setting_user=user, expires_at=0, description="") |
| 40 | + # fixed auth_token so tests have a stable session token to authenticate with |
| 41 | + user.auth_token = "213c18081df7f738ec479107b86f97ec678b1d54" |
| 42 | + |
| 43 | + orgs.create_shared(f"{user_name}-shared", sku=Sku().existing_orgs, owner=user) |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + create_standalone_test_users(CLI_TEST_USERS) |
0 commit comments