Skip to content

Commit a2384d8

Browse files
committed
Merge remote-tracking branch 'origin/master' into add-solid-crud-tests
2 parents d982d3f + 860581a commit a2384d8

File tree

10 files changed

+121
-29
lines changed

10 files changed

+121
-29
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ ADD . /app
1919
WORKDIR /app
2020
RUN php /install/composer.phar install --no-dev --prefer-dist
2121
COPY site.conf /etc/apache2/sites-enabled/site.conf
22+
RUN chown www-data /app/config
2223
EXPOSE 443

bin/serve-docker-dev.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@
44

55
docker run \
66
-i \
7-
--env 'ENVIRONMENT=development' \
8-
--expose 80 \
9-
--name php-solid-server \
7+
--expose 443 \
8+
--name server \
109
--network host \
1110
--rm \
1211
--volume "${PWD}:/app" \
13-
"php:${PHP_VERSION:-7.1}-alpine" \
14-
php \
15-
--define 'log_errors=On' \
16-
--docroot /app/web/ \
17-
--server '0.0.0.0:80' \
18-
/app/web/index.php
12+
"${DOCKER_IMAGE:=php-solid-server}"

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,10 @@
4545
"serve-dev-docker":"bash ./bin/serve-docker-dev.sh",
4646
"test":"phpunit"
4747
},
48+
"scripts-descriptions": {
49+
"serve-dev": "Run the application with the internal PHP development server",
50+
"serve-dev-docker": "Run the application with the docker image provided by the TestSuite repo.",
51+
"test": "Run unit-test with PHPUnit"
52+
},
4853
"type": "project"
4954
}

run-solid-test-suite.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ docker network create testnet
66

77
# Build and start Nextcloud server with code from current repo contents:
88
docker build -t server .
9-
docker run -d --name server --network=testnet server
109

1110
docker build -t webid-provider https://github.com/pdsinterop/test-suites.git#master:/testers/webid-provider
1211
docker build -t solid-crud https://github.com/pdsinterop/test-suites.git#master:/testers/solid-crud
1312
docker build -t cookie https://github.com/pdsinterop/test-suites.git#master:servers/php-solid-server/cookie
1413
wget -O /tmp/env-vars-for-test-image.list https://raw.githubusercontent.com/pdsinterop/test-suites/master/servers/php-solid-server/env.list
14+
15+
docker run -d --name server --network=testnet --env-file /tmp/env-vars-for-test-image.list server
16+
1517
until docker run --rm --network=testnet webid-provider curl -kI https://server 2> /dev/null > /dev/null
1618
do
1719
echo Waiting for server to start, this can take up to a minute ...

src/Controller/AuthorizeController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ final public function __invoke(ServerRequestInterface $request, array $args): Re
1414
$response = $response->withStatus(302, "Approval required");
1515

1616
// FIXME: Generate a proper url for this;
17-
$loginUrl = "https://localhost/login/?returnUrl=" . urlencode($_SERVER['REQUEST_URI']);
17+
$baseUrl = $this->baseUrl;
18+
$loginUrl = $baseUrl . "/login/?returnUrl=" . urlencode($_SERVER['REQUEST_URI']);
1819
$response = $response->withHeader("Location", $loginUrl);
1920
return $response;
2021
}
@@ -50,7 +51,8 @@ final public function __invoke(ServerRequestInterface $request, array $args): Re
5051
$response = $response->withStatus(302, "Approval required");
5152

5253
// FIXME: Generate a proper url for this;
53-
$approvalUrl = "https://localhost/sharing/$clientId/?returnUrl=" . urlencode($_SERVER['REQUEST_URI']);
54+
$baseUrl = $this->baseUrl;
55+
$approvalUrl = $baseUrl . "/sharing/$clientId/?returnUrl=" . urlencode($_SERVER['REQUEST_URI']);
5456
$response = $response->withHeader("Location", $approvalUrl);
5557
return $response;
5658
}

src/Controller/LoginController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ final public function __invoke(ServerRequestInterface $request, array $args): Re
2222
}
2323
$response->getBody()->write("<h1>Already logged in as $user</h1>");
2424
} else if (
25-
($postBody['username'] == $_ENV['USER'] && $postBody['password'] == $_ENV['PASSWORD']) ||
26-
($postBody['username'] == $_SERVER['USER'] && $postBody['password'] == $_SERVER['PASSWORD'])
25+
($postBody['username'] == $_ENV['USERNAME'] && $postBody['password'] == $_ENV['PASSWORD']) ||
26+
($postBody['username'] == $_SERVER['USERNAME'] && $postBody['password'] == $_SERVER['PASSWORD'])
2727
) {
2828
$user = $postBody['username'];
2929
$_SESSION['userid'] = $user;

src/Controller/RegisterController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ final public function __invoke(ServerRequestInterface $request, array $args): Re
2020
$origin = $parsedOrigin['host'];
2121

2222
$clientId = $this->config->saveClientRegistration($origin, $clientData);
23-
23+
24+
// FIXME: properly generate this url;
25+
$baseUrl = $this->baseUrl;
26+
$clientUrl = $baseUrl . "/clients/$clientId";
27+
2428
$registration = array(
2529
'client_id' => $clientId,
26-
'registration_client_uri' => "https://localhost/clients/$clientId", // FIXME: properly generate this url;
30+
'registration_client_uri' => $clientUrl,
2731
'client_id_issued_at' => $clientData['client_id_issued_at'],
2832
'redirect_uris' => $clientData['redirect_uris'],
2933
);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Pdsinterop\Solid\Controller;
4+
5+
use Pdsinterop\Solid\Resources\Server;
6+
use Psr\Http\Message\ResponseInterface as Response;
7+
use Psr\Http\Message\ServerRequestInterface as Request;
8+
9+
class ResourceController extends AbstractController
10+
{
11+
////////////////////////////// CLASS PROPERTIES \\\\\\\\\\\\\\\\\\\\\\\\\\\\
12+
13+
/** @var Server */
14+
private $server;
15+
16+
//////////////////////////////// PUBLIC API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
17+
18+
final public function __construct(Server $server)
19+
{
20+
$this->server = $server;
21+
}
22+
23+
final public function __invoke(Request $request, array $args) : Response
24+
{
25+
return $this->server->respondToRequest($request);
26+
}
27+
}

src/Controller/ServerController.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,21 @@ public function __construct() {
2020
$this->authServerConfig = $this->createAuthServerConfig();
2121
$this->authServerFactory = (new \Pdsinterop\Solid\Auth\Factory\AuthorizationServerFactory($this->authServerConfig))->create();
2222
$this->tokenGenerator = (new \Pdsinterop\Solid\Auth\TokenGenerator($this->authServerConfig));
23-
24-
// $this->baseUrl = "https://localhost";
23+
$this->baseUrl = isset($_ENV['SERVER_ROOT']) ? $_ENV['SERVER_ROOT'] : "https://localhost";
2524
}
2625

2726
public function getOpenIdEndpoints() {
2827
// FIXME: would be better to base this on the available routes if possible.
29-
$this->baseUrl = "https://localhost/"; // FIXME: generate proper urls
28+
$this->baseUrl = isset($_ENV['SERVER_ROOT']) ? $_ENV['SERVER_ROOT'] : "https://localhost";
3029
return [
3130
'issuer' => $this->baseUrl,
32-
'authorization_endpoint' => $this->baseUrl . "authorize",
33-
'jwks_uri' => $this->baseUrl . "jwks",
34-
"check_session_iframe" => $this->baseUrl . "session",
35-
"end_session_endpoint" => $this->baseUrl . "logout",
36-
"token_endpoint" => $this->baseUrl . "token",
37-
"userinfo_endpoint" => $this->baseUrl . "userinfo",
38-
"registration_endpoint" => $this->baseUrl . "register"
31+
'authorization_endpoint' => $this->baseUrl . "/authorize",
32+
'jwks_uri' => $this->baseUrl . "/jwks",
33+
"check_session_iframe" => $this->baseUrl . "/session",
34+
"end_session_endpoint" => $this->baseUrl . "/logout",
35+
"token_endpoint" => $this->baseUrl . "/token",
36+
"userinfo_endpoint" => $this->baseUrl . "/userinfo",
37+
"registration_endpoint" => $this->baseUrl . "/register",
3938
];
4039
}
4140

@@ -114,7 +113,7 @@ public function checkApproval($clientId) {
114113
}
115114

116115
public function getProfilePage() {
117-
return $this->baseUrl . "profile/card#me"; // FIXME: would be better to base this on the available routes if possible.
116+
return $this->baseUrl . "/profile/card#me"; // FIXME: would be better to base this on the available routes if possible.
118117
}
119118

120119
public function getResponseType() {

web/index.php

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use League\Route\Router;
1818
use League\Route\Strategy\ApplicationStrategy;
1919
use Pdsinterop\Solid\Controller\AddSlashToPathController;
20-
use Pdsinterop\Solid\Controller\AuthorizeController;
2120
use Pdsinterop\Solid\Controller\ApprovalController;
21+
use Pdsinterop\Solid\Controller\AuthorizeController;
2222
use Pdsinterop\Solid\Controller\CorsController;
2323
use Pdsinterop\Solid\Controller\HandleApprovalController;
2424
use Pdsinterop\Solid\Controller\HelloWorldController;
@@ -30,9 +30,10 @@
3030
use Pdsinterop\Solid\Controller\Profile\CardController;
3131
use Pdsinterop\Solid\Controller\Profile\ProfileController;
3232
use Pdsinterop\Solid\Controller\RegisterController;
33+
use Pdsinterop\Solid\Controller\ResourceController;
3334
use Pdsinterop\Solid\Controller\StorageController;
3435
use Pdsinterop\Solid\Controller\TokenController;
35-
use Pdsinterop\Solid\Resources\Server;
36+
use Pdsinterop\Solid\Resources\Server as ResourceServer;
3637

3738
use Psr\Http\Message\ResponseInterface;
3839
use Psr\Http\Message\ServerRequestInterface;
@@ -81,6 +82,16 @@
8182
return $template;
8283
});
8384

85+
$container->add(ResourceController::class, function () use ($container) {
86+
$filesystem = $container-> get(FilesystemInterface::class);
87+
88+
require_once __DIR__ . '/../lib/solid-crud/src/Server.php';
89+
90+
$server = new ResourceServer($filesystem, new Response());
91+
92+
return new ResourceController($server);
93+
});
94+
8495
$controllers = [
8596
AddSlashToPathController::class,
8697
ApprovalController::class,
@@ -191,6 +202,53 @@
191202

192203
$response = new HtmlResponse($html, 500, []);
193204
}
205+
/*
206+
$router->group('/data', static function (\League\Route\RouteGroup $group) {
207+
$methods = [
208+
'DELETE',
209+
'GET',
210+
'HEAD',
211+
// 'OPTIONS', // @TODO: This breaks because of the CorsController being added to `OPTION /*` in the index.php
212+
'PATCH',
213+
'POST',
214+
'PUT',
215+
];
216+
217+
array_walk($methods, static function ($method) use (&$group) {
218+
$group->map($method, '/', AddSlashToPathController::class);
219+
$group->map($method, '{path:.*}', ResourceController::class);
220+
});
221+
})->setScheme($scheme);
222+
223+
try {
224+
$response = $router->dispatch($request);
225+
} catch (HttpException $exception) {
226+
$status = $exception->getStatusCode();
227+
228+
$message = 'Yeah, that\'s an error.';
229+
if ($exception instanceof NotFoundException) {
230+
$message = 'No such page.';
231+
}
232+
233+
$html = "<h1>{$message}</h1><p>{$exception->getMessage()} ({$status})</p>";
234+
235+
if (getenv('ENVIRONMENT') === 'development') {
236+
$html .= "<pre>{$exception->getTraceAsString()}</pre>";
237+
}
238+
239+
$response = new HtmlResponse($html, $status, $exception->getHeaders());
240+
} catch (\Exception $exception) {
241+
$html = "<h1>Oh-no! The developers messed up!</h1><p>{$exception->getMessage()}</p>";
242+
243+
if (getenv('ENVIRONMENT') === 'development') {
244+
$html .=
245+
"<p>{$exception->getFile()}:{$exception->getLine()}</p>" .
246+
"<pre>{$exception->getTraceAsString()}</pre>"
247+
;
248+
}
249+
250+
$response = new HtmlResponse($html, 500, []);
251+
*/
194252
}
195253

196254
// send the response to the browser

0 commit comments

Comments
 (0)