File size: 2,310 Bytes
447ebeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# What is this?
## Unit tests for 'docker/entrypoint.sh'

import pytest
import sys
import os

sys.path.insert(
    0, os.path.abspath("../")
)  # Adds the parent directory to the system path
import litellm
import subprocess


@pytest.mark.skip(reason="local test")
def test_decrypt_and_reset_env():
    os.environ["DATABASE_URL"] = (
        "aws_kms/AQICAHgwddjZ9xjVaZ9CNCG8smFU6FiQvfdrjL12DIqi9vUAQwHwF6U7caMgHQa6tK+TzaoMAAAAzjCBywYJKoZIhvcNAQcGoIG9MIG6AgEAMIG0BgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDCmu+DVeKTm5tFZu6AIBEICBhnOFQYviL8JsciGk0bZsn9pfzeYWtNkVXEsl01AdgHBqT9UOZOI4ZC+T3wO/fXA7wdNF4o8ASPDbVZ34ZFdBs8xt4LKp9niufL30WYBkuuzz89ztly0jvE9pZ8L6BMw0ATTaMgIweVtVSDCeCzEb5PUPyxt4QayrlYHBGrNH5Aq/axFTe0La"
    )
    from litellm.secret_managers.aws_secret_manager import (
        decrypt_and_reset_env_var,
    )

    decrypt_and_reset_env_var()

    assert os.environ["DATABASE_URL"] is not None
    assert isinstance(os.environ["DATABASE_URL"], str)
    assert not os.environ["DATABASE_URL"].startswith("aws_kms/")

    print("DATABASE_URL={}".format(os.environ["DATABASE_URL"]))


@pytest.mark.skip(reason="local test")
def test_entrypoint_decrypt_and_reset():
    os.environ["DATABASE_URL"] = (
        "aws_kms/AQICAHgwddjZ9xjVaZ9CNCG8smFU6FiQvfdrjL12DIqi9vUAQwHwF6U7caMgHQa6tK+TzaoMAAAAzjCBywYJKoZIhvcNAQcGoIG9MIG6AgEAMIG0BgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDCmu+DVeKTm5tFZu6AIBEICBhnOFQYviL8JsciGk0bZsn9pfzeYWtNkVXEsl01AdgHBqT9UOZOI4ZC+T3wO/fXA7wdNF4o8ASPDbVZ34ZFdBs8xt4LKp9niufL30WYBkuuzz89ztly0jvE9pZ8L6BMw0ATTaMgIweVtVSDCeCzEb5PUPyxt4QayrlYHBGrNH5Aq/axFTe0La"
    )
    command = "./docker/entrypoint.sh"
    directory = ".."  # Relative to the current directory

    # Run the command using subprocess
    result = subprocess.run(
        command, shell=True, cwd=directory, capture_output=True, text=True
    )

    # Print the output for debugging purposes
    print("STDOUT:", result.stdout)
    print("STDERR:", result.stderr)

    # Assert the script ran successfully
    assert result.returncode == 0, "The shell script did not execute successfully"
    assert (
        "DECRYPTS VALUE" in result.stdout
    ), "Expected output not found in script output"
    assert (
        "Database push successful!" in result.stdout
    ), "Expected output not found in script output"

    assert False