From c800852f3a9d17263bcf46a44022ab4254a56c59 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 26 May 2017 13:06:06 -0400 Subject: [PATCH] Remove stubs to support non-HTTP authentication Also removes authPreferHTTP setting --- lib/Conf.php | 1 - lib/Feed.php | 2 +- lib/User.php | 35 ++++---------------------------- tests/User/TestAuthorization.php | 1 - tests/lib/User/CommonTests.php | 1 - tests/test.php | 1 - 6 files changed, 5 insertions(+), 36 deletions(-) diff --git a/lib/Conf.php b/lib/Conf.php index 5decf1d..6a8115c 100644 --- a/lib/Conf.php +++ b/lib/Conf.php @@ -25,7 +25,6 @@ class Conf { public $dbMySQLAutoUpd = false; public $userDriver = User\Internal\Driver::class; - public $userAuthPreferHTTP = false; public $userComposeNames = true; public $userTempPasswordLength = 20; diff --git a/lib/Feed.php b/lib/Feed.php index 3c48f54..8c1e9a9 100644 --- a/lib/Feed.php +++ b/lib/Feed.php @@ -266,7 +266,7 @@ class Feed { // if there are no tentatively new articles and/or the number of stored articles is less than the size of the feed, don't do a second pass; assume any tentatively new items are in fact new $new = $tentative; } - // FIXME: fetch full content when appropriate + // TODO: fetch full content when appropriate foreach($new as $index) { $this->newItems[] = $items[$index]; } diff --git a/lib/User.php b/lib/User.php index 26cb763..dd2f7a6 100644 --- a/lib/User.php +++ b/lib/User.php @@ -87,20 +87,6 @@ class User { } public function credentials(): array { - if(Data::$conf->userAuthPreferHTTP) { - return $this->credentialsHTTP(); - } else { - return $this->credentialsForm(); - } - } - - public function credentialsForm(): array { - // FIXME: stub - $this->id = "john.doe@example.com"; - return ["user" => "john.doe@example.com", "password" => "secret"]; - } - - public function credentialsHTTP(): array { if($_SERVER['PHP_AUTH_USER']) { $out = ["user" => $_SERVER['PHP_AUTH_USER'], "password" => $_SERVER['PHP_AUTH_PW']]; } else if($_SERVER['REMOTE_USER']) { @@ -117,8 +103,7 @@ class User { public function auth(string $user = null, string $password = null): bool { if($user===null) { - if(Data::$conf->userAuthPreferHTTP) return $this->authHTTP(); - return $this->authForm(); + return $this->authHTTP(); } else { $this->id = $user; $this->actor = []; @@ -135,17 +120,10 @@ class User { } } - public function authForm(): bool { - $cred = $this->credentialsForm(); - if(!$cred["user"]) return $this->challengeForm(); - if(!$this->auth($cred["user"], $cred["password"])) return $this->challengeForm(); - return true; - } - public function authHTTP(): bool { - $cred = $this->credentialsHTTP(); - if(!$cred["user"]) return $this->challengeHTTP(); - if(!$this->auth($cred["user"], $cred["password"])) return $this->challengeHTTP(); + $cred = $this->credentials(); + if(!$cred["user"]) return false; + if(!$this->auth($cred["user"], $cred["password"])) return false; return true; } @@ -358,11 +336,6 @@ class User { } } - // FIXME: stubs - public function challenge(): bool {throw new User\Exception("authFailed");} - public function challengeForm(): bool {throw new User\Exception("authFailed");} - public function challengeHTTP(): bool {throw new User\Exception("authFailed");} - protected function composeName(string $user): string { if(preg_match("/.+?@[^@]+$/",$user)) { return $user; diff --git a/tests/User/TestAuthorization.php b/tests/User/TestAuthorization.php index c7a6856..7ababbb 100644 --- a/tests/User/TestAuthorization.php +++ b/tests/User/TestAuthorization.php @@ -50,7 +50,6 @@ class TestAuthorization extends \PHPUnit\Framework\TestCase { $this->clearData(); $conf = new Conf(); $conf->userDriver = $drv; - $conf->userAuthPreferHTTP = true; $conf->userComposeNames = true; Data::$conf = $conf; if($db !== null) { diff --git a/tests/lib/User/CommonTests.php b/tests/lib/User/CommonTests.php index 4827544..c7d6697 100644 --- a/tests/lib/User/CommonTests.php +++ b/tests/lib/User/CommonTests.php @@ -13,7 +13,6 @@ trait CommonTests { $this->clearData(); $conf = new Conf(); $conf->userDriver = $this->drv; - $conf->userAuthPreferHTTP = true; Data::$conf = $conf; Data::$db = new Database(); Data::$user = Phake::PartialMock(User::class); diff --git a/tests/test.php b/tests/test.php index bf0018a..3fffe21 100644 --- a/tests/test.php +++ b/tests/test.php @@ -10,7 +10,6 @@ $_SERVER['PHP_AUTH_USER'] = $user; $_SERVER['PHP_AUTH_PW'] = $pass; $conf = new Conf(); $conf->dbSQLite3File = ":memory:"; -$conf->userAuthPreferHTTP = true; Data::load($conf); Data::$db->schemaUpdate();