Add Initial IndieAuth tests

This commit is contained in:
Jonny Barnes 2017-02-19 00:36:30 +00:00
parent 1c8f696024
commit 914fd5e881
2 changed files with 120 additions and 0 deletions

View file

@ -0,0 +1,51 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class IndieAuthControllerTest extends TestCase
{
/**
* Test the `start` method redirects to the client on error.
*
* @return void
*/
public function test_indieauthcontroller_begin_auth_flow_redirects_back_to_client_on_error()
{
$response = $this->call('GET', '/indieauth/start', ['me' => 'http://example.org']);
$this->assertSame(config('app.url') . '/micropub/create', $response->headers->get('Location'));
}
/**
* Now we test the `start` method as a whole.
*
* @return void
*/
public function test_indieauthcontroller_begin_auth_redirects_to_endpoint()
{
$response = $this->call('GET', '/indieauth/start', ['me' => config('app.url')]);
$this->assertSame(
'https://indieauth.com/auth?me=',
substr($response->headers->get('Location'), 0, 30)
);
}
/**
* Test the `callback` method.
*
* @return void
*/
public function test_indieauthcontroller_callback_method_gives_error_with_mismatched_state()
{
$response = $this->withSession(['state' => 'state-session'])
->call(
'GET',
'indieauth/callback',
['me', config('app.url'), 'state' => 'request-session']
);
$response->assertSessionHasErrors();
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class IndieAuthServiceTest extends TestCase
{
/**
* Test the getAuthorizationEndpoint method.
*
* @return void
*/
public function test_indieauthservice_getauthorizationendpoint_method()
{
$service = new \App\Services\IndieAuthService();
$client = new \IndieAuth\Client();
$result = $service->getAuthorizationEndpoint(config('app.url'), $client);
$this->assertEquals('https://indieauth.com/auth', $result);
}
/**
* Test that the Service build the correct redirect URL.
*
* @return void
*/
public function test_indieauthservice_builds_correct_redirect_url()
{
$service = new \App\Services\IndieAuthService();
$client = new \IndieAuth\Client();
$result = $service->buildAuthorizationURL(
'https://indieauth.com/auth',
config('app.url'),
$client
);
$this->assertEquals(
'https://indieauth.com/auth?me=',
substr($result, 0, 30)
);
}
/**
* Test the getTokenEndpoint method.
*
* @return void
*/
public function test_indieauthservice_gettokenendpoint_method()
{
$service = new \App\Services\IndieAuthService();
$client = new \IndieAuth\Client();
$result = $service->getTokenEndpoint(config('app.url'), $client);
$this->assertEquals(config('app.url') . '/api/token', $result);
}
/**
* Test the discoverMicropubEndpoint method.
*
* @return void
*/
public function test_indieauthservice_discovermicropubendpoint_method()
{
$service = new \App\Services\IndieAuthService();
$client = new \IndieAuth\Client();
$result = $service->discoverMicropubEndpoint(config('app.url'), $client);
$this->assertEquals(config('app.url') . '/api/post', $result);
}
}