mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 09:14:06 +02:00
github ci
This commit is contained in:
parent
58f6df3807
commit
80a4edf0ef
9 changed files with 144 additions and 6 deletions
70
.github/workflows/ci.yaml
vendored
Normal file
70
.github/workflows/ci.yaml
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
php-cs-fixer:
|
||||||
|
name: PHP-CS-Fixer
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.0'
|
||||||
|
extensions: apcu
|
||||||
|
- name: PHP-CS-Fixer
|
||||||
|
uses: OskarStark/php-cs-fixer-ga@2.16.7
|
||||||
|
with:
|
||||||
|
args: --diff --dry-run --allow-risky yes --stop-on-violation --using-cache=no --path-mode=intersection
|
||||||
|
|
||||||
|
phpstan:
|
||||||
|
name: PHPStan Static Analysis
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.0'
|
||||||
|
extensions: apcu, smbclient
|
||||||
|
- name: Composer
|
||||||
|
run: composer install
|
||||||
|
- env:
|
||||||
|
BACKEND: smbclient
|
||||||
|
run: php ./vendor/bin/phpstan analyse --level 1 src
|
||||||
|
|
||||||
|
phpunit:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
name: Unit tests
|
||||||
|
|
||||||
|
services:
|
||||||
|
samba:
|
||||||
|
image: dperson/samba
|
||||||
|
env:
|
||||||
|
USER: "test;test"
|
||||||
|
SHARE: "test;/tmp;yes;no;yes;all;none"
|
||||||
|
ports:
|
||||||
|
- 139:139
|
||||||
|
- 445:445
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Install packages
|
||||||
|
run: |
|
||||||
|
sudo apt-get install smbclient
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.0'
|
||||||
|
extensions: apcu, smbclient
|
||||||
|
- name: Composer
|
||||||
|
run: composer install
|
||||||
|
- name: Config
|
||||||
|
run: |
|
||||||
|
echo '{"host": "localhost","user": "test","password": "test","share": "test","root": ""}' > tests/config.json
|
||||||
|
- name: PHPUnit Tests
|
||||||
|
env:
|
||||||
|
BACKEND: smbclient
|
||||||
|
run: php ./vendor/bin/phpunit tests
|
||||||
|
|
@ -14,7 +14,8 @@
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^9.3.8",
|
"phpunit/phpunit": "^9.3.8",
|
||||||
"friendsofphp/php-cs-fixer": "^2.16"
|
"friendsofphp/php-cs-fixer": "^2.16",
|
||||||
|
"phpstan/phpstan": "^0.12.57"
|
||||||
},
|
},
|
||||||
"autoload" : {
|
"autoload" : {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
|
||||||
50
src/ProtocolLevel.php
Normal file
50
src/ProtocolLevel.php
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Icewind\SMB;
|
||||||
|
|
||||||
|
|
||||||
|
class ProtocolLevel {
|
||||||
|
/** @var string */
|
||||||
|
private $level;
|
||||||
|
|
||||||
|
private function __construct(string $level) {
|
||||||
|
$this->level = $level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLevel(): string {
|
||||||
|
return $this->level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function NT1(): self {
|
||||||
|
return new ProtocolLevel("NT1");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function SMB2(): self {
|
||||||
|
return new ProtocolLevel("SMB2");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function SMB3(): self {
|
||||||
|
return new ProtocolLevel("SMB3");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -82,7 +82,7 @@ class Connection extends RawConnection {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$output[] .= $line;
|
$output[] = $line;
|
||||||
}
|
}
|
||||||
$line = $this->readLine();
|
$line = $this->readLine();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ namespace Icewind\SMB\Wrapped;
|
||||||
|
|
||||||
use Icewind\SMB\Exception\ConnectException;
|
use Icewind\SMB\Exception\ConnectException;
|
||||||
use Icewind\SMB\Exception\ConnectionException;
|
use Icewind\SMB\Exception\ConnectionException;
|
||||||
|
use Icewind\SMB\Exception\ConnectionResetException;
|
||||||
|
|
||||||
class RawConnection {
|
class RawConnection {
|
||||||
/**
|
/**
|
||||||
|
|
@ -100,7 +101,13 @@ class RawConnection {
|
||||||
* @param string $input
|
* @param string $input
|
||||||
*/
|
*/
|
||||||
public function write($input) {
|
public function write($input) {
|
||||||
fwrite($this->getInputStream(), $input);
|
if (@fwrite($this->getInputStream(), $input) === false) {
|
||||||
|
$error = error_get_last();
|
||||||
|
if ($error && strpos($error['message'], "errno=32")) {
|
||||||
|
error_clear_last();
|
||||||
|
throw new ConnectionResetException();
|
||||||
|
}
|
||||||
|
}
|
||||||
fflush($this->getInputStream());
|
fflush($this->getInputStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ use Icewind\SMB\AbstractServer;
|
||||||
use Icewind\SMB\Exception\AuthenticationException;
|
use Icewind\SMB\Exception\AuthenticationException;
|
||||||
use Icewind\SMB\Exception\ConnectException;
|
use Icewind\SMB\Exception\ConnectException;
|
||||||
use Icewind\SMB\Exception\ConnectionException;
|
use Icewind\SMB\Exception\ConnectionException;
|
||||||
|
use Icewind\SMB\Exception\ConnectionRefusedException;
|
||||||
use Icewind\SMB\Exception\InvalidHostException;
|
use Icewind\SMB\Exception\InvalidHostException;
|
||||||
use Icewind\SMB\IShare;
|
use Icewind\SMB\IShare;
|
||||||
use Icewind\SMB\ISystem;
|
use Icewind\SMB\ISystem;
|
||||||
|
|
@ -62,6 +63,9 @@ class Server extends AbstractServer {
|
||||||
if (isset($output[0])) {
|
if (isset($output[0])) {
|
||||||
$parser->checkConnectionError($output[0]);
|
$parser->checkConnectionError($output[0]);
|
||||||
}
|
}
|
||||||
|
// if (count($output) === 0) {
|
||||||
|
// throw new ConnectionRefusedException();
|
||||||
|
// }
|
||||||
|
|
||||||
// sometimes we get an empty line first
|
// sometimes we get an empty line first
|
||||||
if (count($output) < 2) {
|
if (count($output) < 2) {
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,7 @@ class Share extends AbstractShare {
|
||||||
|
|
||||||
// use a close callback to ensure the upload is finished before continuing
|
// use a close callback to ensure the upload is finished before continuing
|
||||||
// this also serves as a way to keep the connection in scope
|
// this also serves as a way to keep the connection in scope
|
||||||
return CallbackWrapper::wrap($fh, null, null, function () use ($connection, $target) {
|
return CallbackWrapper::wrap($fh, null, null, function () use ($connection) {
|
||||||
$connection->close(false); // dont terminate, give the upload some time
|
$connection->close(false); // dont terminate, give the upload some time
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,11 @@ class NotifyHandlerTest extends TestCase {
|
||||||
} catch (RevisionMismatchException $e) {
|
} catch (RevisionMismatchException $e) {
|
||||||
$this->markTestSkipped("notify not supported with configured smb version");
|
$this->markTestSkipped("notify not supported with configured smb version");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$changes = array_filter($changes, function (Change $change) {
|
||||||
|
return $change->getPath()[0] !== '.';
|
||||||
|
});
|
||||||
|
|
||||||
$process->stop();
|
$process->stop();
|
||||||
$expected = [
|
$expected = [
|
||||||
new Change(INotifyHandler::NOTIFY_ADDED, 'source.txt'),
|
new Change(INotifyHandler::NOTIFY_ADDED, 'source.txt'),
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ namespace Icewind\SMB\Test;
|
||||||
|
|
||||||
use Icewind\SMB\BasicAuth;
|
use Icewind\SMB\BasicAuth;
|
||||||
use Icewind\SMB\Exception\AuthenticationException;
|
use Icewind\SMB\Exception\AuthenticationException;
|
||||||
|
use Icewind\SMB\Exception\ConnectionRefusedException;
|
||||||
use Icewind\SMB\Exception\InvalidHostException;
|
use Icewind\SMB\Exception\InvalidHostException;
|
||||||
use Icewind\SMB\IShare;
|
use Icewind\SMB\IShare;
|
||||||
use Icewind\SMB\Options;
|
use Icewind\SMB\Options;
|
||||||
|
|
@ -83,7 +84,7 @@ class ServerTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWrongHost() {
|
public function testWrongHost() {
|
||||||
$this->expectException(InvalidHostException::class);
|
$this->expectException(ConnectionRefusedException::class);
|
||||||
$server = new Server(
|
$server = new Server(
|
||||||
uniqid(),
|
uniqid(),
|
||||||
new BasicAuth(
|
new BasicAuth(
|
||||||
|
|
@ -99,7 +100,7 @@ class ServerTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHostEscape() {
|
public function testHostEscape() {
|
||||||
$this->expectException(InvalidHostException::class);
|
$this->expectException(ConnectionRefusedException::class);
|
||||||
$server = new Server(
|
$server = new Server(
|
||||||
$this->config->host . ';asd',
|
$this->config->host . ';asd',
|
||||||
new BasicAuth(
|
new BasicAuth(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue