1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

Tests fortoken operations

This commit is contained in:
J. King 2021-02-07 19:20:10 -05:00
parent 9cc779a717
commit eae0ba4b68
2 changed files with 40 additions and 2 deletions

View file

@ -1203,7 +1203,7 @@ class V1 extends \JKingWeb\Arsse\REST\AbstractHandler {
}
public static function tokenGenerate(string $user, string $label): string {
// Miniflux produces tokenss in base64url alphabet
// Miniflux produces tokens in base64url alphabet
$t = str_replace(["+", "/"], ["-", "_"], base64_encode(random_bytes(self::TOKEN_LENGTH)));
return Arsse::$db->tokenCreate($user, "miniflux.login", $t, null, $label);
}

View file

@ -667,6 +667,14 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
];
}
public function testModifyAFeedWithNoBody(): void {
$this->h = \Phake::partialMock(V1::class);
\Phake::when($this->h)->getFeed->thenReturn(new Response(self::FEEDS_OUT[0]));
\Phake::when(Arsse::$db)->subscriptionPropertiesSet->thenReturn(true);
$this->assertMessage(new Response(self::FEEDS_OUT[0]), $this->req("PUT", "/feeds/2112", ""));
\Phake::verify(Arsse::$db)->subscriptionPropertiesSet(Arsse::$user->id, 2112, []);
}
public function testDeleteAFeed(): void {
\Phake::when(Arsse::$db)->subscriptionRemove->thenReturn(true);
$this->assertMessage(new EmptyResponse(204), $this->req("DELETE", "/feeds/2112"));
@ -971,4 +979,34 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
$this->assertMessage(new TextResponse("EXPORT DATA", 200, ['Content-Type' => "application/xml"]), $this->req("GET", "/export"));
\Phake::verify($opml)->export(Arsse::$user->id);
}
}
public function testGenerateTokens(): void {
\Phake::when(Arsse::$db)->tokenCreate->thenReturn("RANDOM TOKEN");
$this->assertSame("RANDOM TOKEN", V1::tokenGenerate("ook", "Eek"));
\Phake::verify(Arsse::$db)->tokenCreate("ook", "miniflux.login", \Phake::capture($token), null, "Eek");
$this->assertRegExp("/^[A-Za-z0-9_\-]{43}=$/", $token);
}
public function testListTheTokensOfAUser(): void {
$out = [
['id' => "TOKEN 1", 'data' => "Ook"],
['id' => "TOKEN 2", 'data' => "Eek"],
['id' => "TOKEN 3", 'data' => "Ack"],
];
$exp = [
['label' => "Ook", 'id' => "TOKEN 1"],
['label' => "Eek", 'id' => "TOKEN 2"],
['label' => "Ack", 'id' => "TOKEN 3"],
];
\Phake::when(Arsse::$db)->tokenList->thenReturn(new Result($this->v($out)));
\Phake::when(Arsse::$db)->userExists->thenReturn(true);
$this->assertSame($exp, V1::tokenList("john.doe@example.com"));
\Phake::verify(Arsse::$db)->tokenList("john.doe@example.com", "miniflux.login");
}
public function testListTheTokensOfAMissingUser(): void {
\Phake::when(Arsse::$db)->userExists->thenReturn(false);
$this->assertException("doesNotExist", "User", "ExceptionConflict");
V1::tokenList("john.doe@example.com");
}
}