Skip to content

Commit 9f1117d

Browse files
orthaghtrasher
authored andcommitted
fix missing removal of undisclosedFields
1 parent ebca9b1 commit 9f1117d

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed

inc/apiclient.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class APIClient extends CommonDBTM {
4545
// From CommonDBTM
4646
public $dohistory = true;
4747

48+
static $undisclosedFields = [
49+
'app_token'
50+
];
51+
4852
static function canCreate() {
4953
return Session::haveRight(static::$rightname, UPDATE);
5054
}

inc/authldap.class.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class AuthLDAP extends CommonDBTM {
9494
//connection caching stuff
9595
static $conn_cache = [];
9696

97+
static $undisclosedFields = [
98+
'rootdn_passwd',
99+
];
100+
97101
static function getTypeName($nb = 0) {
98102
return _n('LDAP directory', 'LDAP directories', $nb);
99103
}
@@ -134,9 +138,6 @@ function post_getEmpty() {
134138
$this->fields['responsible_field'] = '';
135139
}
136140

137-
static public function unsetUndisclosedFields(&$fields) {
138-
unset($fields['rootdn_passwd']);
139-
}
140141

141142
/**
142143
* Preconfig datas for standard system

inc/commondbtm.class.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ class CommonDBTM extends CommonGLPI {
167167
*/
168168
protected static $foreign_key_fields_of = [];
169169

170+
171+
/**
172+
* Fields to remove when querying data with api
173+
* @var array
174+
*/
175+
static $undisclosedFields = [];
176+
170177
/**
171178
* Constructor
172179
**/
@@ -456,6 +463,9 @@ function post_getFromDB() {
456463
* @return void
457464
*/
458465
static public function unsetUndisclosedFields(&$fields) {
466+
foreach (static::$undisclosedFields as $key) {
467+
unset($fields[$key]);
468+
}
459469
}
460470

461471

inc/mailcollector.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class MailCollector extends CommonDBTM {
9494
const REQUESTER_FIELD_FROM = 0;
9595
const REQUESTER_FIELD_REPLY_TO = 1;
9696

97+
static $undisclosedFields = [
98+
'passwd',
99+
];
100+
97101
static function getTypeName($nb = 0) {
98102
return _n('Receiver', 'Receivers', $nb);
99103
}
@@ -2004,10 +2008,6 @@ function cleanDBonPurge() {
20042008
Rule::cleanForItemCriteria($this, '_mailgate');
20052009
}
20062010

2007-
static public function unsetUndisclosedFields(&$fields) {
2008-
unset($fields['passwd']);
2009-
}
2010-
20112011
/**
20122012
* Get the requester field
20132013
*

inc/user.class.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ class User extends CommonDBTM {
5555

5656
static $rightname = 'user';
5757

58+
static $undisclosedFields = [
59+
'password',
60+
'personal_token',
61+
'api_token',
62+
'cookie_token',
63+
];
64+
5865
private $entities = null;
5966

6067

@@ -273,9 +280,6 @@ function post_getEmpty() {
273280
}
274281
}
275282

276-
static public function unsetUndisclosedFields(&$fields) {
277-
unset($fields['password']);
278-
}
279283

280284
function pre_deleteItem() {
281285
global $DB;

tests/APIBaseClass.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,32 @@ public function testGetGlpiConfig() {
13071307
->hasKey('cfg_glpi');
13081308
$this->array($data['cfg_glpi'])
13091309
->hasKey('infocom_types');
1310+
}
1311+
1312+
1313+
public function testUndisclosedField() {
1314+
// test common cases
1315+
$itemtypes = [
1316+
'APIClient', 'AuthLDAP', 'MailCollector', 'User'
1317+
];
1318+
foreach ($itemtypes as $itemtype) {
1319+
$data = $this->query($itemtype, [
1320+
'headers' => ['Session-Token' => $this->session_token]
1321+
]);
1322+
1323+
$this->array($itemtype::$undisclosedFields)
1324+
->size->isGreaterThan(0);
1325+
1326+
foreach ($itemtype::$undisclosedFields as $key) {
1327+
$this->array($data)->notHasKey($key);
1328+
}
1329+
}
1330+
1331+
// test specific cases
1332+
// Config
1333+
$data = $this->query('getGlpiConfig', [
1334+
'headers' => ['Session-Token' => $this->session_token]
1335+
]);
13101336

13111337
// Test undisclosed data are actually not disclosed
13121338
$this->array(Config::$undisclosedFields)

0 commit comments

Comments
 (0)