move backends into their own namespace and add support for multiple auth methods

This commit is contained in:
Robin Appelman 2018-03-13 16:18:37 +01:00
commit 29bdebad42
33 changed files with 752 additions and 377 deletions

View file

@ -11,10 +11,11 @@ use Icewind\SMB\Exception\FileInUseException;
use Icewind\SMB\Exception\InvalidPathException;
use Icewind\SMB\Exception\NotFoundException;
use Icewind\SMB\FileInfo;
use Icewind\SMB\IFileInfo;
abstract class AbstractShareTest extends TestCase {
/**
* @var \Icewind\SMB\Server $server
* @var \Icewind\SMB\IServer $server
*/
protected $server;
@ -557,49 +558,49 @@ abstract class AbstractShareTest extends TestCase {
$this->share->put($txtFile, $this->root . '/' . $name);
$this->share->setMode($this->root . '/' . $name, FileInfo::MODE_NORMAL);
$this->share->setMode($this->root . '/' . $name, IFileInfo::MODE_NORMAL);
$info = $this->share->stat($this->root . '/' . $name);
$this->assertFalse($info->isReadOnly());
$this->assertFalse($info->isArchived());
$this->assertFalse($info->isSystem());
$this->assertFalse($info->isHidden());
$this->share->setMode($this->root . '/' . $name, FileInfo::MODE_READONLY);
$this->share->setMode($this->root . '/' . $name, IFileInfo::MODE_READONLY);
$info = $this->share->stat($this->root . '/' . $name);
$this->assertTrue($info->isReadOnly());
$this->assertFalse($info->isArchived());
$this->assertFalse($info->isSystem());
$this->assertFalse($info->isHidden());
$this->share->setMode($this->root . '/' . $name, FileInfo::MODE_ARCHIVE);
$this->share->setMode($this->root . '/' . $name, IFileInfo::MODE_ARCHIVE);
$info = $this->share->stat($this->root . '/' . $name);
$this->assertFalse($info->isReadOnly());
$this->assertTrue($info->isArchived());
$this->assertFalse($info->isSystem());
$this->assertFalse($info->isHidden());
$this->share->setMode($this->root . '/' . $name, FileInfo::MODE_READONLY | FileInfo::MODE_ARCHIVE);
$this->share->setMode($this->root . '/' . $name, IFileInfo::MODE_READONLY | IFileInfo::MODE_ARCHIVE);
$info = $this->share->stat($this->root . '/' . $name);
$this->assertTrue($info->isReadOnly());
$this->assertTrue($info->isArchived());
$this->assertFalse($info->isSystem());
$this->assertFalse($info->isHidden());
$this->share->setMode($this->root . '/' . $name, FileInfo::MODE_HIDDEN);
$this->share->setMode($this->root . '/' . $name, IFileInfo::MODE_HIDDEN);
$info = $this->share->stat($this->root . '/' . $name);
$this->assertFalse($info->isReadOnly());
$this->assertFalse($info->isArchived());
$this->assertFalse($info->isSystem());
$this->assertTrue($info->isHidden());
$this->share->setMode($this->root . '/' . $name, FileInfo::MODE_SYSTEM);
$this->share->setMode($this->root . '/' . $name, IFileInfo::MODE_SYSTEM);
$info = $this->share->stat($this->root . '/' . $name);
$this->assertFalse($info->isReadOnly());
$this->assertFalse($info->isArchived());
$this->assertTrue($info->isSystem());
$this->assertFalse($info->isHidden());
$this->share->setMode($this->root . '/' . $name, FileInfo::MODE_NORMAL);
$this->share->setMode($this->root . '/' . $name, IFileInfo::MODE_NORMAL);
$info = $this->share->stat($this->root . '/' . $name);
$this->assertFalse($info->isReadOnly());
$this->assertFalse($info->isArchived());

View file

@ -7,16 +7,27 @@
namespace Icewind\SMB\Test;
use Icewind\SMB\NativeServer;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\Native\NativeServer;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
class NativeShareTestTest extends AbstractShareTest {
class NativeShareTest extends AbstractShareTest {
public function setUp() {
$this->requireBackendEnv('libsmbclient');
if (!function_exists('smbclient_state_new')) {
$this->markTestSkipped('libsmbclient php extension not installed');
}
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
$this->server = new NativeServer($this->config->host, $this->config->user, $this->config->password);
$this->server = new NativeServer(
$this->config->host,
new BasicAuth(
$this->config->user,
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
);
$this->share = $this->server->getShare($this->config->share);
if ($this->config->root) {
$this->root = '/' . $this->config->root . '/' . uniqid();

View file

@ -7,16 +7,19 @@
namespace Icewind\SMB\Test;
use Icewind\SMB\NativeServer;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\Native\NativeServer;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
class NativeStreamTest extends TestCase {
/**
* @var \Icewind\SMB\Server $server
* @var \Icewind\SMB\IServer $server
*/
protected $server;
/**
* @var \Icewind\SMB\NativeShare $share
* @var \Icewind\SMB\Native\NativeShare $share
*/
protected $share;
@ -33,7 +36,15 @@ class NativeStreamTest extends TestCase {
$this->markTestSkipped('libsmbclient php extension not installed');
}
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
$this->server = new NativeServer($this->config->host, $this->config->user, $this->config->password);
$this->server = new NativeServer(
$this->config->host,
new BasicAuth(
$this->config->user,
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
);
$this->share = $this->server->getShare($this->config->share);
if ($this->config->root) {
$this->root = '/' . $this->config->root . '/' . uniqid();

View file

@ -7,10 +7,14 @@
namespace Icewind\SMB\Test;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\Change;
use Icewind\SMB\Exception\AlreadyExistsException;
use Icewind\SMB\INotifyHandler;
use Icewind\SMB\IShare;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
use Icewind\SMB\Wrapped\Server;
class NotifyHandlerTest extends TestCase {
/**
@ -23,7 +27,15 @@ class NotifyHandlerTest extends TestCase {
public function setUp() {
$this->requireBackendEnv('smbclient');
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
$this->server = new \Icewind\SMB\Server($this->config->host, $this->config->user, $this->config->password);
$this->server = new Server(
$this->config->host,
new BasicAuth(
$this->config->user,
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
);
}
/**

View file

@ -8,19 +8,20 @@
namespace Icewind\SMB\Test;
use Icewind\SMB\FileInfo;
use Icewind\SMB\IFileInfo;
use Icewind\SMB\Wrapped\FileInfo;
class ParserTest extends \PHPUnit_Framework_TestCase {
public function modeProvider() {
return array(
array('D', FileInfo::MODE_DIRECTORY),
array('A', FileInfo::MODE_ARCHIVE),
array('S', FileInfo::MODE_SYSTEM),
array('H', FileInfo::MODE_HIDDEN),
array('R', FileInfo::MODE_READONLY),
array('N', FileInfo::MODE_NORMAL),
array('RA', FileInfo::MODE_READONLY | FileInfo::MODE_ARCHIVE),
array('RAH', FileInfo::MODE_READONLY | FileInfo::MODE_ARCHIVE | FileInfo::MODE_HIDDEN)
array('D', IFileInfo::MODE_DIRECTORY),
array('A', IFileInfo::MODE_ARCHIVE),
array('S', IFileInfo::MODE_SYSTEM),
array('H', IFileInfo::MODE_HIDDEN),
array('R', IFileInfo::MODE_READONLY),
array('N', IFileInfo::MODE_NORMAL),
array('RA', IFileInfo::MODE_READONLY | IFileInfo::MODE_ARCHIVE),
array('RAH', IFileInfo::MODE_READONLY | IFileInfo::MODE_ARCHIVE | IFileInfo::MODE_HIDDEN)
);
}
@ -42,7 +43,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
* @dataProvider modeProvider
*/
public function testParseMode($string, $mode) {
$parser = new \Icewind\SMB\Parser($this->getTimeZoneProvider('UTC'));
$parser = new \Icewind\SMB\Wrapped\Parser($this->getTimeZoneProvider('UTC'));
$this->assertEquals($mode, $parser->parseMode($string), 'Failed parsing ' . $string);
}
@ -60,7 +61,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
),
array(
'mtime' => strtotime('12 Oct 2013 19:05:58 CEST'),
'mode' => FileInfo::MODE_NORMAL,
'mode' => IFileInfo::MODE_NORMAL,
'size' => 29634
)
),
@ -76,7 +77,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
),
array(
'mtime' => strtotime('12 Oct 2013 19:05:58 CEST'),
'mode' => FileInfo::MODE_DIRECTORY,
'mode' => IFileInfo::MODE_DIRECTORY,
'size' => 29634
)
),
@ -92,7 +93,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
),
array(
'mtime' => strtotime('12 Oct 2013 19:05:58 CEST'),
'mode' => FileInfo::MODE_HIDDEN + FileInfo::MODE_ARCHIVE,
'mode' => IFileInfo::MODE_HIDDEN + IFileInfo::MODE_ARCHIVE,
'size' => 29634
)
)
@ -103,7 +104,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
* @dataProvider statProvider
*/
public function testStat($output, $stat) {
$parser = new \Icewind\SMB\Parser($this->getTimeZoneProvider('UTC'));
$parser = new \Icewind\SMB\Wrapped\Parser($this->getTimeZoneProvider('UTC'));
$this->assertEquals($stat, $parser->parseStat($output));
}
@ -119,7 +120,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
),
array(
new FileInfo('/c.pdf', 'c.pdf', 29634, strtotime('12 Oct 2013 19:05:58 CEST'),
FileInfo::MODE_NORMAL)
IFileInfo::MODE_NORMAL)
)
)
);
@ -129,7 +130,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
* @dataProvider dirProvider
*/
public function testDir($output, $dir) {
$parser = new \Icewind\SMB\Parser($this->getTimeZoneProvider('CEST'));
$parser = new \Icewind\SMB\Wrapped\Parser($this->getTimeZoneProvider('CEST'));
$this->assertEquals($dir, $parser->parseDir($output, ''));
}
}

View file

@ -7,9 +7,14 @@
namespace Icewind\SMB\Test;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
use Icewind\SMB\Wrapped\Server;
class ServerTest extends TestCase {
/**
* @var \Icewind\SMB\Server $server
* @var \Icewind\SMB\Wrapped\Server $server
*/
private $server;
@ -18,7 +23,15 @@ class ServerTest extends TestCase {
public function setUp() {
$this->requireBackendEnv('smbclient');
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
$this->server = new \Icewind\SMB\Server($this->config->host, $this->config->user, $this->config->password);
$this->server = new Server(
$this->config->host,
new BasicAuth(
$this->config->user,
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
);
}
public function testListShares() {
@ -36,7 +49,15 @@ class ServerTest extends TestCase {
*/
public function testWrongUserName() {
$this->markTestSkipped('This fails for no reason on travis');
$server = new \Icewind\SMB\Server($this->config->host, uniqid(), uniqid());
$server = new Server(
$this->config->host,
new BasicAuth(
uniqid(),
uniqid()
),
new System(),
new TimeZoneProvider($this->config->host, new System())
);
$server->listShares();
}
@ -44,7 +65,15 @@ class ServerTest extends TestCase {
* @expectedException \Icewind\SMB\Exception\AuthenticationException
*/
public function testWrongPassword() {
$server = new \Icewind\SMB\Server($this->config->host, $this->config->user, uniqid());
$server = new Server(
$this->config->host,
new BasicAuth(
$this->config->user,
uniqid()
),
new System(),
new TimeZoneProvider($this->config->host, new System())
);
$server->listShares();
}
@ -52,7 +81,15 @@ class ServerTest extends TestCase {
* @expectedException \Icewind\SMB\Exception\InvalidHostException
*/
public function testWrongHost() {
$server = new \Icewind\SMB\Server(uniqid(), $this->config->user, $this->config->password);
$server = new Server(
uniqid(),
new BasicAuth(
$this->config->user,
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
);
$server->listShares();
}
@ -61,7 +98,15 @@ class ServerTest extends TestCase {
* @expectedException \Icewind\SMB\Exception\InvalidHostException
*/
public function testHostEscape() {
$server = new \Icewind\SMB\Server($this->config->host . ';asd', $this->config->user, $this->config->password);
$server = new Server(
$this->config->host . ';asd',
new BasicAuth(
$this->config->user,
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
);
$server->listShares();
}
}

View file

@ -7,13 +7,24 @@
namespace Icewind\SMB\Test;
use Icewind\SMB\Server as NormalServer;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
use Icewind\SMB\Wrapped\Server as NormalServer;
class ShareTestTest extends AbstractShareTest {
class ShareTest extends AbstractShareTest {
public function setUp() {
$this->requireBackendEnv('smbclient');
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
$this->server = new NormalServer($this->config->host, $this->config->user, $this->config->password);
$this->server = new NormalServer(
$this->config->host,
new BasicAuth(
$this->config->user,
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
);
$this->share = $this->server->getShare($this->config->share);
if ($this->config->root) {
$this->root = '/' . $this->config->root . '/' . uniqid();
@ -29,24 +40,16 @@ class ShareTestTest extends AbstractShareTest {
public function testHostEscape() {
$this->requireBackendEnv('smbclient');
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
$this->server = new NormalServer($this->config->host . ';asd', $this->config->user, $this->config->password);
$this->server = new NormalServer(
$this->config->host . ';asd',
new BasicAuth(
$this->config->user,
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
);
$share = $this->server->getShare($this->config->share);
$share->dir($this->root);
}
/**
* @expectedException \Icewind\SMB\Exception\DependencyException
*/
public function testNoSmbclient() {
$system = $this->getMockBuilder('\Icewind\SMB\System')
->setMethods(['getSmbclientPath'])
->getMock();
$share = new \Icewind\SMB\Share($this->server, 'dummy', $system);
$system->expects($this->any())
->method('getSmbclientPath')
->will($this->returnValue(''));
$share->mkdir('');
}
}