Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide api key in xhr-responses if key is configured in config.php #454

Merged
merged 2 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/Controller/LocalAppsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ public function index($state = 'enabled') {
$app['missingDependencies'] = $missing;
$app['installed'] = true;
$app['updateInfo'] = [];
// if ($app['installed']) {
// $app['installInfo'] = $this->marketService->getInstalledAppInfo($app['id']);
// $app['updateInfo'] = $this->marketService->getAvailableUpdateVersion($app['id']);
// }

return $app;
}, $apps));
}
Expand Down
11 changes: 8 additions & 3 deletions lib/Controller/MarketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,15 @@ public function changeApiKey($apiKey) {
* @return array|mixed
*/
public function getApiKey() {
return new DataResponse([
'apiKey' => $this->marketService->getApiKey(),
$responseBody = [
'changeable' => $this->marketService->isApiKeyChangeableByUser(),
], Http::STATUS_OK);
];

if ($this->marketService->isApiKeyChangeableByUser()) {
$responseBody['apiKey'] = $this->marketService->getApiKey();
}

return new DataResponse($responseBody, Http::STATUS_OK);
}

/**
Expand Down
75 changes: 75 additions & 0 deletions tests/unit/MarketControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* @author Ilja Neumann <[email protected]>
*
* @copyright Copyright (c) 2019, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Market\Tests\Unit;

use OCA\Market\Controller\MarketController;
use OCA\Market\MarketService;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use Test\TestCase;

class MarketControllerTest extends TestCase {

/** @var MarketController */
private $controller;
/** @var IRequest */
private $request;
/** @var MarketService|\PHPUnit_Framework_MockObject_MockObject */
private $marketService;

public function setUp() {
parent::setUp();
$this->request = $this->createMock(IRequest::class);
$this->marketService = $this->createMock(MarketService::class);

$this->controller = new MarketController(
'market',
$this->request,
$this->marketService,
$this->createMock(IL10N::class),
$this->createMock(IURLGenerator::class),
$this->createMock(IConfig::class)
);
}

public function testApiKeyIsNotReturnedIfNotChangeableByUser() {
$this->marketService
->method('isApiKeyChangeableByUser')
->willReturn(false);

/** @var array */
$response = $this->controller->getApiKey()->getData();
$this->assertArrayNotHasKey('apiKey', $response);
}

public function testApiKeyIsReturnedIfChangeableByUser() {
$this->marketService
->method('isApiKeyChangeableByUser')
->willReturn(true);

/** @var array */
$response = $this->controller->getApiKey()->getData();
$this->assertArrayHasKey('apiKey', $response);
}
}