litellm/tests/unit/secret_managers/test_aws_secret_manager.py
paveln83 7bd342d7ea
fix(proxy): let a config license unlock enterprise settings and spell "environment" right in license errors (#49745)
* fix(proxy): spell "environment" right in the allowed_ips and AWS KMS V2 license errors

* fix(proxy): read general_settings.litellm_license before the allowed_ips and enforced_params gates

* fix(proxy): read the config license before callbacks and gates, keeping a valid env license

* fix(proxy): keep an invalid config license reported and sync license data with the license in use

A config license that fails no longer overwrites the license string when the env license is not valid either, so /health/license still reports has_license. A failed boot-time env license is not re-checked. Both license writes go through one helper that also refreshes premium_user_data, so /health/license and the seat limits follow the license in use.

* fix(proxy): keep the env license's boot result when a config license fails, without a second license check

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-03 09:56:08 +00:00

50 lines
2.1 KiB
Python

import base64
import re
from typing import Final
import pytest
from botocore.stub import Stubber
from litellm.secret_managers.aws_secret_manager import AWSKeyManagementService_V2
_CIPHERTEXT = b"ciphertext-bytes"
_KEY_ID = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"
@pytest.mark.parametrize(
("plaintext", "expected"),
[
pytest.param(b"True", True, id="true literal"),
pytest.param(b"False", False, id="false literal"),
pytest.param(b" True\n", True, id="padded true literal"),
pytest.param(b"1", "1", id="integer literal"),
pytest.param(b"[True]", "[True]", id="list literal"),
pytest.param(b"'True'", "'True'", id="quoted string literal"),
pytest.param(b"sk-not-a-literal", "sk-not-a-literal", id="plain secret"),
pytest.param(b"", "", id="empty secret"),
],
)
def test_decrypt_value_turns_only_boolean_literals_into_bools(monkeypatch, plaintext, expected):
monkeypatch.setenv("AWS_REGION_NAME", "us-west-2")
monkeypatch.setenv("LITELLM_LICENSE", "license-for-test")
monkeypatch.setenv("ENCRYPTED_SETTING", "aws_kms/" + base64.b64encode(_CIPHERTEXT).decode())
kms = AWSKeyManagementService_V2()
with Stubber(kms.kms_client) as stubber:
stubber.add_response("decrypt", {"KeyId": _KEY_ID, "Plaintext": plaintext}, {"CiphertextBlob": _CIPHERTEXT})
decrypted = kms.decrypt_value(secret_name="ENCRYPTED_SETTING")
assert decrypted == expected
assert type(decrypted) is type(expected)
def test_kms_v2_without_a_license_tells_the_user_to_set_one(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setenv("AWS_REGION_NAME", "us-west-2")
monkeypatch.delenv("LITELLM_LICENSE", raising=False)
monkeypatch.delenv("LITELLM_SECRET_AWS_KMS_LITELLM_LICENSE", raising=False)
expected_message: Final = (
"AWSKeyManagementService V2 is an Enterprise Feature. Please add a valid LITELLM_LICENSE to your environment."
)
with pytest.raises(ValueError, match=f"^{re.escape(expected_message)}$"):
AWSKeyManagementService_V2()