szurubooru/tests/Tests/ApiTests/ApiAuthTest.php

79 lines
2.9 KiB
PHP
Raw Normal View History

<?php
class ApiAuthTest extends AbstractFullApiTest
{
public function testAllAuth()
{
$this->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 EditPostJob(), false);
2014-05-14 19:11:55 +02:00
$this->testAuth(new EditPostContentJob(), false);
$this->testAuth(new EditPostRelationsJob(), false);
$this->testAuth(new EditPostSafetyJob(), false);
$this->testAuth(new EditPostSourceJob(), false);
$this->testAuth(new EditPostTagsJob(), false);
$this->testAuth(new EditPostThumbnailJob(), false);
2014-05-14 19:11:55 +02:00
$this->testAuth(new EditUserJob(), false);
$this->testAuth(new EditUserAccessRankJob(), false);
$this->testAuth(new EditUserEmailJob(), false);
$this->testAuth(new EditUserNameJob(), false);
$this->testAuth(new EditUserPasswordJob(), false);
2014-05-20 19:46:05 +02:00
$this->testAuth(new EditUserAvatarJob(), false);
$this->testAuth(new EditUserSettingsJob(), false);
$this->testAuth(new FeaturePostJob(), true);
$this->testAuth(new FlagPostJob(), false);
$this->testAuth(new FlagUserJob(), false);
$this->testAuth(new GetLogJob(), false);
2014-05-14 19:11:55 +02:00
$this->testAuth(new GetPropertyJob(), false);
$this->testAuth(new GetPostJob(), false);
2014-05-14 19:11:55 +02:00
$this->testAuth(new GetPostContentJob(), false);
$this->testAuth(new GetPostThumbnailJob(), false);
$this->testAuth(new GetUserJob(), false);
$this->testAuth(new GetUserSettingsJob(), 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;
2014-05-12 10:31:34 +02:00
$this->assert->areEqual($expectedAuth, $job->isAuthenticationRequired());
}
public function testAuthEnforcing()
{
2014-05-26 12:30:23 +02:00
Core::getConfig()->comments->needEmailForCommenting = false;
$this->grantAccess('addComment');
$comment = $this->commentMocker->mockSingle();
$this->assert->throws(function() use ($comment)
{
return Api::run(
new DeleteCommentJob(),
[
JobArgs::ARG_COMMENT_ID => $comment->getId(),
]);
}, 'Not logged in');
}
}