LICENSE 0000755 00000002066 14002573567 0005571 0 ustar 00 The MIT License (MIT)
Copyright (c) 2013 Oliver Vogel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. README.md 0000755 00000003563 14002573567 0006046 0 ustar 00 # Intervention HttpAuth
Library to manage HTTP authentication with PHP. Includes ServiceProviders for easy Laravel integration.
[![Latest Version](https://img.shields.io/packagist/v/intervention/httpauth.svg)](https://packagist.org/packages/intervention/httpauth)
![build](https://github.com/Intervention/httpauth/workflows/build/badge.svg)
[![Monthly Downloads](https://img.shields.io/packagist/dm/intervention/httpauth.svg)](https://packagist.org/packages/intervention/httpauth/stats)
## Installation
You can install this package quick and easy with Composer.
Require the package via Composer:
$ composer require intervention/httpauth
### Laravel integration (optional)
The HttpAuth library is built to work with the Laravel Framework (>=5.5). It comes with a service provider and facades, which will be discovered automatically after installation.
## Usage
To create HTTP authentication instances you can choose between different methods.
### Static instantiation by array
```php
use Intervention\HttpAuth\HttpAuth;
// create basic auth by array
$auth = HttpAuth::make([
'type' => 'basic',
'realm' => 'Secure Resource',
'username' => 'admin',
'password' => 'secret',
]);
```
### Instantiation by calls
```php
use Intervention\HttpAuth\HttpAuth;
// create digest auth
$auth = HttpAuth::make();
$auth->digest();
$auth->realm('Secure');
$auth->username('admin');
$auth->password('secret');
```
### Ask user for credentials
After you created a HTTP authentication instance, you have to call `secure()` to ask for credentials.
```php
$auth->secure();
```
## Server Configuration
### Apache
If you are using Apache and running php with fast-cgi, check setting headers:
https://support.deskpro.com/en/kb/articles/missing-authorization-headers-with-apache
## License
Intervention HttpAuth Class is licensed under the [MIT License](http://opensource.org/licenses/MIT).
.github/workflows/build.yml 0000644 00000001336 14002573567 0011777 0 ustar 00 name: build
on: [push]
jobs:
run:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0']
name: Testing on PHP ${{ matrix.php-versions }}
steps:
- uses: actions/checkout@v2
- name: setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring,bcmath
tools: phpunit,composer
- name: install deps
run: composer install -o -q
- name: run phpunit
run: vendor/bin/phpunit
- name: run phpstan
run: composer require --dev illuminate/support && vendor/bin/phpstan analyze --no-progress --autoload-file=tests/phpstan/bootstrap.php --level=5 src/ phpunit.xml 0000755 00000001035 14002573567 0006770 0 ustar 00
./tests/
src/Environment.php 0000644 00000002276 14002573567 0010370 0 ustar 00 tokenClassnames as $classname) {
if ($auth = $this->getActiveTokenOrNull($classname)) {
return $auth;
}
}
return new Token\NullToken();
}
/**
* Try to parse auth token from given classname. Returns token object
* if token is active and could be parsed or null.
*
* @param string $classname
* @return TokenInterface|null
*/
private function getActiveTokenOrNull($classname)
{
try {
$auth = new $classname();
} catch (Exception $e) {
$auth = null;
}
return $auth;
}
}
src/TokenInterface.php 0000644 00000000302 14002573567 0010751 0 ustar 00 'basic',
/*
|--------------------------------------------------------------------------
| Authentication name
|--------------------------------------------------------------------------
|
| Name of secured resource. Clients must authentificate to each named realm.
|
*/
'realm' => 'Secured',
/*
|--------------------------------------------------------------------------
| Authentication username
|--------------------------------------------------------------------------
|
| Username to access the secured realm in combination with a password.
|
*/
'username' => 'admin',
/*
|--------------------------------------------------------------------------
| Password
|--------------------------------------------------------------------------
|
| Password to access the secured realm in combination with the username.
|
*/
'password' => '1234'
];
src/AbstractVault.php 0000644 00000011316 14002573567 0010636 0 ustar 00 checkParameterValidity([
'realm' => $realm,
'username' => $username,
'password' => $password,
]);
$this->environment = new Environment();
$this->realm = $realm;
$this->username = $username;
$this->password = $password;
}
/**
* Throw exception if any of the given parameters are empty
*
* @param array $parameters
* @return void
*/
private function checkParameterValidity(array $parameters): void
{
foreach ($parameters as $key => $value) {
if (empty($value)) {
throw new Exception\InvalidParameterException(
'Cannot create HTTP authentication vault. Parameter "' . $key . '" cannot be empty.'
);
}
}
}
/**
* Return key from current token
*
* @return Key
*/
public function getKey(): Key
{
return $this->environment->getToken()->toKey();
}
/**
* Denies access for non-authenticated users
*
* @return void
*/
public function secure(): void
{
if (! $this->unlocksWithKey($this->getKey())) {
$this->denyAccess();
}
}
/**
* Set name of realm
*
* @param string $realm
* @return AbstractVault
*/
public function setRealm($realm): AbstractVault
{
$this->realm = $realm;
return $this;
}
/**
* Alias for setRealm()
*
* @param string $realm
* @return AbstractVault
*/
public function realm($realm): AbstractVault
{
return $this->setRealm($realm);
}
/**
* Return current realm name
*
* @return string
*/
public function getRealm()
{
return $this->realm;
}
/**
* Set username for current vault
*
* @param string $username
*/
public function setUsername($username): AbstractVault
{
$this->username = $username;
return $this;
}
/**
* Alias for setUsername()
*
* @param string $username
*/
public function username($username): AbstractVault
{
return $this->setUsername($username);
}
/**
* Return current username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set password for current vault
*
* @param string $password
* @return AbstractVault
*/
public function setPassword($password): AbstractVault
{
$this->password = $password;
return $this;
}
/**
* Alias for setPassword()
*
* @param string $password
* @return AbstractVault
*/
public function password($password): AbstractVault
{
return $this->setPassword($password);
}
/**
* Return current password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set username and password at once
*
* @param string $username
* @param string $password
* @return AbstractVault
*/
public function credentials($username, $password): AbstractVault
{
return $this->setUsername($username)->setPassword($password);
}
/**
* Sends HTTP 401 Header
*
* @return void
*/
protected function denyAccess(): void
{
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
header($protocol . ' Unauthorized');
header('WWW-Authenticate: ' . (string) $this->getDirective());
exit('' . $protocol . ' 401 Unauthorized');
}
}
src/Directive.php 0000644 00000003243 14002573567 0007775 0 ustar 00 type = $type;
$this->parameters = $parameters;
}
/**
* Format current instance
*
* @return string
*/
public function format(): string
{
return sprintf(
'%s %s',
ucfirst(strtolower($this->type)),
$this->getParametersString()
);
}
/**
* Return current type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Return value of given key from all parameters, if existing
*
* @param mixed $key
* @return mixed
*/
public function getParameter($key)
{
return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : null;
}
/**
* Format current parameters as string
*
* @return string
*/
private function getParametersString(): string
{
return implode(', ', array_map(function ($key, $value) {
return sprintf('%s="%s"', $key, $value);
}, array_keys($this->parameters), $this->parameters));
}
/**
* Cast object to string
*
* @return string
*/
public function __toString(): string
{
return $this->format();
}
}
src/Vault/DigestVault.php 0000644 00000003211 14002573567 0011400 0 ustar 00 getUsername() == $this->getUsername();
$hash_match = $key->getResponse() == $this->getKeyHash($key);
return $username_match && $hash_match;
}
/**
* Build and return hash from given key/vault
*
* @param Key $key
* @return string
*/
private function getKeyHash(Key $key): string
{
return md5(implode(':', [
md5(sprintf('%s:%s:%s', $key->getUsername(), $this->getRealm(), $this->getPassword())),
$key->getNonce(),
$key->getNc(),
$key->getCnonce(),
$key->getQop(),
md5(sprintf('%s:%s', $this->getRequestMethod(), $key->getUri())),
]));
}
/**
* Return HTTP request method
*
* @return string
*/
private function getRequestMethod()
{
return isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
}
/**
* Return auth directive
*
* @return Directive
*/
public function getDirective(): Directive
{
return new Directive('digest', [
'realm' => $this->getRealm(),
'qop' => 'auth',
'nonce' => uniqid(),
'opaque' => md5($this->getRealm()),
]);
}
}
src/Vault/BasicVault.php 0000644 00000001527 14002573567 0011212 0 ustar 00 getUsername() == $key->getUsername();
$password_match = $this->getPassword() == $key->getPassword();
return $username_match && $password_match;
}
/**
* Return auth directive
*
* @return Directive
*/
public function getDirective(): Directive
{
return new Directive('basic', [
'realm' => $this->getRealm(),
'charset' => 'UTF-8',
]);
}
}
src/Token/HttpAuthorization.php 0000644 00000001001 14002573567 0012625 0 ustar 00 getArrayValue($_SERVER, 'HTTP_AUTHORIZATION');
if (strtolower(substr($value, 0, 6)) === 'digest') {
$this->value = $value;
return true;
}
return false;
}
}
src/Token/PhpAuthUser.php 0000644 00000002126 14002573567 0011346 0 ustar 00 setProperty('username', $this->username);
$key->setProperty('password', $this->password);
return $key;
}
/**
* Parse environment variables and store value in object
*
* @return bool "true" if value was found or "false"
*/
protected function parse(): bool
{
if ($username = $this->getArrayValue($_SERVER, 'PHP_AUTH_USER')) {
$this->username = $username;
$this->password = array_key_exists('PHP_AUTH_PW', $_SERVER) ? $_SERVER['PHP_AUTH_PW'] : null;
return true;
}
return false;
}
}
src/Token/RedirectHttpAuthorization.php 0000644 00000001030 14002573567 0014311 0 ustar 00 getArrayValue($_SERVER, 'REDIRECT_HTTP_AUTHORIZATION');
if (strtolower(substr($value, 0, 5)) === 'basic') {
$this->value = $value;
return true;
}
return false;
}
}
src/Token/NullToken.php 0000644 00000002244 14002573567 0011052 0 ustar 00 parse() === false) {
throw new AuthentificationException('Failed to parse token');
}
}
/**
* Transform current instance to key object
*
* @return Key
*/
public function toKey(): Key
{
return new Key();
}
/**
* Parse environment variables and store value in object
*
* @return bool "true" if value was found or "false"
*/
protected function parse(): bool
{
return true;
}
/**
* Return the value of given key in given array data.
* Returns null if key doesn't exists
*
* @param array $data
* @param mixed $key
* @return mixed
*/
protected function getArrayValue($data, $key)
{
if (array_key_exists($key, $data)) {
return $data[$key];
}
return null;
}
}
src/Token/HttpAuthentification.php 0000644 00000001776 14002573567 0013306 0 ustar 00 value, 6)));
$key = new Key();
$key->setProperty('username', $username);
$key->setProperty('password', $password);
return $key;
}
/**
* Parse environment variables and store value in object
*
* @return bool "true" if value was found or "false"
*/
protected function parse(): bool
{
$value = $this->getArrayValue($_SERVER, 'HTTP_AUTHENTICATION');
if (strtolower(substr($value, 0, 5)) === 'basic') {
$this->value = $value;
return true;
}
return false;
}
}
src/Token/PhpAuthDigest.php 0000644 00000002021 14002573567 0011641 0 ustar 00 value, $matches, PREG_SET_ORDER);
foreach ($matches as $m) {
$key = $m[1];
$value = $m[2] ? $m[2] : $m[3];
$authKey->setProperty($key, $value);
}
return $authKey;
}
/**
* Parse environment variables and store value in object
*
* @return bool "true" if value was found or "false"
*/
protected function parse(): bool
{
if ($value = $this->getArrayValue($_SERVER, 'PHP_AUTH_DIGEST')) {
$this->value = $value;
return true;
}
return false;
}
}
src/HttpAuth.php 0000644 00000007776 14002573567 0007637 0 ustar 00 configure($config);
}
/**
* Configure current instance by array
*
* @param array $config
* @return HttpAuth
*/
private function configure(array $config = []): HttpAuth
{
foreach ($config as $key => $value) {
if (isset(static::${$key})) {
static::${$key} = $value;
}
}
return $this;
}
/**
* Create vault by current parameters and secure it
*
* @return void
*/
public function secure(): void
{
$this->getVault()->secure();
}
/**
* Create HTTP basic auth instance
*
* @return HttpAuth
*/
public function basic(): HttpAuth
{
static::$type = 'basic';
return $this;
}
/**
* Create HTTP digest auth instance
*
* @return HttpAuth
*/
public function digest(): HttpAuth
{
static::$type = 'digest';
return $this;
}
/**
* Set type of configured vault
*
* @param string $value
* @return HttpAuth
*/
public function type($value): HttpAuth
{
static::$type = $value;
return $this;
}
/**
* Set realm name of configured vault
*
* @param string $value
* @return HttpAuth
*/
public function realm($value): HttpAuth
{
static::$realm = $value;
return $this;
}
/**
* Set username of configured vault
*
* @param string $value
* @return HttpAuth
*/
public function username($value): HttpAuth
{
static::$username = $value;
return $this;
}
/**
* Set password of configured vault
*
* @param string $value
* @return HttpAuth
*/
public function password($value): HttpAuth
{
static::$password = $value;
return $this;
}
/**
* Set credentials for configured vault
*
* @param string $username
* @param string $password
* @return HttpAuth
*/
public function credentials($username, $password): HttpAuth
{
return $this->username($username)->password($password);
}
/**
* Get type of current instance
*
* @return mixed
*/
public function getType()
{
return static::$type;
}
/**
* Get realm of current instance
*
* @return mixed
*/
public function getRealm()
{
return static::$realm;
}
/**
* Get username of current instance
*
* @return mixed
*/
public function getUsername()
{
return static::$username;
}
/**
* Get password of current instance
*
* @return mixed
*/
public function getPassword()
{
return static::$password;
}
/**
* Return ready configured vault
*
* @return AbstractVault
*/
protected function getVault(): AbstractVault
{
$classname = sprintf('%s\Vault\%sVault', __NAMESPACE__, ucfirst(strtolower(static::$type)));
if (! class_exists($classname)) {
throw new Exception\NotSupportedException(
'Unable to create HTTP authentication vault of type "' . static::$type . '".'
);
}
return new $classname(static::$realm, static::$username, static::$password);
}
}
src/Laravel/HttpAuthServiceProvider.php 0000755 00000002477 14002573567 0014255 0 ustar 00 publishes([
__DIR__ . '/../config/config.php' => config_path('httpauth.php')
]);
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
// merge default config
$this->mergeConfigFrom(
__DIR__ . '/../config/config.php',
'httpauth'
);
// register singleton
$this->app->singleton('httpauth', function ($app) {
return HttpAuth::make($app['config']->get('httpauth'));
});
// bind classname
$this->app->bind('Intervention\HttpAuth\HttpAuth', function ($app) {
return HttpAuth::make($app['config']->get('httpauth'));
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['httpauth'];
}
}
src/Laravel/Facades/HttpAuth.php 0000755 00000000447 14002573567 0012542 0 ustar 00 realm;
}
/**
* Return current username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Return current password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Return current qop
*
* @return string
*/
public function getQop()
{
return $this->qop;
}
/**
* Return current nonce
*
* @return string
*/
public function getNonce()
{
return $this->nonce;
}
/**
* Return current opaque
*
* @return string
*/
public function getOpaque()
{
return $this->opaque;
}
/**
* Return current uri
*
* @return string
*/
public function getUri()
{
return $this->uri;
}
/**
* Return current nc
*
* @return string
*/
public function getNc()
{
return $this->nc;
}
/**
* Return current cnonce
*
* @return string
*/
public function getCnonce()
{
return $this->cnonce;
}
/**
* Return current response
*
* @return string
*/
public function getResponse()
{
return $this->response;
}
/**
* Set property to given value on current instance
*
* @param string $name
* @param mixed $value
* @return Key
*/
public function setProperty($name, $value): Key
{
if (property_exists($this, $name)) {
$this->{$name} = $value;
}
return $this;
}
}
composer.json 0000755 00000002263 14002573567 0007305 0 ustar 00 {
"name": "intervention/httpauth",
"description": "HTTP authentication (Basic & Digest) including ServiceProviders for easy Laravel integration",
"homepage": "https://github.com/Intervention/httpauth",
"keywords": ["authentication", "http", "laravel"],
"license": "MIT",
"authors": [
{
"name": "Oliver Vogel",
"email": "oliver@olivervogel.com",
"homepage": "https://olivervogel.com/"
}
],
"require": {
"php": "^7.3|^8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"phpstan/phpstan": "^0.12.11"
},
"autoload": {
"psr-4": {
"Intervention\\HttpAuth\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Intervention\\HttpAuth\\Test\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Intervention\\HttpAuth\\Laravel\\HttpAuthServiceProvider"
],
"aliases": {
"HttpAuth": "Intervention\\HttpAuth\\Laravel\\Facades\\HttpAuth"
}
}
},
"minimum-stability": "stable"
}
tests/HttpAuthTest.php 0000644 00000005101 14002573567 0011026 0 ustar 00 'digest',
'realm' => 'foo',
'username' => 'bar',
'password' => 'baz',
]);
$this->assertInstanceOf(Auth::class, $auth);
$this->assertEquals('digest', $auth->getType());
$this->assertEquals('foo', $auth->getRealm());
$this->assertEquals('bar', $auth->getUsername());
$this->assertEquals('baz', $auth->getPassword());
// second make should overwrite just one parameter
$auth = $auth->make(['username' => 'admin']);
$this->assertEquals('digest', $auth->getType());
$this->assertEquals('foo', $auth->getRealm());
$this->assertEquals('admin', $auth->getUsername());
$this->assertEquals('baz', $auth->getPassword());
}
public function testBasic()
{
$auth = Auth::make()->basic();
$this->assertInstanceOf(Auth::class, $auth);
$this->assertEquals('basic', $auth->getType());
}
public function testDigest()
{
$auth = Auth::make()->digest();
$this->assertInstanceOf(Auth::class, $auth);
$this->assertEquals('digest', $auth->getType());
}
public function testType()
{
$auth = Auth::make()->type('digest');
$this->assertInstanceOf(Auth::class, $auth);
$this->assertEquals('digest', $auth->getType());
}
public function testRealm()
{
$auth = Auth::make()->realm('foo');
$this->assertInstanceOf(Auth::class, $auth);
$this->assertEquals('foo', $auth->getRealm());
}
public function testUsername()
{
$auth = Auth::make()->username('foo');
$this->assertInstanceOf(Auth::class, $auth);
$this->assertEquals('foo', $auth->getUsername());
}
public function testPassword()
{
$auth = Auth::make()->password('foo');
$this->assertInstanceOf(Auth::class, $auth);
$this->assertEquals('foo', $auth->getPassword());
}
public function testCredentials()
{
$auth = Auth::make()->credentials('foo', 'bar');
$this->assertInstanceOf(Auth::class, $auth);
$this->assertEquals('foo', $auth->getUsername());
$this->assertEquals('bar', $auth->getPassword());
}
}
tests/EnvironmentTest.php 0000644 00000000666 14002573567 0011604 0 ustar 00 getToken();
$this->assertInstanceOf(TokenInterface::class, $auth);
}
}
tests/DirectiveTest.php 0000644 00000001421 14002573567 0011204 0 ustar 00 assertInstanceOf(Directive::class, $directive);
}
public function testFormat()
{
$directive = new Directive('test', ['a' => 'foo', 'b' => 'bar', 'c' => 'baz']);
$this->assertEquals('Test a="foo", b="bar", c="baz"', $directive->format());
}
public function testToString()
{
$directive = new Directive('test', ['a' => 'foo', 'b' => 'bar', 'c' => 'baz']);
$directive = (string) $directive;
$this->assertEquals('Test a="foo", b="bar", c="baz"', $directive);
}
}
tests/Vault/DigestVaultTest.php 0000644 00000003024 14002573567 0012615 0 ustar 00 getDirective();
$this->assertInstanceOf(Directive::class, $directive);
$this->assertEquals('digest', $directive->getType());
$this->assertEquals('myRealm', $directive->getParameter('realm'));
$this->assertEquals('auth', $directive->getParameter('qop'));
$this->assertMatchesRegularExpression("/^[a-z0-9]{13}$/", $directive->getParameter('nonce'));
$this->assertMatchesRegularExpression("/^[a-z0-9]{32}$/", $directive->getParameter('opaque'));
}
public function testUnlocksWithKey()
{
$vault = new Vault('myRealm', 'myUsername', 'myPassword');
$key = new Key();
$key->setProperty('username', 'myUsername');
$key->setProperty('response', 'xx');
$key->setProperty('nonce', 'myNonce');
$key->setProperty('nc', 'myNc');
$key->setProperty('cnonce', 'myCnonce');
$key->setProperty('qop', 'myQop');
$key->setProperty('uri', 'myUri');
$this->assertFalse($vault->unlocksWithKey($key));
$key->setProperty('response', 'f1d34edc18506c758600fe1233d1c1b3');
$this->assertTrue($vault->unlocksWithKey($key));
}
}
tests/Vault/BasicVaultTest.php 0000644 00000002057 14002573567 0012424 0 ustar 00 getDirective();
$this->assertInstanceOf(Directive::class, $directive);
$this->assertEquals('basic', $directive->getType());
$this->assertEquals('myRealm', $directive->getParameter('realm'));
}
public function testUnlocksWithKey()
{
$key = new Key();
$key->setProperty('username', 'myUsername');
$key->setProperty('password', 'foo');
$vault = new BasicVault('myRealm', 'myUsername', 'myPassword');
$this->assertFalse($vault->unlocksWithKey($key));
$key->setProperty('password', 'myPassword');
$this->assertTrue($vault->unlocksWithKey($key));
}
}
tests/Token/NullTokenTest.php 0000644 00000000747 14002573567 0012273 0 ustar 00 assertInstanceOf(NullToken::class, $auth);
}
public function testToKey()
{
$auth = new NullToken();
$this->assertInstanceOf(Key::class, $auth->toKey());
}
}
tests/Token/HttpAuthentificationTest.php 0000644 00000002235 14002573567 0014510 0 ustar 00 expectException(AuthentificationException::class);
$auth = new HttpAuthentification();
}
public function testParse()
{
$auth = $this->getTestToken();
$this->assertInstanceOf(HttpAuthentification::class, $auth);
}
public function testToKey()
{
$key = $this->getTestToken()->toKey();
$this->assertInstanceOf(Key::class, $key);
$this->assertEquals('test_username', $key->getUsername());
$this->assertEquals('test_password', $key->getPassword());
}
private function getTestToken()
{
$this->setServerVars([
'HTTP_AUTHENTICATION' => 'basic_' . base64_encode(implode(':', [
'test_username',
'test_password'
])),
]);
return new HttpAuthentification();
}
}
tests/Token/HttpAuthorizationTest.php 0000644 00000002356 14002573567 0014056 0 ustar 00 expectException(AuthentificationException::class);
$auth = new HttpAuthorization();
}
public function testParse()
{
$auth = $this->getTestToken();
$this->assertInstanceOf(HttpAuthorization::class, $auth);
}
public function testToKey()
{
$key = $this->getTestToken()->toKey();
$this->assertInstanceOf(Key::class, $key);
$this->assertEquals('test', $key->getRealm());
$this->assertEquals('auth', $key->getQop());
$this->assertEquals('xxxxxxxxxxxxx', $key->getNonce());
$this->assertEquals('yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy', $key->getOpaque());
}
private function getTestToken()
{
$this->setServerVars([
'HTTP_AUTHORIZATION' => 'Digest realm="test",qop="auth",nonce="xxxxxxxxxxxxx",opaque="yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"'
]);
return new HttpAuthorization();
}
}
tests/Token/RedirectHttpAuthorizationTest.php 0000644 00000002276 14002573567 0015541 0 ustar 00 expectException(AuthentificationException::class);
$auth = new RedirectHttpAuthorization();
}
public function testParse()
{
$auth = $this->getTestToken();
$this->assertInstanceOf(RedirectHttpAuthorization::class, $auth);
}
public function testToKey()
{
$key = $this->getTestToken()->toKey();
$this->assertInstanceOf(Key::class, $key);
$this->assertEquals('test_username', $key->getUsername());
$this->assertEquals('test_password', $key->getPassword());
}
private function getTestToken()
{
$this->setServerVars([
'REDIRECT_HTTP_AUTHORIZATION' => 'basic_' . base64_encode(implode(':', [
'test_username',
'test_password'
])),
]);
return new RedirectHttpAuthorization();
}
}
tests/Token/PhpAuthDigestTest.php 0000644 00000002376 14002573567 0013071 0 ustar 00 expectException(AuthentificationException::class);
$auth = new PhpAuthDigest();
}
public function testParse()
{
$auth = $this->getTestToken();
$this->assertInstanceOf(PhpAuthDigest::class, $auth);
}
public function testToKey()
{
$key = $this->getTestToken()->toKey();
$this->assertInstanceOf(Key::class, $key);
$this->assertEquals('test', $key->getRealm());
$this->assertEquals('auth', $key->getQop());
$this->assertEquals('xxxxxxxxxxxxx', $key->getNonce());
$this->assertEquals('yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy', $key->getOpaque());
}
private function getTestToken()
{
$auth_digest = 'realm="test",qop="auth",nonce="xxxxxxxxxxxxx",opaque="yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"';
$this->setServerVars([
'PHP_AUTH_DIGEST' => $auth_digest
]);
return new PhpAuthDigest();
}
}
tests/Token/AbstractTokenTestCase.php 0000644 00000001254 14002573567 0013712 0 ustar 00 $value) {
$_SERVER[$key] = $value;
}
}
}
tests/Token/PhpAuthUserTest.php 0000644 00000002057 14002573567 0012564 0 ustar 00 expectException(AuthentificationException::class);
$auth = new PhpAuthUser();
}
public function testParse()
{
$auth = $this->getTestToken();
$this->assertInstanceOf(PhpAuthUser::class, $auth);
}
public function testToKey()
{
$key = $this->getTestToken()->toKey();
$this->assertInstanceOf(Key::class, $key);
$this->assertEquals('test_username', $key->getUsername());
$this->assertEquals('test_password', $key->getPassword());
}
private function getTestToken()
{
$this->setServerVars([
'PHP_AUTH_USER' => 'test_username',
'PHP_AUTH_PW' => 'test_password',
]);
return new PhpAuthUser();
}
}
tests/phpstan/bootstrap.php 0000644 00000000101 14002573567 0012112 0 ustar 00 assertNull($key->getRealm());
$this->assertNull($key->getUsername());
$this->assertNull($key->getPassword());
$this->assertNull($key->getQop());
$this->assertNull($key->getNonce());
$this->assertNull($key->getOpaque());
$this->assertNull($key->getUri());
$this->assertNull($key->getNc());
$this->assertNull($key->getCnonce());
$this->assertNull($key->getResponse());
$key->setProperty('realm', 'testRealm');
$key->setProperty('username', 'testUsername');
$key->setProperty('password', 'testPassword');
$key->setProperty('qop', 'testQop');
$key->setProperty('nonce', 'testNonce');
$key->setProperty('opaque', 'testOpaque');
$key->setProperty('uri', 'testUri');
$key->setProperty('nc', 'testNc');
$key->setProperty('cnonce', 'testCnonce');
$key->setProperty('response', 'testResponse');
$this->assertEquals('testRealm', $key->getRealm());
$this->assertEquals('testUsername', $key->getUsername());
$this->assertEquals('testPassword', $key->getPassword());
$this->assertEquals('testQop', $key->getQop());
$this->assertEquals('testNonce', $key->getNonce());
$this->assertEquals('testOpaque', $key->getOpaque());
$this->assertEquals('testUri', $key->getUri());
$this->assertEquals('testNc', $key->getNc());
$this->assertEquals('testCnonce', $key->getCnonce());
$this->assertEquals('testResponse', $key->getResponse());
}
}
tests/AbstractVaultTest.php 0000644 00000003753 14002573567 0012057 0 ustar 00 getMockForAbstractClass(
AbstractVault::class,
['myRealm', 'myUsername', 'myPassword']
);
$this->assertEquals('myUsername', $vault->getUsername());
$this->assertEquals('myPassword', $vault->getPassword());
$this->assertEquals('myRealm', $vault->getRealm());
}
public function testConstructorEmpty()
{
$this->expectException(InvalidParameterException::class);
$vault = $this->getMockForAbstractClass(
AbstractVault::class,
[null, null, null]
);
}
public function testGetKey()
{
$vault = $this->getMockForAbstractClass(
AbstractVault::class,
['myRealm', 'myUsername', 'myPassword']
);
$this->assertInstanceOf(Key::class, $vault->getKey());
}
public function testSetGetUsername()
{
$vault = $this->getMockForAbstractClass(
AbstractVault::class,
['myRealm', 'myUsername', 'myPassword']
);
$vault->setUsername('foo');
$this->assertEquals('foo', $vault->getUsername());
}
public function testSetGetPassword()
{
$vault = $this->getMockForAbstractClass(
AbstractVault::class,
['myRealm', 'myUsername', 'myPassword']
);
$vault->setPassword('foo');
$this->assertEquals('foo', $vault->getPassword());
}
public function testSetGetRealm()
{
$vault = $this->getMockForAbstractClass(
AbstractVault::class,
['myRealm', 'myUsername', 'myPassword']
);
$vault->setRealm('foo');
$this->assertEquals('foo', $vault->getRealm());
}
}
.gitignore 0000755 00000000065 14002573567 0006551 0 ustar 00 .DS_Store
.phpunit.result.cache
composer.lock
vendor/