This repository has been archived by the owner on Aug 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the ftp-library package. | ||
* | ||
* (c) 2018 WEBEWEB | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace WBW\Library\Ftp\Security; | ||
|
||
use WBW\Library\Traits\Integers\IntegerPortTrait; | ||
use WBW\Library\Traits\Strings\StringHostnameTrait; | ||
|
||
/** | ||
* Authenticator. | ||
* | ||
* @author webeweb <https://github.com/webeweb/> | ||
* @package WBW\Library\Ftp\Security | ||
*/ | ||
class Authenticator { | ||
|
||
use IntegerPortTrait; | ||
use StringHostnameTrait; | ||
|
||
/** | ||
* Password authentication. | ||
* | ||
* @var PasswordAuthentication | ||
*/ | ||
private $passwordAuthentication; | ||
|
||
/** | ||
* Scheme. | ||
* | ||
* @var string|null | ||
*/ | ||
private $scheme; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param string|null $hostname The hostname. | ||
* @param PasswordAuthentication $passwordAuthentication | ||
*/ | ||
public function __construct(?string $hostname, PasswordAuthentication $passwordAuthentication) { | ||
$this->setHostname($hostname); | ||
$this->setPasswordAuthentication($passwordAuthentication); | ||
} | ||
|
||
/** | ||
* Get the password authentication. | ||
* | ||
* @return PasswordAuthentication Returns the password authentication. | ||
*/ | ||
public function getPasswordAuthentication(): PasswordAuthentication { | ||
return $this->passwordAuthentication; | ||
} | ||
|
||
/** | ||
* Get the scheme. | ||
* | ||
* @return string|null Returns the scheme. | ||
*/ | ||
public function getScheme(): ?string { | ||
return $this->scheme; | ||
} | ||
|
||
/** | ||
* Set the password authenticator. | ||
* | ||
* @param PasswordAuthentication $passwordAuthentication The password authentication. | ||
* @return Authenticator Returns this authenticator. | ||
*/ | ||
public function setPasswordAuthentication(PasswordAuthentication $passwordAuthentication): Authenticator { | ||
$this->passwordAuthentication = $passwordAuthentication; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Set the scheme. | ||
* | ||
* @param string|null $scheme The scheme. | ||
* @return Authenticator Returns this authenticator. | ||
*/ | ||
public function setScheme(?string $scheme): Authenticator { | ||
$this->scheme = $scheme; | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the ftp-library package. | ||
* | ||
* (c) 2018 WEBEWEB | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace WBW\Library\Ftp\Tests\Security; | ||
|
||
use WBW\Library\Ftp\Security\Authenticator; | ||
use WBW\Library\Ftp\Security\PasswordAuthentication; | ||
use WBW\Library\Ftp\Tests\AbstractTestCase; | ||
|
||
/** | ||
* Authenticator test. | ||
* | ||
* @author webeweb <https://github.com/webeweb/> | ||
* @package WBW\Library\Ftp\Tests\Security | ||
*/ | ||
class AuthenticatorTest extends AbstractTestCase { | ||
|
||
/** | ||
* Tests the setPasswordAuthentication() method. | ||
* | ||
* @return void | ||
*/ | ||
public function testSetPasswordAuthentication(): void { | ||
|
||
$obj = new Authenticator(null, $this->passwordAuthentication); | ||
|
||
$obj->setPasswordAuthentication(new PasswordAuthentication(null, null)); | ||
$this->assertNull($obj->getPasswordAuthentication()->getUsername()); | ||
$this->assertNull($obj->getPasswordAuthentication()->getPassword()); | ||
} | ||
|
||
/** | ||
* Tests the setScheme() method. | ||
* | ||
* @return void | ||
*/ | ||
public function testSetScheme(): void { | ||
|
||
$obj = new Authenticator(null, $this->passwordAuthentication); | ||
|
||
$obj->setScheme("scheme"); | ||
$this->assertEquals("scheme", $obj->getScheme()); | ||
} | ||
|
||
/** | ||
* Tests the __construct() method. | ||
* | ||
* @return void | ||
*/ | ||
public function test__construct(): void { | ||
|
||
$obj = new Authenticator(null, $this->passwordAuthentication); | ||
|
||
$this->assertNull($obj->getHostname()); | ||
$this->assertSame($this->passwordAuthentication, $obj->getPasswordAuthentication()); | ||
$this->assertNull($obj->getPort()); | ||
$this->assertNull($obj->getScheme()); | ||
} | ||
} |