mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 09:14:06 +02:00
update wrong auth test
This commit is contained in:
parent
e4f0be4edb
commit
02e848852f
4 changed files with 55 additions and 62 deletions
|
|
@ -8,6 +8,8 @@
|
||||||
namespace Icewind\SMB\Test;
|
namespace Icewind\SMB\Test;
|
||||||
|
|
||||||
use Icewind\SMB\ACL;
|
use Icewind\SMB\ACL;
|
||||||
|
use Icewind\SMB\BasicAuth;
|
||||||
|
use Icewind\SMB\Exception\AccessDeniedException;
|
||||||
use Icewind\SMB\Exception\AlreadyExistsException;
|
use Icewind\SMB\Exception\AlreadyExistsException;
|
||||||
use Icewind\SMB\Exception\FileInUseException;
|
use Icewind\SMB\Exception\FileInUseException;
|
||||||
use Icewind\SMB\Exception\InvalidPathException;
|
use Icewind\SMB\Exception\InvalidPathException;
|
||||||
|
|
@ -15,10 +17,12 @@ use Icewind\SMB\Exception\InvalidResourceException;
|
||||||
use Icewind\SMB\Exception\InvalidTypeException;
|
use Icewind\SMB\Exception\InvalidTypeException;
|
||||||
use Icewind\SMB\Exception\NotEmptyException;
|
use Icewind\SMB\Exception\NotEmptyException;
|
||||||
use Icewind\SMB\Exception\NotFoundException;
|
use Icewind\SMB\Exception\NotFoundException;
|
||||||
use Icewind\SMB\FileInfo;
|
|
||||||
use Icewind\SMB\IFileInfo;
|
use Icewind\SMB\IFileInfo;
|
||||||
|
use Icewind\SMB\IOptions;
|
||||||
use Icewind\SMB\IShare;
|
use Icewind\SMB\IShare;
|
||||||
|
use Icewind\SMB\Options;
|
||||||
use Icewind\SMB\System;
|
use Icewind\SMB\System;
|
||||||
|
use Icewind\SMB\TimeZoneProvider;
|
||||||
|
|
||||||
abstract class AbstractShareTest extends TestCase {
|
abstract class AbstractShareTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,6 +42,34 @@ abstract class AbstractShareTest extends TestCase {
|
||||||
|
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
abstract public function getServerClass(): string;
|
||||||
|
|
||||||
|
public function setUp(): void {
|
||||||
|
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
|
||||||
|
$options = new Options();
|
||||||
|
$options->setMinProtocol(IOptions::PROTOCOL_SMB2);
|
||||||
|
$options->setMaxProtocol(IOptions::PROTOCOL_SMB3);
|
||||||
|
$serverClass = $this->getServerClass();
|
||||||
|
$this->server = new $serverClass(
|
||||||
|
$this->config->host,
|
||||||
|
new BasicAuth(
|
||||||
|
$this->config->user,
|
||||||
|
'test',
|
||||||
|
$this->config->password
|
||||||
|
),
|
||||||
|
new System(),
|
||||||
|
new TimeZoneProvider(new System()),
|
||||||
|
$options
|
||||||
|
);
|
||||||
|
$this->share = $this->server->getShare($this->config->share);
|
||||||
|
if ($this->config->root) {
|
||||||
|
$this->root = '/' . $this->config->root . '/' . uniqid();
|
||||||
|
} else {
|
||||||
|
$this->root = '/' . uniqid();
|
||||||
|
}
|
||||||
|
$this->share->mkdir($this->root);
|
||||||
|
}
|
||||||
|
|
||||||
public function tearDown(): void {
|
public function tearDown(): void {
|
||||||
try {
|
try {
|
||||||
if ($this->share) {
|
if ($this->share) {
|
||||||
|
|
@ -729,4 +761,22 @@ abstract class AbstractShareTest extends TestCase {
|
||||||
$this->assertEquals($acl->getType(), ACL::TYPE_ALLOW);
|
$this->assertEquals($acl->getType(), ACL::TYPE_ALLOW);
|
||||||
$this->assertEquals(ACL::MASK_READ, $acl->getMask() & ACL::MASK_READ);
|
$this->assertEquals(ACL::MASK_READ, $acl->getMask() & ACL::MASK_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testWrongUserName() {
|
||||||
|
$this->expectException(AccessDeniedException::class);
|
||||||
|
$serverClass = $this->getServerClass();
|
||||||
|
$server = new $serverClass(
|
||||||
|
$this->config->host,
|
||||||
|
new BasicAuth(
|
||||||
|
uniqid(),
|
||||||
|
'test',
|
||||||
|
uniqid()
|
||||||
|
),
|
||||||
|
new System(),
|
||||||
|
new TimeZoneProvider(new System()),
|
||||||
|
new Options()
|
||||||
|
);
|
||||||
|
$share = $server->getShare($this->config->share);
|
||||||
|
$share->dir("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,33 +17,12 @@ use Icewind\SMB\System;
|
||||||
use Icewind\SMB\TimeZoneProvider;
|
use Icewind\SMB\TimeZoneProvider;
|
||||||
|
|
||||||
class NativeShareTest extends AbstractShareTest {
|
class NativeShareTest extends AbstractShareTest {
|
||||||
public function setUp(): void {
|
public function getServerClass(): string {
|
||||||
$this->requireBackendEnv('libsmbclient');
|
$this->requireBackendEnv('libsmbclient');
|
||||||
if (!function_exists('smbclient_state_new')) {
|
if (!function_exists('smbclient_state_new')) {
|
||||||
$this->markTestSkipped('libsmbclient php extension not installed');
|
$this->markTestSkipped('libsmbclient php extension not installed');
|
||||||
}
|
}
|
||||||
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
|
return NativeServer::class;
|
||||||
$options = new Options();
|
|
||||||
$options->setMinProtocol(IOptions::PROTOCOL_SMB2);
|
|
||||||
$options->setMaxProtocol(IOptions::PROTOCOL_SMB3);
|
|
||||||
$this->server = new NativeServer(
|
|
||||||
$this->config->host,
|
|
||||||
new BasicAuth(
|
|
||||||
$this->config->user,
|
|
||||||
'test',
|
|
||||||
$this->config->password
|
|
||||||
),
|
|
||||||
new System(),
|
|
||||||
new TimeZoneProvider(new System()),
|
|
||||||
$options
|
|
||||||
);
|
|
||||||
$this->share = $this->server->getShare($this->config->share);
|
|
||||||
if ($this->config->root) {
|
|
||||||
$this->root = '/' . $this->config->root . '/' . uniqid();
|
|
||||||
} else {
|
|
||||||
$this->root = '/' . uniqid();
|
|
||||||
}
|
|
||||||
$this->share->mkdir($this->root);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testProtocolMatch() {
|
public function testProtocolMatch() {
|
||||||
|
|
|
||||||
|
|
@ -51,22 +51,6 @@ class ServerTest extends TestCase {
|
||||||
$this->assertContains($this->config->share, $names);
|
$this->assertContains($this->config->share, $names);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWrongUserName() {
|
|
||||||
$this->expectException(AuthenticationException::class);
|
|
||||||
$server = new Server(
|
|
||||||
$this->config->host,
|
|
||||||
new BasicAuth(
|
|
||||||
uniqid(),
|
|
||||||
'test',
|
|
||||||
uniqid()
|
|
||||||
),
|
|
||||||
new System(),
|
|
||||||
new TimeZoneProvider(new System()),
|
|
||||||
new Options()
|
|
||||||
);
|
|
||||||
$server->listShares();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testWrongPassword() {
|
public function testWrongPassword() {
|
||||||
$this->expectException(AuthenticationException::class);
|
$this->expectException(AuthenticationException::class);
|
||||||
$server = new Server(
|
$server = new Server(
|
||||||
|
|
@ -165,8 +149,6 @@ class ServerTest extends TestCase {
|
||||||
$this->markTestSkipped("Server seems to accept NT1 connections");
|
$this->markTestSkipped("Server seems to accept NT1 connections");
|
||||||
} catch (ConnectionRefusedException $e) {
|
} catch (ConnectionRefusedException $e) {
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->fail("Wrong exception");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,27 +16,9 @@ use Icewind\SMB\TimeZoneProvider;
|
||||||
use Icewind\SMB\Wrapped\Server as NormalServer;
|
use Icewind\SMB\Wrapped\Server as NormalServer;
|
||||||
|
|
||||||
class ShareTest extends AbstractShareTest {
|
class ShareTest extends AbstractShareTest {
|
||||||
public function setUp(): void {
|
public function getServerClass(): string {
|
||||||
$this->requireBackendEnv('smbclient');
|
$this->requireBackendEnv('smbclient');
|
||||||
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
|
return NormalServer::class;
|
||||||
$this->server = new NormalServer(
|
|
||||||
$this->config->host,
|
|
||||||
new BasicAuth(
|
|
||||||
$this->config->user,
|
|
||||||
'test',
|
|
||||||
$this->config->password
|
|
||||||
),
|
|
||||||
new System(),
|
|
||||||
new TimeZoneProvider(new System()),
|
|
||||||
new Options()
|
|
||||||
);
|
|
||||||
$this->share = $this->server->getShare($this->config->share);
|
|
||||||
if ($this->config->root) {
|
|
||||||
$this->root = '/' . $this->config->root . '/' . uniqid();
|
|
||||||
} else {
|
|
||||||
$this->root = '/' . uniqid();
|
|
||||||
}
|
|
||||||
$this->share->mkdir($this->root);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAppendStream() {
|
public function testAppendStream() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue