1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-06-27 16:36:00 +00:00

Merge pull request #8098 from wallabag/add-isgranted-to-entryrestcontroller

Add IsGranted to EntryRestController
This commit is contained in:
Yassine Guedidi 2025-03-18 12:34:57 +01:00 committed by GitHub
commit 7e9e179860
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 115 additions and 86 deletions

View file

@ -6,7 +6,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\Container;
use Wallabag\Entity\Entry;
use Wallabag\Entity\Tag;
use Wallabag\Entity\User;
use Wallabag\Helper\ContentProxy;
class EntryRestControllerTest extends WallabagApiTestCase
@ -535,13 +534,13 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testDeleteEntry()
{
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = new Entry($em->getReference(User::class, 1));
$entry = new Entry($this->user);
$entry->setUrl('http://0.0.0.0/test-delete-entry');
$entry->setTitle('Test delete entry');
$em->persist($entry);
$em->flush();
$em->clear();
$this->client = $this->createAuthorizedClient();
$e = [
'title' => $entry->getTitle(),
@ -569,12 +568,12 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testDeleteEntryExpectId()
{
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = new Entry($em->getReference(User::class, 1));
$entry = new Entry($this->user);
$entry->setUrl('http://0.0.0.0/test-delete-entry-id');
$em->persist($entry);
$em->flush();
$em->clear();
$this->client = $this->createAuthorizedClient();
$id = $entry->getId();
@ -659,14 +658,15 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testPostSameEntry()
{
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = new Entry($em->getReference(User::class, $this->getUserId()));
$entry = new Entry($this->user);
$entry->setUrl('https://www.20minutes.fr/sport/jo_2024/4095122-20240712-jo-paris-2024-saut-ange-bombe-comment-anne-hidalgo-va-plonger-seine-si-fait-vraiment');
$entry->setArchived(true);
$entry->addTag((new Tag())->setLabel('google'));
$entry->addTag((new Tag())->setLabel('apple'));
$em->persist($entry);
$em->flush();
$em->clear();
$this->client = $this->createAuthorizedClient();
$this->client->request('POST', '/api/entries.json', [
'url' => 'https://www.20minutes.fr/sport/jo_2024/4095122-20240712-jo-paris-2024-saut-ange-bombe-comment-anne-hidalgo-va-plonger-seine-si-fait-vraiment',
@ -1354,14 +1354,14 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testDeleteEntriesTagsListAction()
{
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = new Entry($em->getReference(User::class, $this->getUserId()));
$entry = new Entry($this->user);
$entry->setUrl('http://0.0.0.0/test-entry');
$entry->addTag((new Tag())->setLabel('foo-tag'));
$entry->addTag((new Tag())->setLabel('bar-tag'));
$em->persist($entry);
$em->flush();
$em->clear();
$this->client = $this->createAuthorizedClient();
$list = [
[
@ -1422,10 +1422,12 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testDeleteEntriesListAction()
{
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$em->persist((new Entry($em->getReference(User::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1'));
$em->persist((new Entry($this->user))->setUrl('http://0.0.0.0/test-entry1'));
$em->flush();
$em->clear();
$this->client = $this->createAuthorizedClient();
$list = [
'http://0.0.0.0/test-entry1',
'http://0.0.0.0/test-entry-not-exist',
@ -1480,14 +1482,15 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testRePostEntryAndReUsePublishedAt()
{
$em = $this->client->getContainer()->get(EntityManagerInterface::class);
$entry = new Entry($em->getReference(User::class, $this->getUserId()));
$entry = new Entry($this->user);
$entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »');
$entry->setContent('hihi');
$entry->setUrl('https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html');
$entry->setPublishedAt(new \DateTime('2017-06-26T07:46:02+0200'));
$em->persist($entry);
$em->flush();
$em->clear();
$this->client = $this->createAuthorizedClient();
$this->client->request('POST', '/api/entries.json', [
'url' => 'https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html',

View file

@ -49,7 +49,8 @@ class TagRestControllerTest extends WallabagApiTestCase
$em->persist($entry);
$em->flush();
$em->clear();
$this->client = $this->createAuthorizedClient();
$this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json');

View file

@ -80,7 +80,8 @@ class ConfigControllerTest extends WallabagTestCase
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
$crawler = $client->request('GET', '/unread/list');
$form = $crawler->filter('button[id=submit-filter]')->form();

View file

@ -538,7 +538,8 @@ class EntryControllerTest extends WallabagTestCase
$entry->setContent('');
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
$client->request('GET', '/reload/' . $entry->getId());
@ -670,7 +671,8 @@ class EntryControllerTest extends WallabagTestCase
$entry->setUrl($this->url);
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
$client->request('GET', '/archive/' . $entry->getId());
@ -693,7 +695,8 @@ class EntryControllerTest extends WallabagTestCase
$entry->setUrl($this->url);
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
$client->request('GET', '/star/' . $entry->getId());
@ -1200,7 +1203,8 @@ class EntryControllerTest extends WallabagTestCase
$content->setUrl($this->url);
$this->getEntityManager()->persist($content);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
// no uid
$client->request('GET', '/share/' . $content->getUid());
@ -1791,7 +1795,8 @@ class EntryControllerTest extends WallabagTestCase
$this->getEntityManager()->persist($entry3);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
$entries = [];
$entries[] = $entry1->getId();

View file

@ -35,7 +35,8 @@ class TagControllerTest extends WallabagTestCase
$entry->setUrl('http://0.0.0.0/foo');
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
$crawler = $client->request('GET', '/view/' . $entry->getId());
@ -120,7 +121,8 @@ class TagControllerTest extends WallabagTestCase
$entry->addTag($tag);
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
// We make a first request to set an history and test redirection after tag deletion
$crawler = $client->request('GET', '/view/' . $entry->getId());
@ -166,7 +168,8 @@ class TagControllerTest extends WallabagTestCase
$entry2->addTag($tag);
$this->getEntityManager()->persist($entry2);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
$crawler = $client->request('GET', '/tag/list');
$link = $crawler->filter('a[id="delete-' . $tag->getSlug() . '"]')->link();
@ -254,7 +257,8 @@ class TagControllerTest extends WallabagTestCase
$this->getEntityManager()->persist($entry2);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
// We make a first request to set an history and test redirection after tag deletion
$crawler = $client->request('GET', '/tag/list');
@ -321,7 +325,8 @@ class TagControllerTest extends WallabagTestCase
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
// We make a first request to set an history and test redirection after tag deletion
$crawler = $client->request('GET', '/tag/list');
@ -376,7 +381,8 @@ class TagControllerTest extends WallabagTestCase
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
// We make a first request to set an history and test redirection after tag deletion
$crawler = $client->request('GET', '/tag/list');
@ -446,7 +452,8 @@ class TagControllerTest extends WallabagTestCase
$this->getEntityManager()->persist($entry2);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
// We make a first request to set an history and test redirection after tag deletion
$crawler = $client->request('GET', '/tag/list');
@ -496,7 +503,8 @@ class TagControllerTest extends WallabagTestCase
$entry->setUrl('http://0.0.0.0/tag-caché');
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
$client = $this->getTestClient();
$crawler = $client->request('GET', '/view/' . $entry->getId());

View file

@ -189,6 +189,20 @@ class EntryVoterTest extends TestCase
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->entryVoter->vote($this->token, $this->entry, [EntryVoter::CREATE_ANNOTATIONS]));
}
public function testVoteReturnsDeniedForNonEntryUserListTags(): void
{
$this->token->method('getUser')->willReturn(new User());
$this->assertSame(VoterInterface::ACCESS_DENIED, $this->entryVoter->vote($this->token, $this->entry, [EntryVoter::LIST_TAGS]));
}
public function testVoteReturnsGrantedForEntryUserListTags(): void
{
$this->token->method('getUser')->willReturn($this->user);
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->entryVoter->vote($this->token, $this->entry, [EntryVoter::LIST_TAGS]));
}
public function testVoteReturnsDeniedForNonEntryUserTag(): void
{
$this->token->method('getUser')->willReturn(new User());

View file

@ -112,6 +112,20 @@ class MainVoterTest extends TestCase
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->mainVoter->vote($this->token, null, [MainVoter::IMPORT_ENTRIES]));
}
public function testVoteReturnsDeniedForNonUserDeleteEntries(): void
{
$this->security->method('isGranted')->with('ROLE_USER')->willReturn(false);
$this->assertSame(VoterInterface::ACCESS_DENIED, $this->mainVoter->vote($this->token, null, [MainVoter::DELETE_ENTRIES]));
}
public function testVoteReturnsGrantedForUserDeleteEntries(): void
{
$this->security->method('isGranted')->with('ROLE_USER')->willReturn(true);
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->mainVoter->vote($this->token, null, [MainVoter::DELETE_ENTRIES]));
}
public function testVoteReturnsDeniedForNonUserListTags(): void
{
$this->security->method('isGranted')->with('ROLE_USER')->willReturn(false);
@ -140,6 +154,20 @@ class MainVoterTest extends TestCase
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->mainVoter->vote($this->token, null, [MainVoter::CREATE_TAGS]));
}
public function testVoteReturnsDeniedForNonUserDeleteTags(): void
{
$this->security->method('isGranted')->with('ROLE_USER')->willReturn(false);
$this->assertSame(VoterInterface::ACCESS_DENIED, $this->mainVoter->vote($this->token, null, [MainVoter::DELETE_TAGS]));
}
public function testVoteReturnsGrantedForUserDeleteTags(): void
{
$this->security->method('isGranted')->with('ROLE_USER')->willReturn(true);
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->mainVoter->vote($this->token, null, [MainVoter::DELETE_TAGS]));
}
public function testVoteReturnsDeniedForNonUserListSiteCredentials(): void
{
$this->security->method('isGranted')->with('ROLE_USER')->willReturn(false);