Skip to content

Commit 51c405e

Browse files
authored
Merge pull request #217 from pdsinterop/ci/run-phpunit-in-docker
Fix broken unit-test
2 parents 4fc7618 + c070c76 commit 51c405e

File tree

3 files changed

+159
-92
lines changed

3 files changed

+159
-92
lines changed

.github/workflows/php.yml

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ on:
1010
- '.config/phpcs.xml.dist'
1111
- '.config/phpunit.xml.dist'
1212
- '.github/workflows/php.yml'
13-
- 'composer.json'
14-
- 'composer.lock'
13+
- 'solid/composer.json'
14+
- 'solid/composer.lock'
1515
branches: [ main ]
1616
types: [ opened, reopened, synchronize ]
1717
# This event occurs when there is a push to the repository.
@@ -21,8 +21,8 @@ on:
2121
- '.config/phpcs.xml.dist'
2222
- '.config/phpunit.xml.dist'
2323
- '.github/workflows/php.yml'
24-
- 'composer.json'
25-
- 'composer.lock'
24+
- 'solid/composer.json'
25+
- 'solid/composer.lock'
2626
# Allow manually triggering the workflow.
2727
workflow_dispatch:
2828

@@ -57,14 +57,27 @@ jobs:
5757
steps:
5858
- uses: actions/checkout@v4
5959
- run: >-
60-
composer validate
61-
--check-lock
62-
--no-plugins
63-
--no-scripts
64-
--strict
60+
composer validate
61+
--check-lock
62+
--no-plugins
63+
--no-scripts
64+
--strict
6565
working-directory: "solid"
6666
# 02.test.php.test-unit.yml
6767
php-unittest:
68+
container:
69+
image: ghcr.io/${{ github.repository }}:main-${{ matrix.nextcloud_version }}
70+
env:
71+
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
72+
NEXTCLOUD_PATH: /usr/src/nextcloud/apps
73+
NEXTCLOUD_UPDATE: 1
74+
XDEBUG_MODE: coverage
75+
volumes:
76+
- /usr/bin/composer:/usr/bin/composer
77+
defaults:
78+
run:
79+
shell: bash
80+
working-directory: /usr/src/nextcloud/apps/solid/
6881
name: PHP Unit Tests
6982
needs:
7083
- lint-php-syntax
@@ -78,27 +91,24 @@ jobs:
7891
- 29
7992
- 30
8093
steps:
81-
- uses: actions/checkout@v4
82-
- uses: shivammathur/setup-php@v2
83-
with:
84-
ini-values: error_reporting=E_ALL, display_errors=On
85-
php-version: 8.3
94+
- uses: actions/checkout@v5
95+
# @CHECKME: cp site.conf /etc/apache2/sites-enabled/000-default.conf (?)
96+
- name: Setup Test Environment
97+
run: |
98+
git config --global --add safe.directory "${NEXTCLOUD_PATH}"
99+
/entrypoint.sh "echo"
100+
bash "${GITHUB_WORKSPACE}/init.sh"
101+
rm -r "${NEXTCLOUD_PATH}/solid/"
102+
cp --archive --verbose "${GITHUB_WORKSPACE}/." "${NEXTCLOUD_PATH}"
103+
working-directory: /usr/src/nextcloud/
86104
- name: Install and Cache Composer dependencies
87-
uses: "ramsey/composer-install@v2"
105+
uses: ramsey/composer-install@v3
88106
with:
89-
working-directory: "solid"
107+
working-directory: /usr/src/nextcloud/apps/solid
90108
env:
91109
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
92-
- run: |
93-
docker run \
94-
--env 'XDEBUG_MODE=coverage' \
95-
--rm \
96-
--volume="./solid:/var/www/html/apps/solid" \
97-
ghcr.io/${{ github.repository }}:main-${{ matrix.nextcloud_version }} \
98-
bash -c 'NEXTCLOUD_UPDATE=1 /entrypoint.sh "echo" \
99-
&& sudo -u www-data bash /init.sh \
100-
&& cd /var/www/html/apps/solid \
101-
&& bin/phpunit --configuration phpunit.xml'
110+
- name: Run PHPUnit
111+
run: bin/phpunit --configuration phpunit.xml
102112

103113
# 03.quality.php.scan.dependencies-vulnerabilities.yml
104114
scan-dependencies-vulnerabilities:
@@ -109,12 +119,12 @@ jobs:
109119
steps:
110120
- uses: actions/checkout@v4
111121
- run: >-
112-
composer audit
113-
--abandoned=report
114-
--locked
115-
--no-dev
116-
--no-plugins
117-
--no-scripts
122+
composer audit
123+
--abandoned=report
124+
--locked
125+
--no-dev
126+
--no-plugins
127+
--no-scripts
118128
working-directory: "solid"
119129
# 03.quality.php.lint-quality.yml
120130
php-lint-quality:

solid/lib/Controller/ServerController.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ public function authorize() {
156156
// return $result->addHeader('Access-Control-Allow-Origin', '*');
157157
}
158158

159+
if (! isset($_GET['client_id'])) {
160+
return new JSONResponse('Bad request, missing client_id', 400);
161+
}
162+
159163
if (isset($_GET['request'])) {
160164
$jwtConfig = Configuration::forSymmetricSigner(new Sha256(), InMemory::plainText($this->config->getPrivateKey()));
161165
try {
@@ -323,7 +327,9 @@ public function session() {
323327
*/
324328
public function token() {
325329
$request = \Laminas\Diactoros\ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
326-
$grantType = $request->getParsedBody()['grant_type'];
330+
331+
$grantType = $request->getParsedBody()['grant_type'] ?? null;
332+
327333
switch ($grantType) {
328334
case "authorization_code":
329335
$code = $request->getParsedBody()['code'];
@@ -342,9 +348,9 @@ public function token() {
342348
break;
343349
}
344350

345-
$clientId = $request->getParsedBody()['client_id'];
351+
$clientId = $request->getParsedBody()['client_id'] ?? null;
346352

347-
$httpDpop = $request->getServerParams()['HTTP_DPOP'];
353+
$httpDpop = $request->getServerParams()['HTTP_DPOP'] ?? null;
348354

349355
$response = new \Laminas\Diactoros\Response();
350356
$server = new \Pdsinterop\Solid\Auth\Server($this->authServerFactory, $this->authServerConfig, $response);
@@ -361,7 +367,7 @@ public function token() {
361367
);
362368
}
363369

364-
return $this->respond($response); // ->addHeader('Access-Control-Allow-Origin', '*');
370+
return $this->respond($response);
365371
}
366372

367373
/**
@@ -389,8 +395,13 @@ public function logout() {
389395
* @NoCSRFRequired
390396
*/
391397
public function register() {
392-
$clientData = file_get_contents('php://input');
393-
$clientData = json_decode($clientData, true);
398+
$postData = file_get_contents('php://input');
399+
$clientData = json_decode($postData, true);
400+
401+
if (! isset($clientData)) {
402+
return new JSONResponse("Missing client data", Http::STATUS_BAD_REQUEST);
403+
}
404+
394405
if (! isset($clientData['redirect_uris'])) {
395406
return new JSONResponse("Missing redirect URIs", Http::STATUS_BAD_REQUEST);
396407
}

0 commit comments

Comments
 (0)