Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Add Transifex translations link to README

### Fixed

- Fix `Clear` checkbox not erasing the stored SCCM database password and inventory credentials

## [2.7.0] - 2026-10-06

### Added
Expand Down
19 changes: 9 additions & 10 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,15 @@ public function prepareInputForAdd($input): array

public function prepareInputForUpdate($input): array
{
if (isset($input["sccmdb_password"]) && !empty($input["sccmdb_password"])) {
$input["sccmdb_password"] = (new GLPIKey())->encrypt($input["sccmdb_password"]);
} else {
unset($input["sccmdb_password"]);
}

if (isset($input["auth_info"]) && !empty($input["auth_info"])) {
$input["auth_info"] = (new GLPIKey())->encrypt($input["auth_info"]);
} else {
unset($input["auth_info"]);
foreach (['sccmdb_password', 'auth_info'] as $field) {
// "Clear" checkbox rendered by GLPI password fields
if (!empty($input['_blank_' . $field])) {
$input[$field] = '';
} elseif (!empty($input[$field])) {
$input[$field] = (new GLPIKey())->encrypt($input[$field]);
} else {
unset($input[$field]);
}
}

if (array_key_exists('inventory_server_url', $input) && !empty($input['inventory_server_url'])) {
Expand Down
79 changes: 79 additions & 0 deletions tests/PluginSccmConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/**
* -------------------------------------------------------------------------
* SCCM plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of SCCM.
*
* SCCM is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* SCCM 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SCCM. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @author François Legastelois
* @copyright Copyright (C) 2014-2023 by SCCM plugin team.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/pluginsGLPI/sccm
* -------------------------------------------------------------------------
*/

use Glpi\Tests\DbTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class PluginSccmConfigTest extends DbTestCase
{
public static function secretFieldProvider(): iterable
{
yield 'database password' => ['sccmdb_password'];
yield 'inventory credentials' => ['auth_info'];
}

#[DataProvider('secretFieldProvider')]
public function testSecretIsEncrypted(string $field): void
{
$config = $this->createItem(PluginSccmConfig::class, ['name' => 'test', $field => 'secret'], [$field]);

$this->assertNotSame('secret', $config->fields[$field]);
$this->assertSame('secret', (new GLPIKey())->decrypt($config->fields[$field]));
}

#[DataProvider('secretFieldProvider')]
public function testEmptySecretKeepsStoredValue(string $field): void
{
$config = $this->createItem(PluginSccmConfig::class, ['name' => 'test', $field => 'secret'], [$field]);

$this->updateItem(PluginSccmConfig::class, $config->getID(), [$field => ''], [$field]);

$this->assertTrue($config->getFromDB($config->getID()));
$this->assertSame('secret', (new GLPIKey())->decrypt($config->fields[$field]));
}

#[DataProvider('secretFieldProvider')]
public function testClearCheckboxErasesSecret(string $field): void
{
$config = $this->createItem(PluginSccmConfig::class, ['name' => 'test', $field => 'secret'], [$field]);

// The form still posts the displayed value along with the checkbox
$this->updateItem(
PluginSccmConfig::class,
$config->getID(),
[$field => 'secret', '_blank_' . $field => '1'],
[$field, '_blank_' . $field],
);

$this->assertTrue($config->getFromDB($config->getID()));
$this->assertEmpty($config->fields[$field]);
}
}
Loading