Browse Source

Test skeleton for IndieAuth

microsub
J. King 5 years ago
parent
commit
7958cc6f62
  1. 4
      lib/REST.php
  2. 9
      lib/REST/Microsub/Auth.php
  3. 16
      tests/cases/REST/Microsub/TestAuth.php
  4. 3
      tests/phpunit.dist.xml

4
lib/REST.php

@ -40,12 +40,12 @@ class REST {
'match' => "/fever/",
'strip' => "/fever/",
'class' => REST\Fever\API::class,
],
],/*
'microsub' => [ // Microsub https://indieweb.org/Microsub
'match' => "/microsub",
'strip' => "",
'class' => REST\Microsub\API::class,
],
],*/
'microsub_auth' => [ // IndieAuth for Microsub https://indieauth.spec.indieweb.org/
'match' => "/u/",
'strip' => "/u/",

9
lib/REST/Microsub/Auth.php

@ -20,9 +20,9 @@ class Auth extends \JKingWeb\Arsse\REST\AbstractHandler {
const SCOPES = ["read", "follow", "channels"];
/** The list of the logical functions of this API, with their implementations */
const FUNCTIONS = [
'discovery' => ['GET' => "opDiscovery"],
'auth' => ['GET' => "opLogin", 'POST' => "opCodeVerification"],
'token' => ['GET' => "opTokenVerification", 'POST' => "opIssueAccessToken"],
'' => ['GET' => "opDiscovery"],
'auth' => ['GET' => "opLogin", 'POST' => "opCodeVerification"],
'token' => ['GET' => "opTokenVerification", 'POST' => "opIssueAccessToken"],
];
/** The minimal set of reserved URL characters which must be escaped when comparing user ID URLs */
const USERNAME_ESCAPES = [
@ -43,9 +43,8 @@ class Auth extends \JKingWeb\Arsse\REST\AbstractHandler {
}
// gather the query parameters and act on the "f" (function) parameter
$process = $req->getQueryParams()['f'] ?? "";
$process = strlen($process) ? $process : "discovery";
$method = $req->getMethod();
if (isset(self::FUNCTIONS[$process]) || ($process === "discovery" && !strlen($path)) || ($process !== "discovery" && strlen($path))) {
if (isset(self::FUNCTIONS[$process]) || ($process === "" && !strlen($path)) || ($process !== "" && strlen($path))) {
// the function requested needs to exist
// the path should also be empty unless we're doing discovery
return new EmptyResponse(404);

16
tests/cases/REST/Microsub/TestAuth.php

@ -0,0 +1,16 @@
<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\REST\Microsub;
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\Response\JsonResponse as Response;
use Zend\Diactoros\Response\EmptyResponse;
/** @covers \JKingWeb\Arsse\REST\Microsub\Auth<extended> */
class TestAuth extends \JKingWeb\Arsse\Test\AbstractTest {
}

3
tests/phpunit.dist.xml

@ -124,6 +124,9 @@
<file>cases/REST/Fever/TestAPI.php</file>
<file>cases/REST/Fever/PDO/TestAPI.php</file>
</testsuite>
<testsuite name="Microsub">
<file>cases/REST/Microsub/TestAuth.php</file>
</testsuite>
<testsuite name="Admin tools">
<file>cases/Service/TestService.php</file>
<file>cases/CLI/TestCLI.php</file>

Loading…
Cancel
Save