|
|
@ -16,6 +16,7 @@ use JKingWeb\Arsse\Test\Result; |
|
|
|
use JKingWeb\Arsse\Misc\Date; |
|
|
|
use JKingWeb\Arsse\Context\Context; |
|
|
|
use JKingWeb\Arsse\Db\ExceptionInput; |
|
|
|
use JKingWeb\Arsse\User\Exception as UserException; |
|
|
|
use JKingWeb\Arsse\Db\Transaction; |
|
|
|
use JKingWeb\Arsse\REST\Fever\API; |
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
|
@ -48,7 +49,7 @@ class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest { |
|
|
|
$req = $req->withParsedBody($dataPost); |
|
|
|
} else { |
|
|
|
$body = $req->getBody(); |
|
|
|
$body->write($strData); |
|
|
|
$body->write($dataPost); |
|
|
|
$req = $req->withBody($body); |
|
|
|
} |
|
|
|
if (isset($user)) { |
|
|
@ -135,4 +136,41 @@ class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest { |
|
|
|
[true, false, "validUser", ['api_key' => "invalidToken"], ['api' => null], $success], |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
/** @dataProvider providePasswordCreations */ |
|
|
|
public function testRegisterAUserPassword(string $user, string $password = null, $exp) { |
|
|
|
\Phake::when(Arsse::$user)->generatePassword->thenReturn("RANDOM_PASSWORD"); |
|
|
|
\Phake::when(Arsse::$db)->tokenCreate->thenReturnCallback(function($user, $class, $id = null) { |
|
|
|
return $id ?? "RANDOM_TOKEN"; |
|
|
|
}); |
|
|
|
\Phake::when(Arsse::$db)->tokenCreate("john.doe@example.org", $this->anything(), $this->anything())->thenThrow(new UserException("doesNotExist")); |
|
|
|
if ($exp instanceof \JKingWeb\Arsse\AbstractException) { |
|
|
|
$this->assertException($exp); |
|
|
|
API::registerUser($user, $password); |
|
|
|
} else { |
|
|
|
$this->assertSame($exp, API::registerUser($user, $password)); |
|
|
|
} |
|
|
|
\Phake::verify(Arsse::$db)->tokenRevoke($user, "fever.login"); |
|
|
|
\Phake::verify(Arsse::$db)->tokenCreate($user, "fever.login", md5($user.":".($password ?? "RANDOM_PASSWORD"))); |
|
|
|
} |
|
|
|
|
|
|
|
public function providePasswordCreations() { |
|
|
|
return [ |
|
|
|
["jane.doe@example.com", "secret", "secret"], |
|
|
|
["jane.doe@example.com", "superman", "superman"], |
|
|
|
["jane.doe@example.com", null, "RANDOM_PASSWORD"], |
|
|
|
["john.doe@example.org", null, new UserException("doesNotExist")], |
|
|
|
["john.doe@example.net", null, "RANDOM_PASSWORD"], |
|
|
|
["john.doe@example.net", "secret", "secret"], |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function testUnregisterAUser() { |
|
|
|
\Phake::when(Arsse::$db)->tokenRevoke->thenReturn(3); |
|
|
|
$this->assertTrue(API::unregisterUser("jane.doe@example.com")); |
|
|
|
\Phake::verify(Arsse::$db)->tokenRevoke("jane.doe@example.com", "fever.login"); |
|
|
|
\Phake::when(Arsse::$db)->tokenRevoke->thenReturn(0); |
|
|
|
$this->assertFalse(API::unregisterUser("john.doe@example.com")); |
|
|
|
\Phake::verify(Arsse::$db)->tokenRevoke("john.doe@example.com", "fever.login"); |
|
|
|
} |
|
|
|
} |
|
|
|