Skip to content

Commit

Permalink
github ci
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Mar 2, 2021
1 parent 58f6df3 commit 80a4edf
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 6 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"require-dev": {
"phpunit/phpunit": "^9.3.8",
"friendsofphp/php-cs-fixer": "^2.16"
"friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.12.57"
},
"autoload" : {
"psr-4": {
Expand Down
50 changes: 50 additions & 0 deletions src/ProtocolLevel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Robin Appelman <[email protected]>
*
* @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");
}
}
2 changes: 1 addition & 1 deletion src/Wrapped/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function read(callable $callback = null) {
break;
}
} else {
$output[] .= $line;
$output[] = $line;
}
$line = $this->readLine();
}
Expand Down
9 changes: 8 additions & 1 deletion src/Wrapped/RawConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Icewind\SMB\Exception\ConnectException;
use Icewind\SMB\Exception\ConnectionException;
use Icewind\SMB\Exception\ConnectionResetException;

class RawConnection {
/**
Expand Down Expand Up @@ -100,7 +101,13 @@ public function isValid() {
* @param string $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());
}

Expand Down
4 changes: 4 additions & 0 deletions src/Wrapped/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Icewind\SMB\Exception\AuthenticationException;
use Icewind\SMB\Exception\ConnectException;
use Icewind\SMB\Exception\ConnectionException;
use Icewind\SMB\Exception\ConnectionRefusedException;
use Icewind\SMB\Exception\InvalidHostException;
use Icewind\SMB\IShare;
use Icewind\SMB\ISystem;
Expand Down Expand Up @@ -62,6 +63,9 @@ public function listShares() {
if (isset($output[0])) {
$parser->checkConnectionError($output[0]);
}
// if (count($output) === 0) {
// throw new ConnectionRefusedException();
// }

// sometimes we get an empty line first
if (count($output) < 2) {
Expand Down
2 changes: 1 addition & 1 deletion src/Wrapped/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public function write($target) {

// use a close callback to ensure the upload is finished before continuing
// 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
});
}
Expand Down
5 changes: 5 additions & 0 deletions tests/NotifyHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public function testGetChanges() {
} catch (RevisionMismatchException $e) {
$this->markTestSkipped("notify not supported with configured smb version");
}

$changes = array_filter($changes, function (Change $change) {
return $change->getPath()[0] !== '.';
});

$process->stop();
$expected = [
new Change(INotifyHandler::NOTIFY_ADDED, 'source.txt'),
Expand Down
5 changes: 3 additions & 2 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Icewind\SMB\BasicAuth;
use Icewind\SMB\Exception\AuthenticationException;
use Icewind\SMB\Exception\ConnectionRefusedException;
use Icewind\SMB\Exception\InvalidHostException;
use Icewind\SMB\IShare;
use Icewind\SMB\Options;
Expand Down Expand Up @@ -83,7 +84,7 @@ public function testWrongPassword() {
}

public function testWrongHost() {
$this->expectException(InvalidHostException::class);
$this->expectException(ConnectionRefusedException::class);
$server = new Server(
uniqid(),
new BasicAuth(
Expand All @@ -99,7 +100,7 @@ public function testWrongHost() {
}

public function testHostEscape() {
$this->expectException(InvalidHostException::class);
$this->expectException(ConnectionRefusedException::class);
$server = new Server(
$this->config->host . ';asd',
new BasicAuth(
Expand Down

0 comments on commit 80a4edf

Please sign in to comment.