File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed
main/java/com/sap/ai/sdk/core
test/java/com/sap/ai/sdk/core Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ static ServiceBinding createServiceBinding(@Nonnull final String serviceKey)
8181 new AiCoreCredentialsInvalidException ("Missing clientid in service key" ));
8282 }
8383
84- if (credentials .get ("clientsecret" ) != null && credentials .get ("credentials -type" ) == null ) {
84+ if (credentials .get ("clientsecret" ) != null && credentials .get ("credential -type" ) == null ) {
8585 // add missing "credential-type: binding-secret"
8686 credentials .put ("credential-type" , "binding-secret" );
8787 }
Original file line number Diff line number Diff line change @@ -55,4 +55,32 @@ void testMalformedDotenv() {
5555 assertThatThrownBy (accessor ::getServiceBindings )
5656 .isInstanceOf (ServiceBindingAccessException .class );
5757 }
58+
59+ @ Test
60+ void testServiceBindingCreation () {
61+ var serviceKeyWithoutCredentialType =
62+ """
63+ {
64+ "clientid": "",
65+ "clientsecret": ""
66+ }
67+ """ ;
68+ var binding1 = AiCoreServiceKeyAccessor .createServiceBinding (serviceKeyWithoutCredentialType );
69+ assertThat (binding1 .getCredentials ().containsKey ("credential-type" ))
70+ .describedAs ("The missing 'credential-type' should have automatically been added" )
71+ .isTrue ();
72+ var serviceKeyWithCredentialType =
73+ """
74+ {
75+ "clientid": "",
76+ "clientsecret": "",
77+ "credential-type": "foo"
78+ }
79+ }
80+ """ ;
81+ var binding2 = AiCoreServiceKeyAccessor .createServiceBinding (serviceKeyWithCredentialType );
82+ assertThat (binding2 .getCredentials ().get ("credential-type" ))
83+ .describedAs ("The 'credential-type' field should not get overwritten" )
84+ .isEqualTo ("foo" );
85+ }
5886}
Original file line number Diff line number Diff line change @@ -30,9 +30,6 @@ void testGetDestinationFromBinding() {
3030 var binding = AiCoreServiceKeyAccessor .createServiceBinding (serviceKey );
3131 var resolver = new DestinationResolver (() -> List .of (binding ));
3232 var result = resolver .getDestination ();
33- assertThat (binding .getCredentials ().containsKey ("credential-type" ))
34- .describedAs ("The missing 'credential-type' should have automatically been added" )
35- .isTrue ();
3633 assertThat (result .getUri ())
3734 .describedAs ("The destination should already contain the /v2 base path" )
3835 .hasToString ("https://api.ai.core/v2/" );
You can’t perform that action at this time.
0 commit comments