|
10 | 10 | _get_secret, |
11 | 11 | set_aicore_config, |
12 | 12 | ) |
13 | | -from sap_cloud_sdk.aicore import _is_transparent_tls |
14 | 13 |
|
15 | 14 |
|
16 | 15 | class TestGetSecret: |
@@ -713,125 +712,3 @@ def test_set_config_decorated_with_record_metrics(self): |
713 | 712 | # The actual telemetry recording is tested in telemetry tests |
714 | 713 |
|
715 | 714 |
|
716 | | -class TestIsTransparentTls: |
717 | | - """Test suite for _is_transparent_tls helper.""" |
718 | | - |
719 | | - def test_returns_true_for_value_true(self): |
720 | | - with patch.dict("os.environ", {"AICORE_TRANSPARENT_TLS": "true"}): |
721 | | - assert _is_transparent_tls() is True |
722 | | - |
723 | | - def test_returns_true_for_value_1(self): |
724 | | - with patch.dict("os.environ", {"AICORE_TRANSPARENT_TLS": "1"}): |
725 | | - assert _is_transparent_tls() is True |
726 | | - |
727 | | - def test_returns_true_for_value_yes(self): |
728 | | - with patch.dict("os.environ", {"AICORE_TRANSPARENT_TLS": "yes"}): |
729 | | - assert _is_transparent_tls() is True |
730 | | - |
731 | | - def test_returns_true_case_insensitive(self): |
732 | | - with patch.dict("os.environ", {"AICORE_TRANSPARENT_TLS": "TRUE"}): |
733 | | - assert _is_transparent_tls() is True |
734 | | - |
735 | | - def test_returns_false_when_absent(self): |
736 | | - with patch.dict("os.environ", {}, clear=True): |
737 | | - assert _is_transparent_tls() is False |
738 | | - |
739 | | - def test_returns_false_for_value_false(self): |
740 | | - with patch.dict("os.environ", {"AICORE_TRANSPARENT_TLS": "false"}): |
741 | | - assert _is_transparent_tls() is False |
742 | | - |
743 | | - |
744 | | -class TestSetAICoreConfigTransparentTls: |
745 | | - """Test suite for set_aicore_config in transparent TLS mode.""" |
746 | | - |
747 | | - def _base_secrets(self): |
748 | | - return { |
749 | | - "AICORE_CLIENT_ID": "test-client-id", |
750 | | - "AICORE_AUTH_URL": "https://auth.example.com", |
751 | | - "AICORE_RESOURCE_GROUP": "default", |
752 | | - } |
753 | | - |
754 | | - def test_transparent_tls_does_not_set_client_secret(self): |
755 | | - """In transparent TLS mode, AICORE_CLIENT_SECRET must not be written to env.""" |
756 | | - with ( |
757 | | - patch("sap_cloud_sdk.aicore._get_secret") as mock_get_secret, |
758 | | - patch("sap_cloud_sdk.aicore._get_aicore_base_url", return_value="https://api.example.com"), |
759 | | - patch("sap_cloud_sdk.aicore.set_filtering"), |
760 | | - patch.dict("os.environ", {"AICORE_TRANSPARENT_TLS": "true"}, clear=True), |
761 | | - ): |
762 | | - mock_get_secret.side_effect = lambda name, file_name=None, default="", instance_name="aicore-instance": ( |
763 | | - self._base_secrets().get(name, default) |
764 | | - ) |
765 | | - |
766 | | - set_aicore_config() |
767 | | - |
768 | | - assert "AICORE_CLIENT_SECRET" not in os.environ |
769 | | - |
770 | | - def test_transparent_tls_removes_stale_client_secret(self): |
771 | | - """Any pre-existing AICORE_CLIENT_SECRET is cleared in transparent TLS mode.""" |
772 | | - with ( |
773 | | - patch("sap_cloud_sdk.aicore._get_secret") as mock_get_secret, |
774 | | - patch("sap_cloud_sdk.aicore._get_aicore_base_url", return_value=""), |
775 | | - patch("sap_cloud_sdk.aicore.set_filtering"), |
776 | | - patch.dict( |
777 | | - "os.environ", |
778 | | - {"AICORE_TRANSPARENT_TLS": "true", "AICORE_CLIENT_SECRET": "stale-secret"}, |
779 | | - clear=True, |
780 | | - ), |
781 | | - ): |
782 | | - mock_get_secret.side_effect = lambda name, file_name=None, default="", instance_name="aicore-instance": ( |
783 | | - self._base_secrets().get(name, default) |
784 | | - ) |
785 | | - |
786 | | - set_aicore_config() |
787 | | - |
788 | | - assert "AICORE_CLIENT_SECRET" not in os.environ |
789 | | - |
790 | | - def test_transparent_tls_sets_other_credentials(self): |
791 | | - """Non-secret credentials are still set in transparent TLS mode.""" |
792 | | - with ( |
793 | | - patch("sap_cloud_sdk.aicore._get_secret") as mock_get_secret, |
794 | | - patch("sap_cloud_sdk.aicore._get_aicore_base_url", return_value="https://api.example.com"), |
795 | | - patch("sap_cloud_sdk.aicore.set_filtering"), |
796 | | - patch.dict("os.environ", {"AICORE_TRANSPARENT_TLS": "true"}, clear=True), |
797 | | - ): |
798 | | - mock_get_secret.side_effect = lambda name, file_name=None, default="", instance_name="aicore-instance": ( |
799 | | - self._base_secrets().get(name, default) |
800 | | - ) |
801 | | - |
802 | | - set_aicore_config() |
803 | | - |
804 | | - assert os.environ["AICORE_CLIENT_ID"] == "test-client-id" |
805 | | - assert os.environ["AICORE_AUTH_URL"] == "https://auth.example.com/oauth/token" |
806 | | - assert os.environ["AICORE_BASE_URL"] == "https://api.example.com/v2" |
807 | | - |
808 | | - def test_standard_mode_still_sets_client_secret(self): |
809 | | - """Regression: without transparent TLS, client_secret is still written.""" |
810 | | - with ( |
811 | | - patch("sap_cloud_sdk.aicore._get_secret") as mock_get_secret, |
812 | | - patch("sap_cloud_sdk.aicore._get_aicore_base_url", return_value=""), |
813 | | - patch("sap_cloud_sdk.aicore.set_filtering"), |
814 | | - patch.dict("os.environ", {}, clear=True), |
815 | | - ): |
816 | | - mock_get_secret.side_effect = lambda name, file_name=None, default="", instance_name="aicore-instance": ( |
817 | | - {**self._base_secrets(), "AICORE_CLIENT_SECRET": "my-secret"}.get(name, default) |
818 | | - ) |
819 | | - |
820 | | - set_aicore_config() |
821 | | - |
822 | | - assert os.environ["AICORE_CLIENT_SECRET"] == "my-secret" |
823 | | - |
824 | | - def test_transparent_tls_does_not_call_get_secret_for_client_secret(self): |
825 | | - """_get_secret should not be called for clientsecret in transparent TLS mode.""" |
826 | | - with ( |
827 | | - patch("sap_cloud_sdk.aicore._get_secret") as mock_get_secret, |
828 | | - patch("sap_cloud_sdk.aicore._get_aicore_base_url", return_value=""), |
829 | | - patch("sap_cloud_sdk.aicore.set_filtering"), |
830 | | - patch.dict("os.environ", {"AICORE_TRANSPARENT_TLS": "true"}, clear=True), |
831 | | - ): |
832 | | - mock_get_secret.return_value = "" |
833 | | - |
834 | | - set_aicore_config() |
835 | | - |
836 | | - called_names = [c.args[0] for c in mock_get_secret.call_args_list] |
837 | | - assert "AICORE_CLIENT_SECRET" not in called_names |
0 commit comments