Search in sources :

Example 6 with ProfileDto

use of org.eclipse.che.api.user.shared.dto.ProfileDto in project che by eclipse.

the class GitHubAuthenticatorImplTest method onAuthenticatedWhenGenerateKeysIsSelected.

@Test
public void onAuthenticatedWhenGenerateKeysIsSelected() throws Exception {
    String userId = "userId";
    OAuthStatus authStatus = mock(OAuthStatus.class);
    SshKeyUploader sshKeyUploader = mock(SshKeyUploader.class);
    CurrentUser user = mock(CurrentUser.class);
    ProfileDto profile = mock(ProfileDto.class);
    when(view.isGenerateKeysSelected()).thenReturn(true);
    when(registry.getUploader(GITHUB_HOST)).thenReturn(sshKeyUploader);
    when(appContext.getCurrentUser()).thenReturn(user);
    when(user.getProfile()).thenReturn(profile);
    when(profile.getUserId()).thenReturn(userId);
    gitHubAuthenticator.onAuthenticated(authStatus);
    verify(view).isGenerateKeysSelected();
    verify(registry).getUploader(eq(GITHUB_HOST));
    verify(appContext).getCurrentUser();
    verify(sshKeyUploader).uploadKey(eq(userId), Matchers.<AsyncCallback<Void>>anyObject());
}
Also used : SshKeyUploader(org.eclipse.che.plugin.ssh.key.client.SshKeyUploader) CurrentUser(org.eclipse.che.ide.api.app.CurrentUser) Matchers.anyString(org.mockito.Matchers.anyString) OAuthStatus(org.eclipse.che.security.oauth.OAuthStatus) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Test(org.junit.Test)

Example 7 with ProfileDto

use of org.eclipse.che.api.user.shared.dto.ProfileDto in project che by eclipse.

the class GitHubAuthenticatorImplTest method onAuthenticatedWhenGetFailedKeyIsSuccess.

@Test
public void onAuthenticatedWhenGetFailedKeyIsSuccess() throws Exception {
    String userId = "userId";
    SshPairDto pair = mock(SshPairDto.class);
    List<SshPairDto> pairs = new ArrayList<>();
    pairs.add(pair);
    OAuthStatus authStatus = mock(OAuthStatus.class);
    SshKeyUploader keyUploader = mock(SshKeyUploader.class);
    CurrentUser user = mock(CurrentUser.class);
    ProfileDto profile = mock(ProfileDto.class);
    MessageDialog messageDialog = mock(MessageDialog.class);
    when(view.isGenerateKeysSelected()).thenReturn(true);
    when(registry.getUploader(GITHUB_HOST)).thenReturn(keyUploader);
    when(appContext.getCurrentUser()).thenReturn(user);
    when(user.getProfile()).thenReturn(profile);
    when(profile.getUserId()).thenReturn(userId);
    when(dialogFactory.createMessageDialog(anyString(), anyString(), Matchers.<ConfirmCallback>anyObject())).thenReturn(messageDialog);
    when(pair.getName()).thenReturn(GITHUB_HOST);
    when(pair.getService()).thenReturn(SshKeyManagerPresenter.VCS_SSH_SERVICE);
    gitHubAuthenticator.authenticate(null, getCallBack());
    gitHubAuthenticator.onAuthenticated(authStatus);
    verify(keyUploader).uploadKey(eq(userId), generateKeyCallbackCaptor.capture());
    AsyncCallback<Void> generateKeyCallback = generateKeyCallbackCaptor.getValue();
    generateKeyCallback.onFailure(new Exception(""));
    verify(sshPairDTOsPromise).then(operationSshPairDTOsCapture.capture());
    operationSshPairDTOsCapture.getValue().apply(pairs);
    verify(view).isGenerateKeysSelected();
    verify(registry).getUploader(eq(GITHUB_HOST));
    verify(appContext).getCurrentUser();
    verify(dialogFactory).createMessageDialog(anyString(), anyString(), Matchers.<ConfirmCallback>anyObject());
    verify(messageDialog).show();
    verify(sshServiceClient).getPairs(eq(SshKeyManagerPresenter.VCS_SSH_SERVICE));
    verify(sshServiceClient).deletePair(eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), eq(GITHUB_HOST));
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) SshKeyUploader(org.eclipse.che.plugin.ssh.key.client.SshKeyUploader) CurrentUser(org.eclipse.che.ide.api.app.CurrentUser) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) OAuthStatus(org.eclipse.che.security.oauth.OAuthStatus) MessageDialog(org.eclipse.che.ide.api.dialogs.MessageDialog) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Test(org.junit.Test)

Example 8 with ProfileDto

use of org.eclipse.che.api.user.shared.dto.ProfileDto in project che by eclipse.

the class GitHubAuthenticatorImplTest method onAuthenticatedWhenGenerateKeysIsNotSelected.

@Test
public void onAuthenticatedWhenGenerateKeysIsNotSelected() throws Exception {
    String userId = "userId";
    OAuthStatus authStatus = mock(OAuthStatus.class);
    CurrentUser user = mock(CurrentUser.class);
    ProfileDto profile = mock(ProfileDto.class);
    when(view.isGenerateKeysSelected()).thenReturn(false);
    when(appContext.getCurrentUser()).thenReturn(user);
    when(user.getProfile()).thenReturn(profile);
    when(profile.getUserId()).thenReturn(userId);
    gitHubAuthenticator.authenticate(null, getCallBack());
    gitHubAuthenticator.onAuthenticated(authStatus);
    verify(view).isGenerateKeysSelected();
    verifyNoMoreInteractions(registry);
}
Also used : CurrentUser(org.eclipse.che.ide.api.app.CurrentUser) Matchers.anyString(org.mockito.Matchers.anyString) OAuthStatus(org.eclipse.che.security.oauth.OAuthStatus) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Test(org.junit.Test)

Example 9 with ProfileDto

use of org.eclipse.che.api.user.shared.dto.ProfileDto in project che by eclipse.

the class GitHubAuthenticatorImplTest method onAuthenticatedWhenGenerateKeysIsSuccess.

@Test
public void onAuthenticatedWhenGenerateKeysIsSuccess() throws Exception {
    String userId = "userId";
    OAuthStatus authStatus = mock(OAuthStatus.class);
    SshKeyUploader keyProvider = mock(SshKeyUploader.class);
    CurrentUser user = mock(CurrentUser.class);
    ProfileDto profile = mock(ProfileDto.class);
    when(view.isGenerateKeysSelected()).thenReturn(true);
    when(registry.getUploader(GITHUB_HOST)).thenReturn(keyProvider);
    when(appContext.getCurrentUser()).thenReturn(user);
    when(user.getProfile()).thenReturn(profile);
    when(profile.getUserId()).thenReturn(userId);
    gitHubAuthenticator.authenticate(null, getCallBack());
    gitHubAuthenticator.onAuthenticated(authStatus);
    verify(keyProvider).uploadKey(eq(userId), generateKeyCallbackCaptor.capture());
    AsyncCallback<Void> generateKeyCallback = generateKeyCallbackCaptor.getValue();
    generateKeyCallback.onSuccess(null);
    verify(view).isGenerateKeysSelected();
    verify(registry).getUploader(eq(GITHUB_HOST));
    verify(appContext).getCurrentUser();
    verify(notificationManager).notify(anyString(), eq(SUCCESS), eq(FLOAT_MODE));
}
Also used : SshKeyUploader(org.eclipse.che.plugin.ssh.key.client.SshKeyUploader) CurrentUser(org.eclipse.che.ide.api.app.CurrentUser) Matchers.anyString(org.mockito.Matchers.anyString) OAuthStatus(org.eclipse.che.security.oauth.OAuthStatus) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Test(org.junit.Test)

Example 10 with ProfileDto

use of org.eclipse.che.api.user.shared.dto.ProfileDto in project che by eclipse.

the class ProfileServiceTest method shouldGetCurrentProfile.

@Test
public void shouldGetCurrentProfile() throws Exception {
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/profile");
    assertEquals(response.getStatusCode(), 200);
    final ProfileDto profileDto = unwrapDto(response, ProfileDto.class);
    assertEquals(profileDto.getUserId(), SUBJECT.getUserId());
}
Also used : Response(com.jayway.restassured.response.Response) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Test(org.testng.annotations.Test)

Aggregations

ProfileDto (org.eclipse.che.api.user.shared.dto.ProfileDto)12 Test (org.junit.Test)9 CurrentUser (org.eclipse.che.ide.api.app.CurrentUser)7 OAuthStatus (org.eclipse.che.security.oauth.OAuthStatus)7 Matchers.anyString (org.mockito.Matchers.anyString)7 SshKeyUploader (org.eclipse.che.plugin.ssh.key.client.SshKeyUploader)4 Test (org.testng.annotations.Test)3 Response (com.jayway.restassured.response.Response)2 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 Promise (org.eclipse.che.api.promises.client.Promise)2 MessageDialog (org.eclipse.che.ide.api.dialogs.MessageDialog)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 Sets (com.google.common.collect.Sets)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1