2019-01-20 20:02:37 +00:00
|
|
|
<?php
|
|
|
|
namespace ActivityPub\Test\Auth;
|
|
|
|
|
2019-01-21 03:55:36 +00:00
|
|
|
use ActivityPub\Auth\AuthService;
|
2019-01-23 16:37:05 +00:00
|
|
|
use ActivityPub\Test\TestUtils\TestActivityPubObject;
|
2019-02-07 03:48:00 +00:00
|
|
|
use ActivityPub\Test\TestConfig\APTestCase;
|
2019-01-21 03:55:36 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2019-01-20 20:02:37 +00:00
|
|
|
|
2019-02-07 03:48:00 +00:00
|
|
|
class AuthServiceTest extends APTestCase
|
2019-01-20 20:02:37 +00:00
|
|
|
{
|
2019-02-14 03:27:47 +00:00
|
|
|
/**
|
|
|
|
* @var AuthService
|
|
|
|
*/
|
2019-01-21 03:55:36 +00:00
|
|
|
private $authService;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->authService = new AuthService();
|
|
|
|
}
|
|
|
|
|
2019-01-20 20:02:37 +00:00
|
|
|
public function testAuthService()
|
|
|
|
{
|
2019-01-21 03:55:36 +00:00
|
|
|
$testCases = array(
|
|
|
|
array(
|
|
|
|
'id' => 'addressedTo',
|
|
|
|
'actor' => 'https://example.com/actor/1',
|
|
|
|
'object' => array(
|
|
|
|
'to' => 'https://example.com/actor/1',
|
|
|
|
),
|
|
|
|
'expectedResult' => true,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'noAuth',
|
|
|
|
'object' => array(
|
|
|
|
'to' => 'https://example.com/actor/1',
|
|
|
|
),
|
|
|
|
'expectedResult' => false,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'noAudience',
|
|
|
|
'object' => array(
|
|
|
|
'type' => 'Note'
|
|
|
|
),
|
|
|
|
'expectedResult' => true,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'actor',
|
|
|
|
'object' => array(
|
|
|
|
'actor' => 'https://example.com/actor/1',
|
|
|
|
'to' => 'https://example.com/actor/2',
|
|
|
|
),
|
|
|
|
'actor' => 'https://example.com/actor/1',
|
|
|
|
'expectedResult' => true,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'id' => 'attributedTo',
|
|
|
|
'object' => array(
|
|
|
|
'attributedTo' => 'https://example.com/actor/1',
|
|
|
|
'to' => 'https://example.com/actor/2',
|
|
|
|
),
|
|
|
|
'actor' => 'https://example.com/actor/1',
|
|
|
|
'expectedResult' => true,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
foreach ( $testCases as $testCase ) {
|
|
|
|
$request = Request::create( 'https://example.com/objects/1' );
|
|
|
|
if ( array_key_exists( 'actor', $testCase ) ) {
|
|
|
|
$request->attributes->set( 'actor', $testCase['actor'] );
|
|
|
|
}
|
2019-01-23 16:37:05 +00:00
|
|
|
$object = TestActivityPubObject::fromArray( $testCase['object'] );
|
2019-01-21 03:55:36 +00:00
|
|
|
$actual = $this->authService->isAuthorized( $request, $object );
|
|
|
|
$this->assertEquals(
|
|
|
|
$testCase['expectedResult'], $actual, "Error on test $testCase[id]"
|
|
|
|
);
|
|
|
|
}
|
2019-01-20 20:02:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-07 03:48:00 +00:00
|
|
|
|