AuthHelper { public AuthClientHandler.ImplicitClient getResourceLoginUri( String tenant, String user, String password, String authServerAddress, int authServerPort, String loginRedirectEndpoint, String logoutRedirectEndpoint) throws AuthException, NoSuchAlgorithmException, CertificateException, OperatorCreationException, URISyntaxException { AuthOIDCClient oidcClient = new AuthOIDCClient(authServerAddress, authServerPort, tenant); return getResourceLoginUri(oidcClient, user, password, loginRedirectEndpoint, logoutRedirectEndpoint); }  AuthClientHandler.ImplicitClient getResourceLoginUri(
      String tenant, String user, String password, String authServerAddress, int authServerPort,
      String loginRedirectEndpoint, String logoutRedirectEndpoint); AuthClientHandler.ImplicitClient getResourceLoginUri(
      AuthOIDCClient oidcClient, String user, String password,
      String loginRedirectEndpoint, String logoutRedirectEndpoint);  }
@Test public void getRedirectUriTestSuccess() throws Throwable { doReturn(authClientHandler).when(authOIDCClient).getClientHandler(eq(userName), eq(password)); doReturn(implicitClient).when(authClientHandler).registerImplicitClient(eq(loginRedirectUri), eq(logoutRedirectUri)); AuthHelper authHelper = new AuthHelper(); AuthClientHandler.ImplicitClient gotImplicitClient = authHelper.getResourceLoginUri(authOIDCClient, userName, password, loginRedirectEndpoint, logoutRedirectEndpoint); assertEquals(gotImplicitClient.loginURI, implicitClient.loginURI); assertEquals(gotImplicitClient.logoutURI, implicitClient.logoutURI); verify(authOIDCClient, times(1)).getClientHandler(userName, password); verify(authClientHandler, times(1)).registerImplicitClient(eq(loginRedirectUri), eq(logoutRedirectUri)); }
@Test(expectedExceptions = AuthException.class) public void getRedirectUriTestFailToGetClientHandler() throws Throwable { doThrow(new AuthException("Failed to get client handler.")) .when(authOIDCClient) .getClientHandler(eq(userName), eq(password)); AuthHelper authHelper = new AuthHelper(); authHelper.getResourceLoginUri(authOIDCClient, userName, password, loginRedirectEndpoint, logoutRedirectEndpoint); verify(authOIDCClient, times(1)).getClientHandler(userName, password); verify(authClientHandler, never()).registerClient(eq(loginRedirectUri)); verify(authClientHandler, never()).buildAuthenticationRequestURI(eq(clientID), eq(loginRedirectUri)); }
@Test(expectedExceptions = AuthException.class) public void getRedirectUriTestFailToRegister() throws Throwable { doReturn(authClientHandler).when(authOIDCClient).getClientHandler(eq(userName), eq(password)); doThrow(new AuthException("Failed to build URI.")) .when(authClientHandler) .registerImplicitClient(eq(loginRedirectUri), eq(logoutRedirectUri)); AuthHelper authHelper = new AuthHelper(); authHelper.getResourceLoginUri(authOIDCClient, userName, password, loginRedirectEndpoint, logoutRedirectEndpoint); verify(authOIDCClient, times(1)).getClientHandler(userName, password); verify(authClientHandler, times(1)).registerImplicitClient(eq(loginRedirectUri), eq(logoutRedirectUri)); }