From c8e9804a15794ca560b3253e4dfc106fce599602 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 6 May 2014 18:15:35 +0200 Subject: [PATCH] Changed privilege tests to be more generic --- lib/chibi-core | 2 +- tests/AbstractFullApiTest.php | 30 +++ tests/Api/ApiAuthTest.php | 74 +++++++ tests/Api/ApiEmailRequirementsTest.php | 105 ++++++++++ tests/Api/ApiPrivilegeTest.php | 186 ++++++++++++++++++ tests/JobTests/AddCommentJobTest.php | 32 --- tests/JobTests/DeleteCommentJobTest.php | 51 ----- tests/JobTests/EditCommentJobTest.php | 64 ------ tests/JobTests/EditPostContentJobTest.php | 55 ------ tests/JobTests/EditPostSourceJobTest.php | 64 ------ tests/JobTests/ListCommentsJobTest.php | 8 - tests/JobTests/PreviewCommentJobTest.php | 22 --- .../AuthTest.php} | 2 +- 13 files changed, 397 insertions(+), 298 deletions(-) create mode 100644 tests/AbstractFullApiTest.php create mode 100644 tests/Api/ApiAuthTest.php create mode 100644 tests/Api/ApiEmailRequirementsTest.php create mode 100644 tests/Api/ApiPrivilegeTest.php rename tests/{BasicAuthTest.php => MiscTests/AuthTest.php} (98%) diff --git a/lib/chibi-core b/lib/chibi-core index 45c662d0..5e78e0a6 160000 --- a/lib/chibi-core +++ b/lib/chibi-core @@ -1 +1 @@ -Subproject commit 45c662d0a4b32e09399b5b68ac53aaa3f1a29911 +Subproject commit 5e78e0a68a1188851d12e26c0f58c1ffe95ffb69 diff --git a/tests/AbstractFullApiTest.php b/tests/AbstractFullApiTest.php new file mode 100644 index 00000000..c16ec388 --- /dev/null +++ b/tests/AbstractFullApiTest.php @@ -0,0 +1,30 @@ +testedJobs); + $allJobs = $this->getAllJobs(); + foreach ($allJobs as $x) + { + if (!in_array($x, $testedJobs)) + $this->assert->fail($x . ' appears to be untested'); + } + } + + protected function getAllJobs() + { + $files = glob(getConfig()->rootDir . DS . 'src' . DS . 'Api' . DS . 'Jobs' . DS . '*.php'); + \Chibi\Util\Reflection::loadClasses($files); + return array_filter(get_declared_classes(), function($x) + { + $class = new ReflectionClass($x); + return !$class->isAbstract() and $class->isSubClassOf('AbstractJob'); + }); + } +} diff --git a/tests/Api/ApiAuthTest.php b/tests/Api/ApiAuthTest.php new file mode 100644 index 00000000..58ba77ff --- /dev/null +++ b/tests/Api/ApiAuthTest.php @@ -0,0 +1,74 @@ +testAuth(new AcceptUserRegistrationJob(), false); + $this->testAuth(new ActivateUserEmailJob(), false); + $this->testAuth(new AddPostJob(), false); + $this->testAuth(new AddCommentJob(), false); + $this->testAuth(new AddUserJob(), false); + $this->testAuth(new DeletePostJob(), true); + $this->testAuth(new DeleteCommentJob(), true); + $this->testAuth(new DeleteUserJob(), false); + $this->testAuth(new EditCommentJob(), true); + $this->testAuth(new EditPostContentJob(), false); + $this->testAuth(new EditPostJob(), false); + $this->testAuth(new EditPostRelationsJob(), false); + $this->testAuth(new EditPostSafetyJob(), false); + $this->testAuth(new EditPostSourceJob(), false); + $this->testAuth(new EditPostTagsJob(), false); + $this->testAuth(new EditPostThumbJob(), false); + $this->testAuth(new EditUserAccessRankJob(), false); + $this->testAuth(new EditUserEmailJob(), false); + $this->testAuth(new EditUserJob(), false); + $this->testAuth(new EditUserNameJob(), false); + $this->testAuth(new EditUserPasswordJob(), false); + $this->testAuth(new FeaturePostJob(), true); + $this->testAuth(new FlagPostJob(), false); + $this->testAuth(new FlagUserJob(), false); + $this->testAuth(new GetLogJob(), false); + $this->testAuth(new GetPostContentJob(), false); + $this->testAuth(new GetPostJob(), false); + $this->testAuth(new GetPostThumbJob(), false); + $this->testAuth(new GetUserJob(), false); + $this->testAuth(new ListCommentsJob(), false); + $this->testAuth(new ListLogsJob(), false); + $this->testAuth(new ListPostsJob(), false); + $this->testAuth(new ListRelatedTagsJob(), false); + $this->testAuth(new ListTagsJob(), false); + $this->testAuth(new ListUsersJob(), false); + $this->testAuth(new MergeTagsJob(), false); + $this->testAuth(new PasswordResetJob(), false); + $this->testAuth(new PreviewCommentJob(), false); + $this->testAuth(new RenameTagsJob(), false); + $this->testAuth(new ScorePostJob(), true); + $this->testAuth(new TogglePostFavoriteJob(), true); + $this->testAuth(new TogglePostTagJob(), false); + $this->testAuth(new TogglePostVisibilityJob(), false); + $this->testAuth(new ToggleUserBanJob(), false); + } + + protected function testAuth($job, $expectedAuth) + { + $this->testedJobs []= $job; + $this->assert->areEqual($expectedAuth, $job->requiresAuthentication()); + } + + public function testAuthEnforcing() + { + getConfig()->registration->needEmailForCommenting = false; + $this->grantAccess('addComment'); + + $comment = $this->mockComment(Auth::getCurrentUser()); + + $this->assert->throws(function() use ($comment) + { + return Api::run( + new DeleteCommentJob(), + [ + DeleteCommentJob::COMMENT_ID => $comment->getId(), + ]); + }, 'Not logged in'); + } +} diff --git a/tests/Api/ApiEmailRequirementsTest.php b/tests/Api/ApiEmailRequirementsTest.php new file mode 100644 index 00000000..8b3cb0f6 --- /dev/null +++ b/tests/Api/ApiEmailRequirementsTest.php @@ -0,0 +1,105 @@ +registration->needEmailForCommenting = true; + getConfig()->registration->needEmailForUploading = true; + + $this->testRegularEmailRequirement(new AcceptUserRegistrationJob()); + $this->testRegularEmailRequirement(new ActivateUserEmailJob()); + $this->testRegularEmailRequirement(new AddUserJob()); + $this->testRegularEmailRequirement(new DeletePostJob()); + $this->testRegularEmailRequirement(new DeleteCommentJob()); + $this->testRegularEmailRequirement(new DeleteUserJob()); + $this->testRegularEmailRequirement(new EditCommentJob()); + $this->testRegularEmailRequirement(new EditPostContentJob()); + $this->testRegularEmailRequirement(new EditPostJob()); + $this->testRegularEmailRequirement(new EditPostRelationsJob()); + $this->testRegularEmailRequirement(new EditPostSafetyJob()); + $this->testRegularEmailRequirement(new EditPostSourceJob()); + $this->testRegularEmailRequirement(new EditPostTagsJob()); + $this->testRegularEmailRequirement(new EditPostThumbJob()); + $this->testRegularEmailRequirement(new EditUserAccessRankJob()); + $this->testRegularEmailRequirement(new EditUserEmailJob()); + $this->testRegularEmailRequirement(new EditUserJob()); + $this->testRegularEmailRequirement(new EditUserNameJob()); + $this->testRegularEmailRequirement(new EditUserPasswordJob()); + $this->testRegularEmailRequirement(new FeaturePostJob()); + $this->testRegularEmailRequirement(new FlagPostJob()); + $this->testRegularEmailRequirement(new FlagUserJob()); + $this->testRegularEmailRequirement(new GetLogJob()); + $this->testRegularEmailRequirement(new GetPostContentJob()); + $this->testRegularEmailRequirement(new GetPostJob()); + $this->testRegularEmailRequirement(new GetPostThumbJob()); + $this->testRegularEmailRequirement(new GetUserJob()); + $this->testRegularEmailRequirement(new ListCommentsJob()); + $this->testRegularEmailRequirement(new ListLogsJob()); + $this->testRegularEmailRequirement(new ListPostsJob()); + $this->testRegularEmailRequirement(new ListRelatedTagsJob()); + $this->testRegularEmailRequirement(new ListTagsJob()); + $this->testRegularEmailRequirement(new ListUsersJob()); + $this->testRegularEmailRequirement(new MergeTagsJob()); + $this->testRegularEmailRequirement(new PasswordResetJob()); + $this->testRegularEmailRequirement(new RenameTagsJob()); + $this->testRegularEmailRequirement(new ScorePostJob()); + $this->testRegularEmailRequirement(new TogglePostFavoriteJob()); + $this->testRegularEmailRequirement(new TogglePostTagJob()); + $this->testRegularEmailRequirement(new TogglePostVisibilityJob()); + $this->testRegularEmailRequirement(new ToggleUserBanJob()); + } + + protected function testRegularEmailRequirement($job) + { + $this->testedJobs []= $job; + $this->assert->areEqual(false, $job->requiresConfirmedEmail()); + } + + public function testCommentsEmailRequirements() + { + $this->testCommentEmailRequirement(new AddCommentJob()); + $this->testCommentEmailRequirement(new PreviewCommentJob()); + } + + protected function testCommentEmailRequirement($job) + { + $this->testedJobs []= $job; + + getConfig()->registration->needEmailForCommenting = false; + $this->assert->areEqual(false, $job->requiresConfirmedEmail()); + + getConfig()->registration->needEmailForCommenting = true; + $this->assert->areEqual(true, $job->requiresConfirmedEmail()); + } + + public function testPostingEmailRequirement() + { + $job = new AddPostJob(); + + $this->testedJobs []= $job; + + getConfig()->registration->needEmailForUploading = false; + $this->assert->areEqual(false, $job->requiresConfirmedEmail()); + + getConfig()->registration->needEmailForUploading = true; + $this->assert->areEqual(true, $job->requiresConfirmedEmail()); + } + + public function testEnforcing() + { + $this->grantAccess('addComment'); + $this->login($this->mockUser()); + getConfig()->registration->needEmailForCommenting = true; + $this->assert->throws(function() + { + $post = $this->mockPost(Auth::getCurrentUser()); + + return Api::run( + new AddCommentJob(), + [ + AddCommentJob::POST_ID => $post->getId(), + AddCommentJob::TEXT => 'alohaaa', + ]); + }, 'Need e-mail'); + } +} diff --git a/tests/Api/ApiPrivilegeTest.php b/tests/Api/ApiPrivilegeTest.php new file mode 100644 index 00000000..9bd60e04 --- /dev/null +++ b/tests/Api/ApiPrivilegeTest.php @@ -0,0 +1,186 @@ +assert->areNotEqual($priv1, $priv2); + $this->assert->areEquivalent($priv1, $priv2); + } + + public function testRegularPrivileges() + { + $this->testRegularPrivilege(new AcceptUserRegistrationJob(), new Privilege(Privilege::AcceptUserRegistration)); + $this->testRegularPrivilege(new ActivateUserEmailJob(), false); + $this->testRegularPrivilege(new AddCommentJob(), new Privilege(Privilege::AddComment)); + $this->testRegularPrivilege(new PreviewCommentJob(), new Privilege(Privilege::AddComment)); + $this->testRegularPrivilege(new AddPostJob(), new Privilege(Privilege::UploadPost)); + $this->testRegularPrivilege(new AddUserJob(), new Privilege(Privilege::RegisterAccount)); + $this->testRegularPrivilege(new EditPostJob(), false); + $this->testRegularPrivilege(new EditUserJob(), false); + $this->testRegularPrivilege(new GetLogJob(), new Privilege(Privilege::ViewLog)); + $this->testRegularPrivilege(new ListCommentsJob(), new Privilege(Privilege::ListComments)); + $this->testRegularPrivilege(new ListLogsJob(), new Privilege(Privilege::ListLogs)); + $this->testRegularPrivilege(new ListPostsJob(), new Privilege(Privilege::ListPosts)); + $this->testRegularPrivilege(new ListRelatedTagsJob(), new Privilege(Privilege::ListTags)); + $this->testRegularPrivilege(new ListTagsJob(), new Privilege(Privilege::ListTags)); + $this->testRegularPrivilege(new ListUsersJob(), new Privilege(Privilege::ListUsers)); + $this->testRegularPrivilege(new PasswordResetJob(), false); + $this->testRegularPrivilege(new MergeTagsJob(), new Privilege(Privilege::MergeTags)); + $this->testRegularPrivilege(new RenameTagsJob(), new Privilege(Privilege::RenameTags)); + } + + protected function testRegularPrivilege($job, $expectedPrivilege) + { + $this->testedJobs []= $job; + $this->assert->areEquivalent($expectedPrivilege, $job->requiresPrivilege()); + } + + public function testDynamicPostPrivileges() + { + $this->login($this->mockUser()); + + $this->testDynamicPostPrivilege(new DeletePostJob(), new Privilege(Privilege::DeletePost)); + $this->testDynamicPostPrivilege(new EditPostContentJob(), new Privilege(Privilege::EditPostContent)); + $this->testDynamicPostPrivilege(new EditPostRelationsJob(), new Privilege(Privilege::EditPostRelations)); + $this->testDynamicPostPrivilege(new EditPostSafetyJob(), new Privilege(Privilege::EditPostSafety)); + $this->testDynamicPostPrivilege(new EditPostSourceJob(), new Privilege(Privilege::EditPostSource)); + $this->testDynamicPostPrivilege(new EditPostTagsJob(), new Privilege(Privilege::EditPostTags)); + $this->testDynamicPostPrivilege(new EditPostThumbJob(), new Privilege(Privilege::EditPostThumb)); + $this->testDynamicPostPrivilege(new FeaturePostJob(), new Privilege(Privilege::FeaturePost)); + $this->testDynamicPostPrivilege(new FlagPostJob(), new Privilege(Privilege::FlagPost)); + $this->testDynamicPostPrivilege(new ScorePostJob(), new Privilege(Privilege::ScorePost)); + $this->testDynamicPostPrivilege(new TogglePostTagJob(), new Privilege(Privilege::EditPostTags)); + $this->testDynamicPostPrivilege(new TogglePostVisibilityJob(), new Privilege(Privilege::HidePost)); + $this->testDynamicPostPrivilege(new TogglePostFavoriteJob(), new Privilege(Privilege::FavoritePost)); + } + + protected function testDynamicPostPrivilege($job, $expectedPrivilege) + { + $this->testedJobs []= $job; + + $ownPost = $this->mockPost(Auth::getCurrentUser()); + $otherPost = $this->mockPost($this->mockUser()); + + $expectedPrivilege->secondary = 'all'; + $job->setArgument(AbstractJob::POST_ID, $otherPost->getId()); + $job->prepare(); + $this->assert->areEquivalent($expectedPrivilege, $job->requiresPrivilege()); + + $expectedPrivilege->secondary = 'own'; + $job->setArgument(AbstractJob::POST_ID, $ownPost->getId()); + $job->prepare(); + $this->assert->areEquivalent($expectedPrivilege, $job->requiresPrivilege()); + } + + public function testDynamicPostRetrievalPrivileges() + { + $jobs = + [ + new GetPostJob(), + new GetPostContentJob(), + ]; + + $post = $this->mockPost($this->mockUser()); + + foreach ($jobs as $job) + { + $this->testedJobs []= $job; + + $post->setHidden(true); + PostModel::save($post); + + $job->setArgument(AbstractJob::POST_ID, $post->getId()); + $job->setArgument(AbstractJob::POST_NAME, $post->getName()); + $job->prepare(); + $this->assert->areEquivalent([ + new Privilege(Privilege::ViewPost, 'hidden'), + new Privilege(Privilege::ViewPost, 'safe')], $job->requiresPrivilege()); + } + } + + public function testDynamicPostThumbPrivileges() + { + $job = new GetPostThumbJob(); + $this->testedJobs []= $job; + $this->assert->areEquivalent(false, $job->requiresPrivilege()); + } + + public function testDynamicUserPrivileges() + { + $ownUser = $this->mockUser(); + $this->login($ownUser); + + $this->testDynamicUserPrivilege(new DeleteUserJob(), new Privilege(Privilege::DeleteUser)); + $this->testDynamicUserPrivilege(new EditUserAccessRankJob(), new Privilege(Privilege::ChangeUserAccessRank)); + $this->testDynamicUserPrivilege(new EditUserEmailJob(), new Privilege(Privilege::ChangeUserEmail)); + $this->testDynamicUserPrivilege(new EditUserNameJob(), new Privilege(Privilege::ChangeUserName)); + $this->testDynamicUserPrivilege(new EditUserPasswordJob(), new Privilege(Privilege::ChangeUserPassword)); + $this->testDynamicUserPrivilege(new FlagUserJob(), new Privilege(Privilege::FlagUser)); + $this->testDynamicUserPrivilege(new GetUserJob(), new Privilege(Privilege::ViewUser)); + $this->testDynamicUserPrivilege(new ToggleUserBanJob(), new Privilege(Privilege::BanUser)); + } + + protected function testDynamicUserPrivilege($job, $expectedPrivilege) + { + $ownUser = Auth::getCurrentUser(); + + $otherUser = $this->mockUser($this->mockUser()); + $otherUser->setName('somebody-else'); + UserModel::save($otherUser); + + $this->testedJobs []= $job; + + $expectedPrivilege->secondary = 'own'; + $job->setArgument(AbstractJob::USER_NAME, $ownUser->getName()); + $job->prepare(); + $this->assert->areEquivalent($expectedPrivilege, $job->requiresPrivilege()); + + $expectedPrivilege->secondary = 'all'; + $job->setArgument(AbstractJob::USER_NAME, $otherUser->getName()); + $job->prepare(); + $this->assert->areEquivalent($expectedPrivilege, $job->requiresPrivilege()); + } + + public function testDynamicCommentPrivileges() + { + $this->login($this->mockUser()); + + $this->testDynamicCommentPrivilege(new DeleteCommentJob(), new Privilege(Privilege::DeleteComment)); + $this->testDynamicCommentPrivilege(new EditCommentJob(), new Privilege(Privilege::EditComment)); + } + + protected function testDynamicCommentPrivilege($job, $expectedPrivilege) + { + $ownComment = $this->mockComment(Auth::getCurrentUser()); + $otherComment = $this->mockComment($this->mockUser()); + + $this->testedJobs []= $job; + + $expectedPrivilege->secondary = 'own'; + $job->setArgument(AbstractJob::COMMENT_ID, $ownComment->getId()); + $job->prepare(); + $this->assert->areEquivalent($expectedPrivilege, $job->requiresPrivilege()); + + $expectedPrivilege->secondary = 'all'; + $job->setArgument(AbstractJob::COMMENT_ID, $otherComment->getId()); + $job->prepare(); + $this->assert->areEquivalent($expectedPrivilege, $job->requiresPrivilege()); + } + + public function testPrivilegeEnforcing() + { + $this->assert->throws(function() + { + $post = $this->mockPost(Auth::getCurrentUser()); + getConfig()->registration->needEmailForCommenting = false; + return Api::run( + new AddCommentJob(), + [ + AddCommentJob::POST_ID => $post->getId(), + AddCommentJob::TEXT => 'alohaaa', + ]); + }, 'Insufficient privileges'); + } +} diff --git a/tests/JobTests/AddCommentJobTest.php b/tests/JobTests/AddCommentJobTest.php index cb685773..717b580f 100644 --- a/tests/JobTests/AddCommentJobTest.php +++ b/tests/JobTests/AddCommentJobTest.php @@ -24,16 +24,6 @@ class AddCommentJobTest extends AbstractTest }); } - public function testEmailActivation() - { - $this->prepare(); - getConfig()->registration->needEmailForCommenting = true; - $this->assert->throws(function() - { - $this->runApi('alohaaaa'); - }, 'Need e-mail'); - } - public function testAlmostTooShortText() { $this->prepare(); @@ -70,28 +60,6 @@ class AddCommentJobTest extends AbstractTest }, 'Comment must have at most'); } - public function testNoAuth() - { - $this->prepare(); - Auth::setCurrentUser(null); - - $this->assert->doesNotThrow(function() - { - $this->runApi('alohaaaaaaa'); - }); - } - - public function testAccessDenial() - { - $this->prepare(); - $this->revokeAccess('addComment'); - - $this->assert->throws(function() - { - $this->runApi('alohaaaaaaa'); - }, 'Insufficient privileges'); - } - public function testAnonymous() { $this->prepare(); diff --git a/tests/JobTests/DeleteCommentJobTest.php b/tests/JobTests/DeleteCommentJobTest.php index 1c2a1e3c..ba5c9b52 100644 --- a/tests/JobTests/DeleteCommentJobTest.php +++ b/tests/JobTests/DeleteCommentJobTest.php @@ -14,57 +14,6 @@ class DeleteCommentJobTest extends AbstractTest $this->assert->areEqual(0, CommentModel::getCount()); } - public function testNoAuth() - { - $this->prepare(); - Auth::setCurrentUser(null); - - $this->assert->throws(function() - { - $this->runApi(); - }, 'Not logged in'); - } - - public function testOwnAccessDenial() - { - $this->prepare(); - - $this->assert->throws(function() - { - $this->runApi(); - }, 'Insufficient privileges'); - } - - public function testOtherAccessGrant() - { - $this->prepare(); - $this->grantAccess('deleteComment.all'); - - $comment = $this->mockComment(Auth::getCurrentUser()); - //login as someone else - $this->login($this->mockUser()); - - $this->assert->doesNotThrow(function() use ($comment) - { - $this->runApi($comment); - }); - } - - public function testOtherAccessDenial() - { - $this->prepare(); - $this->grantAccess('deleteComment.own'); - - $comment = $this->mockComment(Auth::getCurrentUser()); - //login as someone else - $this->login($this->mockUser()); - - $this->assert->throws(function() use ($comment) - { - $this->runApi($comment); - }, 'Insufficient privileges'); - } - public function testWrongCommentId() { $this->prepare(); diff --git a/tests/JobTests/EditCommentJobTest.php b/tests/JobTests/EditCommentJobTest.php index a7dfd86b..4d0ed7cb 100644 --- a/tests/JobTests/EditCommentJobTest.php +++ b/tests/JobTests/EditCommentJobTest.php @@ -62,70 +62,6 @@ class EditCommentJobTest extends AbstractTest }, 'Comment must have at most'); } - public function testNoAuth() - { - $this->prepare(); - $this->grantAccess('editComment'); - Auth::setCurrentUser(null); - - $this->assert->throws(function() - { - $this->runApi('alohaaaaaaa'); - }, 'Not logged in'); - } - - public function testOwnAccessDenial() - { - $this->prepare(); - - $this->assert->throws(function() - { - $this->runApi('alohaaaaaaa'); - }, 'Insufficient privileges'); - } - - public function testOtherAccessGrant() - { - $this->prepare(); - $this->grantAccess('editComment.all'); - - $comment = $this->mockComment(Auth::getCurrentUser()); - - //login as someone else - $this->login($this->mockUser()); - - $this->assert->doesNotThrow(function() use ($comment) - { - Api::run( - new EditCommentJob(), - [ - EditCommentJob::COMMENT_ID => $comment->getId(), - EditCommentJob::TEXT => 'alohaa', - ]); - }); - } - - public function testOtherAccessDenial() - { - $this->prepare(); - $this->grantAccess('editComment.own'); - - $comment = $this->mockComment(Auth::getCurrentUser()); - - //login as someone else - $this->login($this->mockUser()); - - $this->assert->throws(function() use ($comment) - { - Api::run( - new EditCommentJob(), - [ - EditCommentJob::COMMENT_ID => $comment->getId(), - EditCommentJob::TEXT => 'alohaa', - ]); - }, 'Insufficient privileges'); - } - public function testWrongCommentId() { $this->prepare(); diff --git a/tests/JobTests/EditPostContentJobTest.php b/tests/JobTests/EditPostContentJobTest.php index 88903a21..77a22470 100644 --- a/tests/JobTests/EditPostContentJobTest.php +++ b/tests/JobTests/EditPostContentJobTest.php @@ -103,61 +103,6 @@ class EditPostContentJobTest extends AbstractTest }); } - public function testNoAuth() - { - $this->prepare(); - $this->grantAccess('editPostContent'); - Auth::setCurrentUser(null); - - $this->assert->doesNotThrow(function() - { - $this->uploadFromFile('image.jpg'); - }); - } - - public function testOwnAccessDenial() - { - $this->prepare(); - - $this->assert->throws(function() - { - $this->uploadFromFile('image.jpg'); - }, 'Insufficient privileges'); - } - - public function testOtherAccessGrant() - { - $this->prepare(); - $this->grantAccess('editPostContent.all'); - - $post = $this->mockPost(Auth::getCurrentUser()); - - //login as someone else - $this->login($this->mockUser()); - - $this->assert->doesNotThrow(function() use ($post) - { - $this->uploadFromFile('image.jpg', $post); - }); - } - - public function testOtherAccessDenial() - { - $this->prepare(); - $this->grantAccess('editPostContent.own'); - - $post = $this->mockPost(Auth::getCurrentUser()); - - //login as someone else - $this->login($this->mockUser()); - - $this->assert->throws(function() use ($post) - { - $this->uploadFromFile('image.jpg', $post); - }, 'Insufficient privileges'); - } - - public function testWrongPostId() { $this->assert->throws(function() diff --git a/tests/JobTests/EditPostSourceJobTest.php b/tests/JobTests/EditPostSourceJobTest.php index 6a43a32f..492854b9 100644 --- a/tests/JobTests/EditPostSourceJobTest.php +++ b/tests/JobTests/EditPostSourceJobTest.php @@ -37,70 +37,6 @@ class EditPostSourceJobTest extends AbstractTest }, 'Source must have at most'); } - public function testNoAuth() - { - $this->prepare(); - $this->grantAccess('editPostSource'); - Auth::setCurrentUser(null); - - $this->assert->doesNotThrow(function() - { - $this->runApi('alohaaaaaaa'); - }); - } - - public function testOwnAccessDenial() - { - $this->prepare(); - - $this->assert->throws(function() - { - $this->runApi('alohaaaaaaa'); - }, 'Insufficient privileges'); - } - - public function testOtherAccessGrant() - { - $this->prepare(); - $this->grantAccess('editPostSource.all'); - - $post = $this->mockPost(Auth::getCurrentUser()); - - //login as someone else - $this->login($this->mockUser()); - - $this->assert->doesNotThrow(function() use ($post) - { - Api::run( - new EditPostSourceJob(), - [ - EditPostSourceJob::POST_ID => $post->getId(), - EditPostSourceJob::SOURCE => 'alohaa', - ]); - }); - } - - public function testOtherAccessDenial() - { - $this->prepare(); - $this->grantAccess('editPostSource.own'); - - $post = $this->mockPost(Auth::getCurrentUser()); - - //login as someone else - $this->login($this->mockUser()); - - $this->assert->throws(function() use ($post) - { - Api::run( - new EditPostSourceJob(), - [ - EditPostSourceJob::POST_ID => $post->getId(), - EditPostSourceJob::SOURCE => 'alohaa', - ]); - }, 'Insufficient privileges'); - } - public function testWrongPostId() { $this->prepare(); diff --git a/tests/JobTests/ListCommentsJobTest.php b/tests/JobTests/ListCommentsJobTest.php index 01af6caf..4735c162 100644 --- a/tests/JobTests/ListCommentsJobTest.php +++ b/tests/JobTests/ListCommentsJobTest.php @@ -55,14 +55,6 @@ class ListCommentJobTest extends AbstractTest $this->assert->areEqual(1, count($ret->entities)); } - public function testAccessDenial() - { - $this->assert->throws(function() - { - $this->runApi(1); - }, 'Insufficient privileges'); - } - protected function runApi($page) { return Api::run( diff --git a/tests/JobTests/PreviewCommentJobTest.php b/tests/JobTests/PreviewCommentJobTest.php index 215ca26d..e29d7850 100644 --- a/tests/JobTests/PreviewCommentJobTest.php +++ b/tests/JobTests/PreviewCommentJobTest.php @@ -57,28 +57,6 @@ class PreviewCommentJobTest extends AbstractTest }, 'Comment must have at most'); } - public function testNoAuth() - { - $this->prepare(); - Auth::setCurrentUser(null); - - $this->assert->doesNotThrow(function() - { - return $this->runApi('alohaaaaaaa'); - }); - } - - public function testAccessDenial() - { - $this->prepare(); - $this->revokeAccess('addComment'); - - $this->assert->throws(function() - { - return $this->runApi('alohaaaaaaa'); - }, 'Insufficient privileges'); - } - protected function runApi($text) { diff --git a/tests/BasicAuthTest.php b/tests/MiscTests/AuthTest.php similarity index 98% rename from tests/BasicAuthTest.php rename to tests/MiscTests/AuthTest.php index 66d1070b..f301507a 100644 --- a/tests/BasicAuthTest.php +++ b/tests/MiscTests/AuthTest.php @@ -1,5 +1,5 @@