Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Add Authenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
webeweb committed Jul 16, 2021
1 parent e5f29e8 commit aa75804
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 0 deletions.
92 changes: 92 additions & 0 deletions src/Security/Authenticator.php
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;
}
}
67 changes: 67 additions & 0 deletions tests/Security/AuthenticatorTest.php
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());
}
}

0 comments on commit aa75804

Please sign in to comment.