Skip to content

Commit 9b55908

Browse files
committed
Migrate CI to GitHub Actions and extend SSH features
Fixes #7 Fixes #9 Fixes #11 Fixes #12
1 parent 4db3af6 commit 9b55908

9 files changed

Lines changed: 520 additions & 179 deletions

File tree

.coveralls.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
phpunit:
11+
runs-on: ubuntu-22.04
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
include:
16+
- php: '7.0'
17+
composer: 'v1'
18+
- php: '7.4'
19+
composer: 'v2'
20+
- php: '8.0'
21+
composer: 'v2'
22+
- php: '8.4'
23+
composer: 'v2'
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: ${{ matrix.php }}
33+
tools: composer:${{ matrix.composer }}
34+
coverage: none
35+
36+
- name: Install dependencies
37+
run: composer update --no-interaction --prefer-dist --no-progress
38+
39+
- name: Configure SSH integration server
40+
run: |
41+
sudo apt-get update
42+
sudo apt-get install -y openssh-server
43+
44+
sudo userdel -r ci-test >/dev/null 2>&1 || true
45+
sudo useradd -m -s /bin/bash ci-test
46+
echo 'ci-test:ci-test-password' | sudo chpasswd
47+
48+
mkdir -p "$HOME/.ssh"
49+
ssh-keygen -q -t rsa -b 4096 -N '' -f "$HOME/.ssh/php_ssh_connection_ci_key"
50+
51+
sudo mkdir -p /home/ci-test/.ssh
52+
cat "$HOME/.ssh/php_ssh_connection_ci_key.pub" | sudo tee /home/ci-test/.ssh/authorized_keys >/dev/null
53+
sudo chown -R ci-test:ci-test /home/ci-test/.ssh
54+
sudo chmod 700 /home/ci-test/.ssh
55+
sudo chmod 600 /home/ci-test/.ssh/authorized_keys
56+
57+
if grep -q '^#\?PasswordAuthentication ' /etc/ssh/sshd_config; then
58+
sudo sed -i 's/^#\?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
59+
else
60+
echo 'PasswordAuthentication yes' | sudo tee -a /etc/ssh/sshd_config >/dev/null
61+
fi
62+
63+
if grep -q '^#\?PubkeyAuthentication ' /etc/ssh/sshd_config; then
64+
sudo sed -i 's/^#\?PubkeyAuthentication .*/PubkeyAuthentication yes/' /etc/ssh/sshd_config
65+
else
66+
echo 'PubkeyAuthentication yes' | sudo tee -a /etc/ssh/sshd_config >/dev/null
67+
fi
68+
69+
sudo service ssh restart
70+
71+
- name: Run tests
72+
env:
73+
RUN_SSH_INTEGRATION_TESTS: '1'
74+
SSH_TEST_HOST: 127.0.0.1
75+
SSH_TEST_PORT: '22'
76+
SSH_TEST_USER: ci-test
77+
SSH_TEST_PASSWORD: ci-test-password
78+
run: |
79+
export SSH_TEST_PRIVATE_KEY_PATH="$HOME/.ssh/php_ssh_connection_ci_key"
80+
vendor/bin/phpunit

.travis.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

README.md

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,86 @@
11
# PHP SSH Connection
22

3-
[![Build Status](https://travis-ci.com/Jord-JD/php-ssh-connection.svg?branch=master)](https://travis-ci.com/Jord-JD/php-ssh-connection)
4-
[![Coverage Status](https://coveralls.io/repos/github/Jord-JD/php-ssh-connection/badge.svg?branch=master)](https://coveralls.io/github/Jord-JD/php-ssh-connection?branch=master)
3+
[![Tests](https://github.com/Jord-JD/php-ssh-connection/actions/workflows/tests.yml/badge.svg)](https://github.com/Jord-JD/php-ssh-connection/actions/workflows/tests.yml)
54

6-
The PHP SSH Connection package provides an elegant syntax to connect to SSH servers and execute commands. It supports both password and public-private keypair authentication, and can easily capture command output and errors.
5+
The PHP SSH Connection package provides an elegant syntax to connect to SSH servers and execute commands. It supports password and public-private key authentication, and can capture command output and errors.
76

87
## Installation
98

10-
You can install the PHP SSH Connection package by running the following Composer command.
9+
Install with Composer:
1110

1211
```bash
1312
composer require jord-jd/php-ssh-connection
1413
```
1514

1615
## Usage
1716

18-
See the following basic usage instructions.
19-
2017
```php
2118
$connection = (new SSHConnection())
2219
->to('test.rebex.net')
2320
->onPort(22)
2421
->as('demo')
2522
->withPassword('password')
2623
// ->withPrivateKey($privateKeyPath)
27-
// ->timeout(0)
24+
// ->withPrivateKeyString($privateKeyContents)
25+
// ->timeout(30)
2826
->connect();
2927

3028
$command = $connection->run('echo "Hello world!"');
3129

32-
$command->getOutput(); // 'Hello World'
30+
$command->getOutput(); // 'Hello world!'
3331
$command->getError(); // ''
3432

3533
$connection->upload($localPath, $remotePath);
36-
$connection->download($remotePath, $localPath);
34+
$connection->download($remotePath, $localPath); // supports recursive directory downloads
3735
```
3836

39-
For security, you can fingerprint the remote server and verify the fingerprint remains the same
40-
upon each subsequent connection.
37+
### Running multiple commands
38+
39+
Each `run()` call executes in a fresh shell context. If you need stateful command execution (for example `cd` then `touch`), use `runCommands()`:
40+
41+
```php
42+
$connection->runCommands([
43+
'cd /var/www/html',
44+
'mkdir -p app',
45+
'cd app',
46+
'touch index.php',
47+
]);
48+
```
49+
50+
### Fingerprint verification
51+
52+
For security, you can fingerprint the remote server and verify it remains the same across connections.
4153

4254
```php
43-
$fingerprint = $connection->fingerprint();
55+
$fingerprint = $connection->fingerprint(); // defaults to MD5 for backward compatibility
4456

45-
if ($newConnection->fingerprint() != $fingerprint) {
57+
if ($newConnection->fingerprint() !== $fingerprint) {
4658
throw new Exception('Fingerprint does not match!');
4759
}
4860
```
4961

50-
If you wish, you can specify the type of fingerprint you wish to retrieve.
62+
Available fingerprint types:
5163

5264
```php
53-
$md5Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_MD5); // default
54-
$sha1Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA1);
65+
$md5Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_MD5);
66+
$sha1Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA1);
67+
$sha256Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA256);
68+
$sha512Fingerprint = $connection->fingerprint(SSHConnection::FINGERPRINT_SHA512);
69+
```
70+
71+
## Testing
72+
73+
The package test suite includes SSH integration tests. Set these variables before running tests:
74+
75+
- `RUN_SSH_INTEGRATION_TESTS=1`
76+
- `SSH_TEST_HOST`
77+
- `SSH_TEST_PORT`
78+
- `SSH_TEST_USER`
79+
- `SSH_TEST_PRIVATE_KEY_PATH` or `SSH_TEST_PRIVATE_KEY_CONTENTS`
80+
- `SSH_TEST_PASSWORD` (only required for password-auth test)
81+
82+
Then run:
83+
84+
```bash
85+
vendor/bin/phpunit
5586
```

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=7.1",
13+
"php": ">=7.0",
1414
"phpseclib/phpseclib": "^2.0"
1515
},
1616
"require-dev": {
17-
"phpunit/phpunit": "^9.6"
17+
"phpunit/phpunit": "^6.5 || ^7.5 || ^8.5 || ^9.6 || ^10.5 || ^11.5"
1818
},
1919
"autoload": {
2020
"psr-4": {
@@ -26,7 +26,7 @@
2626
},
2727
"extra": {
2828
"branch-alias": {
29-
"dev-master": "3.0-dev"
29+
"dev-master": "3.1-dev"
3030
}
3131
}
3232
}

phpunit.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit bootstrap="vendor/autoload.php"
3-
colors="true"
4-
cacheResult="false">
3+
colors="true">
54
<testsuites>
65
<testsuite name="Unit Tests">
76
<directory suffix="Test.php">./tests/Integration</directory>

0 commit comments

Comments
 (0)