Commit c4f912a 1 parent a8181e4 commit c4f912a Copy full SHA for c4f912a
File tree 2 files changed +27
-3
lines changed
cloudplatform/connectivity-ztis/src
main/java/com/sap/cloud/sdk/cloudplatform/connectivity
test/java/com/sap/cloud/sdk/cloudplatform/connectivity
2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 32
32
import io .spiffe .workloadapi .X509Source ;
33
33
import io .vavr .Lazy ;
34
34
import io .vavr .NotImplementedError ;
35
+ import io .vavr .control .Option ;
35
36
import lombok .AccessLevel ;
36
37
import lombok .Getter ;
37
38
import lombok .RequiredArgsConstructor ;
@@ -149,9 +150,16 @@ public String getSpiffeId()
149
150
* @return The app identifier.
150
151
*/
151
152
@ Nonnull
152
- public String getAppIdentifier ()
153
+ public Option < String > getAppIdentifier ()
153
154
{
154
- return credentials .get ().getMapView ("parameters" ).getString ("app-identifier" );
155
+ final TypedMapView mapView = credentials .get ();
156
+ return Option
157
+ .some (mapView )
158
+ .filter (m -> m .containsKey ("parameters" ))
159
+ .map (m -> m .getMapView ("parameters" ))
160
+ .filter (m -> m .containsKey ("app-identifier" ))
161
+ .map (m -> m .getString ("app-identifier" ))
162
+ .filter (s -> !s .isBlank ());
155
163
}
156
164
157
165
/**
Original file line number Diff line number Diff line change 20
20
import org .junit .jupiter .api .BeforeEach ;
21
21
import org .junit .jupiter .api .Test ;
22
22
23
+ import com .sap .cloud .environment .servicebinding .api .DefaultServiceBinding ;
23
24
import com .sap .cloud .environment .servicebinding .api .DefaultServiceBindingBuilder ;
24
25
import com .sap .cloud .environment .servicebinding .api .ServiceBinding ;
25
26
import com .sap .cloud .environment .servicebinding .api .exception .ServiceBindingAccessException ;
@@ -91,7 +92,22 @@ void testSpiffeId()
91
92
@ Test
92
93
void testAppIdentifier ()
93
94
{
94
- assertThat (sut .getAppIdentifier ()).isEqualTo ("test-app" );
95
+ assertThat (sut .getAppIdentifier ()).contains ("test-app" );
96
+
97
+ final DefaultServiceBinding emptyBinding =
98
+ new DefaultServiceBindingBuilder ().withServiceIdentifier (ZTIS_IDENTIFIER ).build ();
99
+
100
+ sut = new ZeroTrustIdentityService (emptyBinding );
101
+ assertThat (sut .getAppIdentifier ()).isEmpty ();
102
+
103
+ final DefaultServiceBinding emptyValue =
104
+ new DefaultServiceBindingBuilder ()
105
+ .withServiceIdentifier (ZTIS_IDENTIFIER )
106
+ .withCredentials (Map .of ("parameters" , Map .of ("app-identifier" , "" )))
107
+ .build ();
108
+
109
+ sut = new ZeroTrustIdentityService (emptyValue );
110
+ assertThat (sut .getAppIdentifier ()).isEmpty ();
95
111
}
96
112
97
113
@ Test
You can’t perform that action at this time.
0 commit comments