Browse Source

Tests fortoken operations

rpm
J. King 3 years ago
parent
commit
eae0ba4b68
  1. 2
      lib/REST/Miniflux/V1.php
  2. 40
      tests/cases/REST/Miniflux/TestV1.php

2
lib/REST/Miniflux/V1.php

@ -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);
}

40
tests/cases/REST/Miniflux/TestV1.php

@ -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");
}
}
Loading…
Cancel
Save