use of org.eclipse.che.plugin.ssh.key.client.SshKeyUploader in project che by eclipse.
the class GitHubAuthenticatorImpl method generateSshKeys.
private void generateSshKeys(final OAuthStatus authStatus) {
final SshKeyUploader githubKeyUploader = registry.getUploader(GITHUB_HOST);
if (githubKeyUploader != null) {
String userId = appContext.getCurrentUser().getProfile().getUserId();
githubKeyUploader.uploadKey(userId, new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
callback.onSuccess(authStatus);
notificationManager.notify(locale.authMessageKeyUploadSuccess(), SUCCESS, FLOAT_MODE);
}
@Override
public void onFailure(Throwable exception) {
dialogFactory.createMessageDialog(locale.authorizationDialogTitle(), locale.authMessageUnableCreateSshKey(), null).show();
callback.onFailure(new Exception(locale.authMessageUnableCreateSshKey()));
getFailedKey();
}
});
} else {
dialogFactory.createMessageDialog(locale.authorizationDialogTitle(), locale.authMessageUnableCreateSshKey(), null).show();
callback.onFailure(new Exception(locale.authMessageUnableCreateSshKey()));
}
}
use of org.eclipse.che.plugin.ssh.key.client.SshKeyUploader in project che by eclipse.
the class GitHubAuthenticatorImplTest method onAuthenticatedWhenGenerateKeysIsFailure.
@Test
public void onAuthenticatedWhenGenerateKeysIsFailure() 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);
MessageDialog messageDialog = mock(MessageDialog.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);
when(dialogFactory.createMessageDialog(anyString(), anyString(), Matchers.<ConfirmCallback>anyObject())).thenReturn(messageDialog);
gitHubAuthenticator.authenticate(null, getCallBack());
gitHubAuthenticator.onAuthenticated(authStatus);
verify(keyProvider).uploadKey(eq(userId), generateKeyCallbackCaptor.capture());
AsyncCallback<Void> generateKeyCallback = generateKeyCallbackCaptor.getValue();
generateKeyCallback.onFailure(new Exception(""));
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));
}
use of org.eclipse.che.plugin.ssh.key.client.SshKeyUploader 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());
}
use of org.eclipse.che.plugin.ssh.key.client.SshKeyUploader 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));
}
use of org.eclipse.che.plugin.ssh.key.client.SshKeyUploader 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));
}
Aggregations