OIDCAuthService { public ResponseEntity<String> getGroupObjectIdFromAzure(String groupName) { String ssoToken = oidcUtil.getSSOToken(); if (!StringUtils.isEmpty(ssoToken)) { String objectId = oidcUtil.getGroupObjectResponse(ssoToken, groupName); if (objectId != null) { return ResponseEntity.status(HttpStatus.OK).body("{\"data\":{\"objectId\": \""+objectId+"\"}}"); } return ResponseEntity.status(HttpStatus.NOT_FOUND).body("{\"errors\":[\"Group not found in Active Directory\"]}"); } return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Failed to get SSO token for Azure AD access\"]}"); }  ResponseEntity<String> getAuthenticationMounts(String token); ResponseEntity<OIDCEntityResponse> entityLookUp(String token,
			OIDCLookupEntityRequest oidcLookupEntityRequest); ResponseEntity<String> groupEntityLookUp(String token, OIDCLookupEntityRequest oidcLookupEntityRequest); ResponseEntity<String> readEntityAliasById(String token, String id); ResponseEntity<String> readEntityByName(String token, String entityName); ResponseEntity<String> updateEntityByName(String token, OIDCEntityRequest oidcEntityRequest); ResponseEntity<String> updateIdentityGroupByName(String token,
                                                            OIDCIdentityGroupRequest oidcIdentityGroupRequest); ResponseEntity<String> readGroupAliasById(String token, String id); ResponseEntity<String> deleteGroupByName(String token, String name); ResponseEntity<String> deleteGroupAliasByID(String token, String id); ResponseEntity<String> createGroupAlias(String token, GroupAliasRequest groupAliasRequest); ResponseEntity<String> getAuthUrl(OidcRequest oidcRequest); ResponseEntity<String> processOIDCCallback(String state, String code); ResponseEntity<String> getGroupObjectIdFromAzure(String groupName); ResponseEntity<String> getIdentityGroupDetails(String groupName, String token); ResponseEntity<String> getUserName(UserDetails userDetails); ResponseEntity<DirectoryObjects> searchGroupInAzureAD(String groupName);  }
@Test public void test_getGroupObjectIdFromAzure_success() throws Exception { String ssoToken = "abcd"; String groupName = "group1"; when(OIDCUtil.getSSOToken()).thenReturn(ssoToken); when(OIDCUtil.getGroupObjectResponse(ssoToken, groupName)).thenReturn("abcdefg"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"data\":{\"objectId\": \"abcdefg\"}}"); ResponseEntity<String> responseEntityActual = oidcAuthService.getGroupObjectIdFromAzure(groupName); assertEquals(HttpStatus.OK, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected.toString(),responseEntityActual.toString()); }
@Test public void test_getGroupObjectIdFromAzure_400() throws Exception { String ssoToken = "abcd"; String groupName = "group1"; when(OIDCUtil.getSSOToken()).thenReturn(ssoToken); when(OIDCUtil.getGroupObjectResponse(ssoToken, groupName)).thenReturn(null); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.NOT_FOUND).body("{\"errors\":[\"Group not found in Active Directory\"]}"); ResponseEntity<String> responseEntityActual = oidcAuthService.getGroupObjectIdFromAzure(groupName); assertEquals(HttpStatus.NOT_FOUND, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected.toString(),responseEntityActual.toString()); }
@Test public void test_getGroupObjectIdFromAzure_404() throws Exception { String ssoToken = "abcd"; String groupName = "group1"; when(OIDCUtil.getSSOToken()).thenReturn(null); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Failed to get SSO token for Azure AD access\"]}"); ResponseEntity<String> responseEntityActual = oidcAuthService.getGroupObjectIdFromAzure(groupName); assertEquals(HttpStatus.BAD_REQUEST, responseEntityActual.getStatusCode()); assertEquals(responseEntityExpected.toString(),responseEntityActual.toString()); }