Skip to content

Commit 80a4edf

Browse files
committed
github ci
1 parent 58f6df3 commit 80a4edf

File tree

9 files changed

+144
-6
lines changed

9 files changed

+144
-6
lines changed

.github/workflows/ci.yaml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
on: [push, pull_request]
2+
3+
name: CI
4+
5+
jobs:
6+
php-cs-fixer:
7+
name: PHP-CS-Fixer
8+
runs-on: ubuntu-20.04
9+
steps:
10+
- uses: actions/checkout@master
11+
- name: Setup PHP
12+
uses: shivammathur/setup-php@v2
13+
with:
14+
php-version: '8.0'
15+
extensions: apcu
16+
- name: PHP-CS-Fixer
17+
uses: OskarStark/[email protected]
18+
with:
19+
args: --diff --dry-run --allow-risky yes --stop-on-violation --using-cache=no --path-mode=intersection
20+
21+
phpstan:
22+
name: PHPStan Static Analysis
23+
runs-on: ubuntu-20.04
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Setup PHP
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: '8.0'
31+
extensions: apcu, smbclient
32+
- name: Composer
33+
run: composer install
34+
- env:
35+
BACKEND: smbclient
36+
run: php ./vendor/bin/phpstan analyse --level 1 src
37+
38+
phpunit:
39+
runs-on: ubuntu-20.04
40+
name: Unit tests
41+
42+
services:
43+
samba:
44+
image: dperson/samba
45+
env:
46+
USER: "test;test"
47+
SHARE: "test;/tmp;yes;no;yes;all;none"
48+
ports:
49+
- 139:139
50+
- 445:445
51+
52+
steps:
53+
- name: Install packages
54+
run: |
55+
sudo apt-get install smbclient
56+
- uses: actions/checkout@v2
57+
- name: Setup PHP
58+
uses: shivammathur/setup-php@v2
59+
with:
60+
php-version: '8.0'
61+
extensions: apcu, smbclient
62+
- name: Composer
63+
run: composer install
64+
- name: Config
65+
run: |
66+
echo '{"host": "localhost","user": "test","password": "test","share": "test","root": ""}' > tests/config.json
67+
- name: PHPUnit Tests
68+
env:
69+
BACKEND: smbclient
70+
run: php ./vendor/bin/phpunit tests

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
},
1515
"require-dev": {
1616
"phpunit/phpunit": "^9.3.8",
17-
"friendsofphp/php-cs-fixer": "^2.16"
17+
"friendsofphp/php-cs-fixer": "^2.16",
18+
"phpstan/phpstan": "^0.12.57"
1819
},
1920
"autoload" : {
2021
"psr-4": {

src/ProtocolLevel.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2021 Robin Appelman <[email protected]>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace Icewind\SMB;
25+
26+
27+
class ProtocolLevel {
28+
/** @var string */
29+
private $level;
30+
31+
private function __construct(string $level) {
32+
$this->level = $level;
33+
}
34+
35+
public function getLevel(): string {
36+
return $this->level;
37+
}
38+
39+
public static function NT1(): self {
40+
return new ProtocolLevel("NT1");
41+
}
42+
43+
public static function SMB2(): self {
44+
return new ProtocolLevel("SMB2");
45+
}
46+
47+
public static function SMB3(): self {
48+
return new ProtocolLevel("SMB3");
49+
}
50+
}

src/Wrapped/Connection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function read(callable $callback = null) {
8282
break;
8383
}
8484
} else {
85-
$output[] .= $line;
85+
$output[] = $line;
8686
}
8787
$line = $this->readLine();
8888
}

src/Wrapped/RawConnection.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Icewind\SMB\Exception\ConnectException;
1111
use Icewind\SMB\Exception\ConnectionException;
12+
use Icewind\SMB\Exception\ConnectionResetException;
1213

1314
class RawConnection {
1415
/**
@@ -100,7 +101,13 @@ public function isValid() {
100101
* @param string $input
101102
*/
102103
public function write($input) {
103-
fwrite($this->getInputStream(), $input);
104+
if (@fwrite($this->getInputStream(), $input) === false) {
105+
$error = error_get_last();
106+
if ($error && strpos($error['message'], "errno=32")) {
107+
error_clear_last();
108+
throw new ConnectionResetException();
109+
}
110+
}
104111
fflush($this->getInputStream());
105112
}
106113

src/Wrapped/Server.php

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Icewind\SMB\Exception\AuthenticationException;
1212
use Icewind\SMB\Exception\ConnectException;
1313
use Icewind\SMB\Exception\ConnectionException;
14+
use Icewind\SMB\Exception\ConnectionRefusedException;
1415
use Icewind\SMB\Exception\InvalidHostException;
1516
use Icewind\SMB\IShare;
1617
use Icewind\SMB\ISystem;
@@ -62,6 +63,9 @@ public function listShares() {
6263
if (isset($output[0])) {
6364
$parser->checkConnectionError($output[0]);
6465
}
66+
// if (count($output) === 0) {
67+
// throw new ConnectionRefusedException();
68+
// }
6569

6670
// sometimes we get an empty line first
6771
if (count($output) < 2) {

src/Wrapped/Share.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public function write($target) {
348348

349349
// use a close callback to ensure the upload is finished before continuing
350350
// this also serves as a way to keep the connection in scope
351-
return CallbackWrapper::wrap($fh, null, null, function () use ($connection, $target) {
351+
return CallbackWrapper::wrap($fh, null, null, function () use ($connection) {
352352
$connection->close(false); // dont terminate, give the upload some time
353353
});
354354
}

tests/NotifyHandlerTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public function testGetChanges() {
7272
} catch (RevisionMismatchException $e) {
7373
$this->markTestSkipped("notify not supported with configured smb version");
7474
}
75+
76+
$changes = array_filter($changes, function (Change $change) {
77+
return $change->getPath()[0] !== '.';
78+
});
79+
7580
$process->stop();
7681
$expected = [
7782
new Change(INotifyHandler::NOTIFY_ADDED, 'source.txt'),

tests/ServerTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Icewind\SMB\BasicAuth;
1111
use Icewind\SMB\Exception\AuthenticationException;
12+
use Icewind\SMB\Exception\ConnectionRefusedException;
1213
use Icewind\SMB\Exception\InvalidHostException;
1314
use Icewind\SMB\IShare;
1415
use Icewind\SMB\Options;
@@ -83,7 +84,7 @@ public function testWrongPassword() {
8384
}
8485

8586
public function testWrongHost() {
86-
$this->expectException(InvalidHostException::class);
87+
$this->expectException(ConnectionRefusedException::class);
8788
$server = new Server(
8889
uniqid(),
8990
new BasicAuth(
@@ -99,7 +100,7 @@ public function testWrongHost() {
99100
}
100101

101102
public function testHostEscape() {
102-
$this->expectException(InvalidHostException::class);
103+
$this->expectException(ConnectionRefusedException::class);
103104
$server = new Server(
104105
$this->config->host . ';asd',
105106
new BasicAuth(

0 commit comments

Comments
 (0)