Browse Source

Verify even in exceptional cases

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

19
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,14 +144,17 @@ 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"));
if ($exp instanceof \JKingWeb\Arsse\AbstractException) { try {
$this->assertException($exp); if ($exp instanceof \JKingWeb\Arsse\AbstractException) {
API::userRegister($user, $password); $this->assertException($exp);
} else { API::userRegister($user, $password);
$this->assertSame($exp, API::userRegister($user, $password)); } else {
$this->assertSame($exp, API::userRegister($user, $password));
}
} finally {
\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)->tokenRevoke($user, "fever.login");
\Phake::verify(Arsse::$db)->tokenCreate($user, "fever.login", md5($user.":".($password ?? "RANDOM_PASSWORD")));
} }
public function providePasswordCreations() { public function providePasswordCreations() {

Loading…
Cancel
Save