Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace yiiunit\framework\filters\auth; use Yii; use yii\base\Action; use yii\fil..

Decoded Output download

<?php
 namespace yiiunit\framework\filters\auth; use Yii; use yii\base\Action; use yii\filters\auth\AuthMethod; use yii\filters\auth\HttpBearerAuth; use yii\filters\auth\QueryParamAuth; use yii\filters\auth\HttpHeaderAuth; use yii\helpers\ArrayHelper; use yii\rest\Controller; use yii\web\UnauthorizedHttpException; use yiiunit\framework\filters\stubs\UserIdentity; class AuthTest extends \yiiunit\TestCase { protected function setUp() : void { parent::setUp(); $_SERVER["SCRIPT_FILENAME"] = "/index.php"; $_SERVER["SCRIPT_NAME"] = "/index.php"; $appConfig = array("components" => array("user" => array("identityClass" => UserIdentity::className())), "controllerMap" => array("test-auth" => TestAuthController::className())); $this->mockWebApplication($appConfig); } public function tokenProvider() { return array(array("token1", "user1"), array("token2", "user2"), array("token3", "user3"), array("unknown", null), array(null, null)); } public function authOnly($token, $login, $filter) { $controller = Yii::$app->createController("test-auth")[0]; $controller->authenticatorConfig = ArrayHelper::merge($filter, array("only" => array("filtered"))); try { $this->assertEquals($login, $controller->run("filtered")); } catch (UnauthorizedHttpException $e) { } } public function authOptional($token, $login, $filter) { $controller = Yii::$app->createController("test-auth")[0]; $controller->authenticatorConfig = ArrayHelper::merge($filter, array("optional" => array("filtered"))); try { $this->assertEquals($login, $controller->run("filtered")); } catch (UnauthorizedHttpException $e) { } } public function authExcept($token, $login, $filter) { $controller = Yii::$app->createController("test-auth")[0]; $controller->authenticatorConfig = ArrayHelper::merge($filter, array("except" => array("other"))); try { $this->assertEquals($login, $controller->run("filtered")); } catch (UnauthorizedHttpException $e) { } } public function ensureFilterApplies($token, $login, $filter) { $this->authOnly($token, $login, $filter); $this->authOptional($token, $login, $filter); $this->authExcept($token, $login, $filter); } public function testQueryParamAuth($token, $login) { $_GET["access-token"] = $token; $filter = array("class" => QueryParamAuth::className()); $this->ensureFilterApplies($token, $login, $filter); } public function testHttpHeaderAuth($token, $login) { Yii::$app->request->headers->set("X-Api-Key", $token); $filter = array("class" => HttpHeaderAuth::className()); $this->ensureFilterApplies($token, $login, $filter); } public function testHttpBearerAuth($token, $login) { Yii::$app->request->headers->set("Authorization", "Bearer {$token}"); $filter = array("class" => HttpBearerAuth::className()); $this->ensureFilterApplies($token, $login, $filter); } public function authMethodProvider() { return array(array("yii\filters\auth\CompositeAuth"), array("yii\filters\auth\HttpBearerAuth"), array("yii\filters\auth\QueryParamAuth"), array("yii\filters\auth\HttpHeaderAuth")); } public function testActive($authClass) { $filter = new $authClass(); $reflection = new \ReflectionClass($filter); $method = $reflection->getMethod("isActive"); $method->setAccessible(true); $controller = new \yii\web\Controller("test", Yii::$app); $this->assertTrue($method->invokeArgs($filter, array(new Action("index", $controller)))); $this->assertTrue($method->invokeArgs($filter, array(new Action("view", $controller)))); $filter->only = array("index"); $filter->except = array(); $filter->optional = array(); $this->assertTrue($method->invokeArgs($filter, array(new Action("index", $controller)))); $this->assertFalse($method->invokeArgs($filter, array(new Action("view", $controller)))); $filter->only = array("index"); $filter->except = array(); $filter->optional = array("view"); $this->assertTrue($method->invokeArgs($filter, array(new Action("index", $controller)))); $this->assertFalse($method->invokeArgs($filter, array(new Action("view", $controller)))); $filter->only = array("index", "view"); $filter->except = array("view"); $filter->optional = array(); $this->assertTrue($method->invokeArgs($filter, array(new Action("index", $controller)))); $this->assertFalse($method->invokeArgs($filter, array(new Action("view", $controller)))); $filter->only = array("index", "view"); $filter->except = array("view"); $filter->optional = array("view"); $this->assertTrue($method->invokeArgs($filter, array(new Action("index", $controller)))); $this->assertFalse($method->invokeArgs($filter, array(new Action("view", $controller)))); $filter->only = array(); $filter->except = array("view"); $filter->optional = array("view"); $this->assertTrue($method->invokeArgs($filter, array(new Action("index", $controller)))); $this->assertFalse($method->invokeArgs($filter, array(new Action("view", $controller)))); } public function testHeaders() { Yii::$app->request->headers->set("Authorization", "Bearer wrong_token"); $filter = array("class" => HttpBearerAuth::className()); $controller = Yii::$app->createController("test-auth")[0]; $controller->authenticatorConfig = ArrayHelper::merge($filter, array("only" => array("filtered"))); try { $controller->run("filtered"); $this->fail("Should throw UnauthorizedHttpException"); } catch (UnauthorizedHttpException $e) { $this->assertArrayHasKey("WWW-Authenticate", Yii::$app->getResponse()->getHeaders()); } } } class TestAuthController extends Controller { public $authenticatorConfig = array(); public function behaviors() { return array("authenticator" => $this->authenticatorConfig); } public function actionFiltered() { return Yii::$app->user->id; } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace yiiunit\framework\filters\auth; use Yii; use yii\base\Action; use yii\filters\auth\AuthMethod; use yii\filters\auth\HttpBearerAuth; use yii\filters\auth\QueryParamAuth; use yii\filters\auth\HttpHeaderAuth; use yii\helpers\ArrayHelper; use yii\rest\Controller; use yii\web\UnauthorizedHttpException; use yiiunit\framework\filters\stubs\UserIdentity; class AuthTest extends \yiiunit\TestCase { protected function setUp() : void { parent::setUp(); $_SERVER["\x53\x43\122\x49\120\x54\137\x46\111\114\x45\x4e\101\x4d\105"] = "\x2f\x69\156\x64\x65\x78\x2e\160\x68\160"; $_SERVER["\123\103\122\111\x50\x54\x5f\116\101\x4d\105"] = "\57\151\x6e\x64\145\x78\x2e\x70\150\160"; $appConfig = array("\143\x6f\x6d\x70\x6f\x6e\x65\x6e\164\163" => array("\x75\163\145\x72" => array("\151\144\145\x6e\x74\151\164\x79\x43\154\x61\x73\163" => UserIdentity::className())), "\x63\x6f\156\x74\162\x6f\154\x6c\145\162\115\141\160" => array("\164\x65\163\164\x2d\141\x75\x74\150" => TestAuthController::className())); $this->mockWebApplication($appConfig); } public function tokenProvider() { return array(array("\164\x6f\x6b\145\156\x31", "\x75\x73\x65\162\61"), array("\x74\x6f\153\x65\156\62", "\x75\x73\145\162\x32"), array("\x74\157\x6b\145\x6e\x33", "\x75\x73\x65\162\x33"), array("\x75\x6e\153\156\x6f\x77\156", null), array(null, null)); } public function authOnly($token, $login, $filter) { $controller = Yii::$app->createController("\164\145\x73\164\x2d\x61\x75\x74\150")[0]; $controller->authenticatorConfig = ArrayHelper::merge($filter, array("\157\x6e\x6c\171" => array("\x66\x69\x6c\164\x65\x72\145\144"))); try { $this->assertEquals($login, $controller->run("\x66\x69\x6c\x74\x65\162\145\144")); } catch (UnauthorizedHttpException $e) { } } public function authOptional($token, $login, $filter) { $controller = Yii::$app->createController("\x74\145\x73\164\55\x61\x75\164\x68")[0]; $controller->authenticatorConfig = ArrayHelper::merge($filter, array("\157\160\x74\151\x6f\x6e\141\154" => array("\146\151\154\x74\145\162\x65\x64"))); try { $this->assertEquals($login, $controller->run("\146\151\154\164\145\162\x65\x64")); } catch (UnauthorizedHttpException $e) { } } public function authExcept($token, $login, $filter) { $controller = Yii::$app->createController("\x74\145\x73\x74\55\141\165\x74\x68")[0]; $controller->authenticatorConfig = ArrayHelper::merge($filter, array("\145\x78\143\x65\160\x74" => array("\x6f\x74\x68\x65\162"))); try { $this->assertEquals($login, $controller->run("\x66\151\154\x74\145\x72\145\x64")); } catch (UnauthorizedHttpException $e) { } } public function ensureFilterApplies($token, $login, $filter) { $this->authOnly($token, $login, $filter); $this->authOptional($token, $login, $filter); $this->authExcept($token, $login, $filter); } public function testQueryParamAuth($token, $login) { $_GET["\141\x63\143\145\x73\163\x2d\x74\x6f\153\x65\156"] = $token; $filter = array("\143\x6c\141\163\163" => QueryParamAuth::className()); $this->ensureFilterApplies($token, $login, $filter); } public function testHttpHeaderAuth($token, $login) { Yii::$app->request->headers->set("\x58\55\x41\x70\x69\55\113\145\x79", $token); $filter = array("\x63\154\x61\x73\163" => HttpHeaderAuth::className()); $this->ensureFilterApplies($token, $login, $filter); } public function testHttpBearerAuth($token, $login) { Yii::$app->request->headers->set("\x41\165\x74\x68\x6f\162\151\172\x61\164\151\157\x6e", "\x42\x65\141\x72\145\162\x20{$token}"); $filter = array("\x63\x6c\141\163\x73" => HttpBearerAuth::className()); $this->ensureFilterApplies($token, $login, $filter); } public function authMethodProvider() { return array(array("\x79\x69\x69\x5c\146\151\x6c\x74\145\162\x73\x5c\141\165\164\x68\134\x43\x6f\155\x70\x6f\x73\151\164\145\101\x75\x74\x68"), array("\x79\151\151\134\146\151\154\164\145\162\163\x5c\x61\x75\164\150\134\110\164\x74\x70\102\x65\x61\162\x65\x72\x41\x75\x74\150"), array("\171\x69\x69\134\146\x69\x6c\x74\145\x72\163\134\141\165\x74\x68\x5c\121\x75\145\x72\x79\120\141\x72\x61\155\101\165\x74\150"), array("\x79\151\151\x5c\x66\151\154\164\x65\x72\163\x5c\141\165\x74\150\134\110\x74\164\x70\110\x65\141\x64\x65\162\x41\x75\164\x68")); } public function testActive($authClass) { $filter = new $authClass(); $reflection = new \ReflectionClass($filter); $method = $reflection->getMethod("\x69\163\x41\143\164\x69\x76\x65"); $method->setAccessible(true); $controller = new \yii\web\Controller("\x74\x65\163\x74", Yii::$app); $this->assertTrue($method->invokeArgs($filter, array(new Action("\x69\x6e\x64\145\x78", $controller)))); $this->assertTrue($method->invokeArgs($filter, array(new Action("\x76\151\x65\167", $controller)))); $filter->only = array("\151\156\x64\145\x78"); $filter->except = array(); $filter->optional = array(); $this->assertTrue($method->invokeArgs($filter, array(new Action("\151\156\x64\145\170", $controller)))); $this->assertFalse($method->invokeArgs($filter, array(new Action("\166\x69\x65\167", $controller)))); $filter->only = array("\151\156\144\x65\170"); $filter->except = array(); $filter->optional = array("\166\x69\x65\167"); $this->assertTrue($method->invokeArgs($filter, array(new Action("\151\156\x64\145\170", $controller)))); $this->assertFalse($method->invokeArgs($filter, array(new Action("\x76\x69\x65\x77", $controller)))); $filter->only = array("\x69\x6e\x64\x65\x78", "\x76\151\145\x77"); $filter->except = array("\166\151\145\x77"); $filter->optional = array(); $this->assertTrue($method->invokeArgs($filter, array(new Action("\151\156\144\145\170", $controller)))); $this->assertFalse($method->invokeArgs($filter, array(new Action("\x76\151\x65\x77", $controller)))); $filter->only = array("\x69\x6e\144\x65\x78", "\166\x69\145\x77"); $filter->except = array("\x76\x69\x65\167"); $filter->optional = array("\x76\151\145\x77"); $this->assertTrue($method->invokeArgs($filter, array(new Action("\151\x6e\144\145\x78", $controller)))); $this->assertFalse($method->invokeArgs($filter, array(new Action("\x76\151\145\167", $controller)))); $filter->only = array(); $filter->except = array("\x76\151\x65\x77"); $filter->optional = array("\x76\x69\145\x77"); $this->assertTrue($method->invokeArgs($filter, array(new Action("\151\x6e\x64\x65\x78", $controller)))); $this->assertFalse($method->invokeArgs($filter, array(new Action("\x76\151\x65\x77", $controller)))); } public function testHeaders() { Yii::$app->request->headers->set("\x41\165\x74\x68\x6f\x72\x69\172\x61\x74\151\157\156", "\x42\x65\x61\162\145\162\40\167\162\157\156\x67\137\x74\157\x6b\x65\156"); $filter = array("\143\x6c\141\x73\x73" => HttpBearerAuth::className()); $controller = Yii::$app->createController("\164\145\x73\164\x2d\x61\x75\164\150")[0]; $controller->authenticatorConfig = ArrayHelper::merge($filter, array("\157\x6e\154\171" => array("\x66\151\x6c\164\x65\162\x65\x64"))); try { $controller->run("\146\x69\154\164\x65\x72\145\x64"); $this->fail("\123\150\x6f\165\x6c\144\x20\x74\x68\162\x6f\x77\x20\x55\156\141\x75\164\x68\x6f\x72\151\172\x65\144\110\x74\x74\160\105\x78\x63\145\160\x74\x69\157\156"); } catch (UnauthorizedHttpException $e) { $this->assertArrayHasKey("\x57\127\127\55\x41\165\164\x68\x65\156\164\151\x63\x61\164\145", Yii::$app->getResponse()->getHeaders()); } } } class TestAuthController extends Controller { public $authenticatorConfig = array(); public function behaviors() { return array("\141\x75\x74\x68\145\156\x74\151\143\x61\164\x6f\162" => $this->authenticatorConfig); } public function actionFiltered() { return Yii::$app->user->id; } }

Function Calls

None

Variables

None

Stats

MD5 c6b89d59f0f708ebb981f154fabd8cb1
Eval Count 0
Decode Time 106 ms