1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Test skeleton for IndieAuth

This commit is contained in:
J. King 2019-09-25 08:23:42 -04:00
parent cbd382d768
commit 7958cc6f62
4 changed files with 25 additions and 7 deletions

View file

@ -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/",

View file

@ -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);

View file

@ -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 {
}

View file

@ -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>