public function itRemovesMultipleTimeTheSSHKeyforUserIfFoundMultipleTimes() { $url_list_keys = $this->gerrit_server_host . ':' . $this->gerrit_server_port . '/a/accounts/' . urlencode($this->user->getSSHUserName()) . '/sshkeys'; $existing_keys = <<<EOS )]}' [ { "seq": 1, "ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...azertyAw\\u003d\\u003d john.doe@example.com", "encoded_key": "AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...azertyAw\\u003d\\u003d", "algorithm": "ssh-rsa", "comment": "*****@*****.**", "valid": true }, { "seq": 2, "ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...YImydZAw\\u003d\\u003d john.doe@example.com", "encoded_key": "AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...YImydZAw\\u003d\\u003d", "algorithm": "ssh-rsa", "comment": "*****@*****.**", "valid": true }, { "seq": 3, "ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...YImydZAw\\u003d\\u003d another comment that do not match the requested comment", "encoded_key": "AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...YImydZAw\\u003d\\u003d", "algorithm": "ssh-rsa", "comment": "another comment that do not match the requested comment", "valid": true } ] EOS; stub($this->guzzle_client)->get($url_list_keys, '*')->returns($this->getGuzzleRequestWithTextResponse($existing_keys)); $url_first_key = $this->gerrit_server_host . ':' . $this->gerrit_server_port . '/a/accounts/' . urlencode($this->user->getSSHUserName()) . '/sshkeys/2'; $ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0T...YImydZAw== john.doe@example.com"; expect($this->guzzle_client)->delete($url_first_key, array('verify' => false))->at(0); $url_second_key = $this->gerrit_server_host . ':' . $this->gerrit_server_port . '/a/accounts/' . urlencode($this->user->getSSHUserName()) . '/sshkeys/3'; expect($this->guzzle_client)->delete($url_second_key, array('verify' => false))->at(1); expect($this->guzzle_client)->delete()->count(2); stub($this->guzzle_client)->delete()->returns($this->guzzle_request); expect($this->logger)->info()->count(8); $this->driver->removeSSHKeyFromAccount($this->gerrit_server, $this->user, $ssh_key); }
/** * * @param Git_RemoteServer_GerritServer $server * @param Git_Driver_Gerrit_User $user * @param string $ssh_key * @throws Git_Driver_Gerrit_Exception */ public function removeSSHKeyFromAccount(Git_RemoteServer_GerritServer $server, Git_Driver_Gerrit_User $user, $ssh_key) { $escaped_ssh_key = escapeshellarg($ssh_key); $query = self::COMMAND . ' set-account --delete-ssh-key "' . $escaped_ssh_key . '" ' . $user->getSSHUserName(); $this->ssh->execute($server, $query); }
public function getEndUserCloneUrl($gerrit_project, Git_Driver_Gerrit_User $user = null) { $login = self::DEFAULT_GERRIT_USERNAME; if ($user !== null) { $login = $user->getSSHUserName(); } return 'ssh://' . $login . '@' . $this->host . ':' . $this->ssh_port . '/' . $gerrit_project . '.git'; }
private function actionRemoveSSHKey(Git_RemoteServer_GerritServer $server, Git_Driver_Gerrit_User $user, $gerrit_key_id) { try { $this->sendRequest($server, $this->guzzle_client->delete($this->getGerritURL($server, '/accounts/' . urlencode($user->getSSHUserName()) . '/sshkeys/' . urlencode($gerrit_key_id)), $this->getRequestOptions())); $this->logger->info("Gerrit REST driver: Successfully deleted ssh key ({$gerrit_key_id})"); return true; } catch (Exception $exception) { $this->throwGerritException("Gerrit REST driver: Cannot remove ssh key ({$gerrit_key_id}): " . $exception->getMessage()); } }