mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
split test cases
This commit is contained in:
parent
78916cfc08
commit
c94eea8294
4 changed files with 59 additions and 15 deletions
|
|
@ -14,6 +14,6 @@ spl_autoload_register(function ($class) {
|
||||||
if (substr($class, 0, 4) == 'SMB\\') {
|
if (substr($class, 0, 4) == 'SMB\\') {
|
||||||
$class = strtolower($class);
|
$class = strtolower($class);
|
||||||
$file = str_replace('\\', '/', substr($class, 4));
|
$file = str_replace('\\', '/', substr($class, 4));
|
||||||
include $file . '.php';
|
include __DIR__ . '/' . $file . '.php';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -78,12 +78,26 @@ class Server {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Share[]
|
* @return Share[]
|
||||||
|
* @throws AuthenticationException
|
||||||
|
* @throws InvalidHostException
|
||||||
*/
|
*/
|
||||||
public function listShares() {
|
public function listShares() {
|
||||||
$auth = escapeshellarg($this->getAuthString()); //TODO: don't pass password as shell argument
|
$auth = escapeshellarg($this->getAuthString()); //TODO: don't pass password as shell argument
|
||||||
$command = self::CLIENT . ' -N -U ' . $auth . ' ' . '-gL ' . escapeshellarg($this->getHost());// . ' 2> /dev/null';
|
$command = self::CLIENT . ' -N -U ' . $auth . ' ' . '-gL ' . escapeshellarg($this->getHost()); // . ' 2> /dev/null';
|
||||||
exec($command, $output);
|
exec($command, $output);
|
||||||
|
|
||||||
|
$line = $output[0];
|
||||||
|
$authError = 'NT_STATUS_LOGON_FAILURE';
|
||||||
|
if (substr($line, -23) === $authError) {
|
||||||
|
$this->pipes = array(null, null);
|
||||||
|
throw new AuthenticationException();
|
||||||
|
}
|
||||||
|
$addressError = 'NT_STATUS_BAD_NETWORK_NAME';
|
||||||
|
if (substr($line, -26) === $addressError) {
|
||||||
|
$this->pipes = array(null, null);
|
||||||
|
throw new InvalidHostException();
|
||||||
|
}
|
||||||
|
|
||||||
$shareNames = array();
|
$shareNames = array();
|
||||||
foreach ($output as $line) {
|
foreach ($output as $line) {
|
||||||
if (strpos($line, '|')) {
|
if (strpos($line, '|')) {
|
||||||
|
|
|
||||||
35
tests/server.php
Normal file
35
tests/server.php
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SMB\Test;
|
||||||
|
|
||||||
|
class Server extends \PHPUnit_Framework_TestCase {
|
||||||
|
/**
|
||||||
|
* @var \SMB\Server $server
|
||||||
|
*/
|
||||||
|
private $server;
|
||||||
|
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
|
||||||
|
$this->server = new \SMB\Server($this->config->host, $this->config->user, $this->config->password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListShares() {
|
||||||
|
$shares = $this->server->listShares();
|
||||||
|
foreach ($shares as $share) {
|
||||||
|
if ($share->getName() === $this->config->share) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->fail('Share "' . $this->config->share . '" not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \SMB\AuthenticationException
|
||||||
|
*/
|
||||||
|
public function testWrongUserName() {
|
||||||
|
$server = new \SMB\Server($this->config->host, uniqid(), $this->config->password);
|
||||||
|
$server->listShares();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Test extends PHPUnit_Framework_TestCase {
|
namespace SMB\Test;
|
||||||
|
|
||||||
|
class Share extends \PHPUnit_Framework_TestCase {
|
||||||
/**
|
/**
|
||||||
* @var SMB\Server $server
|
* @var \SMB\Server $server
|
||||||
*/
|
*/
|
||||||
private $server;
|
private $server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var SMB\Share $share
|
* @var \SMB\Share $share
|
||||||
*/
|
*/
|
||||||
private $share;
|
private $share;
|
||||||
|
|
||||||
|
|
@ -18,17 +20,16 @@ class Test extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
private $needsCleanup = false;
|
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
|
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
|
||||||
$this->server = new SMB\Server($this->config->host, $this->config->user, $this->config->password);
|
$this->server = new \SMB\Server($this->config->host, $this->config->user, $this->config->password);
|
||||||
$this->share = $this->server->getShare($this->config->share);
|
$this->share = $this->server->getShare($this->config->share);
|
||||||
$this->root = '/' . uniqid();
|
$this->root = '/' . uniqid();
|
||||||
|
$this->share->mkdir($this->root);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
if ($this->share and $this->needsCleanup) {
|
if ($this->share) {
|
||||||
$this->share->rmdir($this->root);
|
$this->share->rmdir($this->root);
|
||||||
}
|
}
|
||||||
unset($this->share);
|
unset($this->share);
|
||||||
|
|
@ -45,8 +46,6 @@ class Test extends PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDirectory() {
|
public function testDirectory() {
|
||||||
$this->share->mkdir($this->root);
|
|
||||||
$this->needsCleanup = true;
|
|
||||||
$this->assertEquals(array(), $this->share->dir($this->root));
|
$this->assertEquals(array(), $this->share->dir($this->root));
|
||||||
|
|
||||||
$this->share->mkdir($this->root . '/foo');
|
$this->share->mkdir($this->root . '/foo');
|
||||||
|
|
@ -65,8 +64,6 @@ class Test extends PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFile() {
|
public function testFile() {
|
||||||
$this->share->mkdir($this->root);
|
|
||||||
$this->needsCleanup = true;
|
|
||||||
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
|
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
|
||||||
$size = strlen($text);
|
$size = strlen($text);
|
||||||
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
$tmpFile1 = tempnam('/tmp', 'smb_test_');
|
||||||
|
|
@ -97,8 +94,6 @@ class Test extends PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEscaping() {
|
public function testEscaping() {
|
||||||
$this->share->mkdir($this->root);
|
|
||||||
$this->needsCleanup = true;
|
|
||||||
// / ? < > \ : * | ” are illegal characters in path on windows, no use trying to get them working
|
// / ? < > \ : * | ” are illegal characters in path on windows, no use trying to get them working
|
||||||
$names = array('simple', 'with spaces', "single'quote'", '$as#d', '€', '££Ö€ßœĚęĘĞĜΣΥΦΩΫΫ');
|
$names = array('simple', 'with spaces', "single'quote'", '$as#d', '€', '££Ö€ßœĚęĘĞĜΣΥΦΩΫΫ');
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue