Skip to content

Commit

Permalink
UHF-10012: Use different permission for debug route
Browse files Browse the repository at this point in the history
  • Loading branch information
tuutti committed Apr 24, 2024
1 parent 26d6361 commit 4a8ee5e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 119 deletions.
2 changes: 1 addition & 1 deletion helfi_api_base.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ helfi_api_base.debug_list:
_title: 'Debug'
_controller: '\Drupal\helfi_api_base\Controller\DebugController::build'
requirements:
_permission: 'restful get helfi_debug_data'
_permission: 'restful get helfi_debug_package_version'
32 changes: 1 addition & 31 deletions tests/src/Functional/DebugUiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Drupal\Tests\helfi_api_base\Functional;

use Drupal\user\Entity\Role;

/**
* Tests debug data rest resource.
*
Expand All @@ -27,42 +25,14 @@ class DebugUiTest extends MigrationTestBase {
*/
protected $defaultTheme = 'stark';

/**
* Tests /debug endpoint.
*/
public function testDebugEndpoint() : void {
$this->drupalGet('/api/v1/debug');
$this->assertSession()->statusCodeEquals(403);

// Allow all users to fetch resources.
Role::load('anonymous')
->grantPermission('restful get helfi_debug_data')
->save();

$this->drupalGet('/api/v1/debug');
$this->assertSession()->statusCodeEquals(200);
$content = json_decode($this->getSession()->getPage()->getContent(), TRUE);

$this->assertNotEmpty($content['composer']);
// Make sure we have no imported items by default.
$this->assertEquals(0, $content['migrate']['data'][0]['imported']);
// Run migration to verify that caches are cleared properly.
$this->executeMigration('dummy_migrate');

$this->drupalGet('/api/v1/debug');
$this->assertSession()->statusCodeEquals(200);
$content = json_decode($this->getSession()->getPage()->getContent(), TRUE);
$this->assertEquals(4, $content['migrate']['data'][0]['imported']);
}

/**
* Tests the admin UI route.
*/
public function testDebugAdminUi() : void {
$this->drupalGet('/admin/debug');
$this->assertSession()->statusCodeEquals(403);

$account = $this->createUser(['restful get helfi_debug_data']);
$account = $this->createUser(['restful get helfi_debug_package_version']);
$this->drupalLogin($account);

$this->drupalGet('/admin/debug');
Expand Down
86 changes: 0 additions & 86 deletions tests/src/Functional/InstallTest.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/src/Kernel/Controller/DebugControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testControllerPermission() : void {

$this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode());

$this->drupalSetUpCurrentUser(permissions: ['restful get helfi_debug_data']);
$this->drupalSetUpCurrentUser(permissions: ['restful get helfi_debug_package_version']);
$request = $this->getMockedRequest('/admin/debug');
$response = $this->processRequest($request);

Expand Down

0 comments on commit 4a8ee5e

Please sign in to comment.