Skip to content

Commit

Permalink
Add test and check file info sucessful response.
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronGilMartinez committed Dec 11, 2024
1 parent 93bad6c commit 8239ce5
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
langcode: en
status: true
dependencies:
module:
- jwt
id: cool
label: Collabora
description: ''
key_type: jwt_hs
key_type_settings:
algorithm: HS256
key_provider: config
key_provider_settings:
key_value: wwHYDJCstKi7pBfwtiV4y5iEDtnGaS+ALk2OR7DO5EZxSYkcnak5b0v1ZvdlpFXKP+RGijZvh7r+geV4SHJ4kw==
key_input: text_field
key_input_settings: { }
2 changes: 2 additions & 0 deletions tests/src/Kernel/CollaboraKernelTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ protected function setUp(): void {
$this->installEntitySchema('file');
$this->installSchema('file', 'file_usage');
$this->installEntitySchema('media');
$this->installEntitySchema('key');
$this->installConfig([
'field',
'system',
'user',
'image',
'file',
'media',
'collabora_online'
]);

// Install user module to avoid user 1 permissions bypass.
Expand Down
80 changes: 80 additions & 0 deletions tests/src/Kernel/WopiControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/*
* Copyright the Collabora Online contributors.
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

declare(strict_types=1);

namespace Drupal\Tests\collabora_online\Kernel;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
* Tests the WopiController.
*/
class WopiControllerTest extends CollaboraKernelTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = [
'collabora_online_test',
'jwt',
];

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

$this->installConfig([
'jwt',
]);
}

/**
* Tests collabora-online.wopi.info
*/
public function testWopiInfoController(): void {
$media = $this->createMediaEntity('document');
/** @var \Drupal\collabora_online\Jwt\JwtTranscoderInterface $transcoder */
$transcoder = \Drupal::service('Drupal\collabora_online\Jwt\JwtTranscoderInterface');

$expire_timestamp = gettimeofday(TRUE) + 1000;

$access_token = $transcoder->encode([
'fid' => '1',
'uid' => '2',
'wri' => FALSE,
'exp' => $expire_timestamp,
], $expire_timestamp);

$request = Request::create(
'/cool/wopi/files/1',
'GET',
[
'id' => '1',
'action' => 'info',
'access_token' => $access_token,
]
);

$this->setCurrentUser($this->createUser(['access content']));

/** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */
$kernel = \Drupal::getContainer()->get('http_kernel');
$response = $kernel->handle($request);

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

}

0 comments on commit 8239ce5

Please sign in to comment.