Refactor slightly the indieauth code

This commit is contained in:
Jonny Barnes 2017-03-01 20:59:09 +00:00
parent 4f57905bcc
commit fe8f871e3a
5 changed files with 70 additions and 59 deletions

View file

@ -15,8 +15,8 @@ class IndieAuthControllerTest extends TestCase
*/
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'));
$response = $this->call('POST', '/indieauth/start', ['me' => 'http://example.org']);
$this->assertSame(route('micropub-client'), $response->headers->get('Location'));
}
/**
@ -26,7 +26,7 @@ class IndieAuthControllerTest extends TestCase
*/
public function test_indieauthcontroller_begin_auth_redirects_to_endpoint()
{
$response = $this->call('GET', '/indieauth/start', ['me' => config('app.url')]);
$response = $this->call('POST', '/indieauth/start', ['me' => config('app.url')]);
$this->assertSame(
'https://indieauth.com/auth?me=',
substr($response->headers->get('Location'), 0, 30)
@ -46,6 +46,6 @@ class IndieAuthControllerTest extends TestCase
'indieauth/callback',
['me', config('app.url'), 'state' => 'request-session']
);
$response->assertSessionHasErrors();
$response->assertSessionHas(['error' => 'Invalid <code>state</code> value returned from indieauth server']);
}
}

View file

@ -16,11 +16,22 @@ class IndieAuthServiceTest extends TestCase
public function test_indieauthservice_getauthorizationendpoint_method()
{
$service = new \App\Services\IndieAuthService();
$client = new \IndieAuth\Client();
$result = $service->getAuthorizationEndpoint(config('app.url'), $client);
$result = $service->getAuthorizationEndpoint(config('app.url'));
$this->assertEquals('https://indieauth.com/auth', $result);
}
/**
* Test the getAuthorizationEndpoint method returns null on failure.
*
* @return void
*/
public function test_indieauthservice_getauthorizationendpoint_method_returns_null_on_failure()
{
$service = new \App\Services\IndieAuthService();
$result = $service->getAuthorizationEndpoint('http://example.org');
$this->assertEquals(null, $result);
}
/**
* Test that the Service build the correct redirect URL.
*
@ -29,11 +40,9 @@ class IndieAuthServiceTest extends TestCase
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
config('app.url')
);
$this->assertEquals(
'https://indieauth.com/auth?me=',
@ -49,8 +58,7 @@ class IndieAuthServiceTest extends TestCase
public function test_indieauthservice_gettokenendpoint_method()
{
$service = new \App\Services\IndieAuthService();
$client = new \IndieAuth\Client();
$result = $service->getTokenEndpoint(config('app.url'), $client);
$result = $service->getTokenEndpoint(config('app.url'));
$this->assertEquals(config('app.url') . '/api/token', $result);
}
@ -62,8 +70,7 @@ class IndieAuthServiceTest extends TestCase
public function test_indieauthservice_discovermicropubendpoint_method()
{
$service = new \App\Services\IndieAuthService();
$client = new \IndieAuth\Client();
$result = $service->discoverMicropubEndpoint(config('app.url'), $client);
$result = $service->discoverMicropubEndpoint(config('app.url'));
$this->assertEquals(config('app.url') . '/api/post', $result);
}
}