Browse Source

Verify even in exceptional cases

microsub
J. King 5 years ago
parent
commit
3b28634447
  1. 5
      tests/cases/REST/Fever/TestAPI.php

5
tests/cases/REST/Fever/TestAPI.php

@ -81,7 +81,7 @@ class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest {
} }
/** @dataProvider provideAuthenticationRequests */ /** @dataProvider provideAuthenticationRequests */
public function testAuthenticateAUser(bool $httpRequired, bool $tokenEnforced, string $httpUser = null, array $dataPost, array $dataGet, ResponseInterface $exp) { public function testAuthenticateAUserToken(bool $httpRequired, bool $tokenEnforced, string $httpUser = null, array $dataPost, array $dataGet, ResponseInterface $exp) {
self::setConf([ self::setConf([
'userHTTPAuthRequired' => $httpRequired, 'userHTTPAuthRequired' => $httpRequired,
'userSessionEnforced' => $tokenEnforced, 'userSessionEnforced' => $tokenEnforced,
@ -144,15 +144,18 @@ class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest {
return $id ?? "RANDOM_TOKEN"; return $id ?? "RANDOM_TOKEN";
}); });
\Phake::when(Arsse::$db)->tokenCreate("john.doe@example.org", $this->anything(), $this->anything())->thenThrow(new UserException("doesNotExist")); \Phake::when(Arsse::$db)->tokenCreate("john.doe@example.org", $this->anything(), $this->anything())->thenThrow(new UserException("doesNotExist"));
try {
if ($exp instanceof \JKingWeb\Arsse\AbstractException) { if ($exp instanceof \JKingWeb\Arsse\AbstractException) {
$this->assertException($exp); $this->assertException($exp);
API::userRegister($user, $password); API::userRegister($user, $password);
} else { } else {
$this->assertSame($exp, API::userRegister($user, $password)); $this->assertSame($exp, API::userRegister($user, $password));
} }
} finally {
\Phake::verify(Arsse::$db)->tokenRevoke($user, "fever.login"); \Phake::verify(Arsse::$db)->tokenRevoke($user, "fever.login");
\Phake::verify(Arsse::$db)->tokenCreate($user, "fever.login", md5($user.":".($password ?? "RANDOM_PASSWORD"))); \Phake::verify(Arsse::$db)->tokenCreate($user, "fever.login", md5($user.":".($password ?? "RANDOM_PASSWORD")));
} }
}
public function providePasswordCreations() { public function providePasswordCreations() {
return [ return [

Loading…
Cancel
Save