mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
WIP
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
<fields>
|
||||
<field id="contact_list" xsi:type="AttributeLinkedSetIndirect">
|
||||
<linked_class>lnkContactTestToServer</linked_class>
|
||||
<ext_key_to_me>testserver_id</ext_key_to_me>
|
||||
<ext_key_to_me>test_server_id</ext_key_to_me>
|
||||
<ext_key_to_remote>contact_test_id</ext_key_to_remote>
|
||||
<is_null_allowed>true</is_null_allowed>
|
||||
</field>
|
||||
@@ -50,7 +50,7 @@
|
||||
<field id="server_test_list" xsi:type="AttributeLinkedSetIndirect">
|
||||
<linked_class>lnkContactTestToServer</linked_class>
|
||||
<ext_key_to_me>contact_test_id</ext_key_to_me>
|
||||
<ext_key_to_remote>testserver_id</ext_key_to_remote>
|
||||
<ext_key_to_remote>test_server_id</ext_key_to_remote>
|
||||
<is_null_allowed>true</is_null_allowed>
|
||||
</field>
|
||||
</fields>
|
||||
@@ -72,7 +72,7 @@
|
||||
<extkey_attcode>contact_test_id</extkey_attcode>
|
||||
<target_attcode>password</target_attcode>
|
||||
</field>
|
||||
<field id="testserver_id" xsi:type="AttributeExternalKey" _delta="define">
|
||||
<field id="test_server_id" xsi:type="AttributeExternalKey" _delta="define">
|
||||
<target_class>TestServer</target_class>
|
||||
<on_target_delete>DEL_MANUAL</on_target_delete>
|
||||
<sql>test_server</sql>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
// Copyright (c) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
@@ -19,111 +20,142 @@
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use ArchivedObjectException;
|
||||
use Combodo\iTop\Test\UnitTest\ItopCustomDatamodelTestCase;
|
||||
use CoreException;
|
||||
use CoreUnexpectedValue;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use PasswordTest;
|
||||
use RestResultWithObjects;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class RestServicesSanitizeOutputTest extends iTopCustomDatamodelTestCase
|
||||
class RestServicesSanitizeOutputTest extends ItopCustomDatamodelTestCase
|
||||
{
|
||||
private const SIMPLE_PASSWORD = '123456';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws CoreException
|
||||
*/
|
||||
public function testSanitizeJsonOutputOnSimpleAttribute()
|
||||
{
|
||||
// inserer en base ?
|
||||
// insererer contact list ?
|
||||
// requeter des champs qui ne s'affichent pas
|
||||
$oContactTest = MetaModel::NewObject('ContactTest', array(
|
||||
'password' => '123456'));
|
||||
$oRestResultWithObject = new \RestResultWithObjects();
|
||||
$oRestResultWithObject->AddObject(0, "ok", $oContactTest, ['ContactTest' => ['password']]);
|
||||
$oContactTest = MetaModel::NewObject('ContactTest', [
|
||||
'password' => self::SIMPLE_PASSWORD]);
|
||||
$oRestResultWithObject = new RestResultWithObjects();
|
||||
$oRestResultWithObject->AddObject(0, 'ok', $oContactTest, ['ContactTest' => ['password']]);
|
||||
$oRestResultWithObject->SanitizeContent();
|
||||
$this->assertEquals(
|
||||
static::assertEquals(
|
||||
'{"objects":{"ContactTest::-1":{"code":0,"message":"ok","class":"ContactTest","key":-1,"fields":{"password":"*****"}}},"code":0,"message":null}',
|
||||
json_encode($oRestResultWithObject));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSanitizeJsonOutputAttributeExternalKeyOnNNRelation()
|
||||
{
|
||||
$oContactTest = $this->CreateObject('ContactTest', array(
|
||||
'password' => '123456'));
|
||||
$oContactTest = $this->createObject('ContactTest', [
|
||||
'password' => self::SIMPLE_PASSWORD]);
|
||||
|
||||
$oTestServer = $this->CreateObject('TestServer', [
|
||||
'name' => 'testserver',
|
||||
$oTestServer = $this->createObject('TestServer', [
|
||||
'name' => 'test_server',
|
||||
]);
|
||||
|
||||
|
||||
// create lnkContactTestToServer
|
||||
$oLnkContactTestToServer = $this->CreateObject('lnkContactTestToServer', array(
|
||||
$oLnkContactTestToServer = $this->createObject('lnkContactTestToServer', [
|
||||
'contact_test_id' => $oContactTest->GetKey(),
|
||||
'testserver_id' => $oTestServer->GetKey()
|
||||
));
|
||||
'test_server_id' => $oTestServer->GetKey()
|
||||
]);
|
||||
|
||||
$oRestResultWithObject = new \RestResultWithObjects();
|
||||
$oRestResultWithObject->AddObject(0, "ok", $oLnkContactTestToServer,
|
||||
$oRestResultWithObject = new RestResultWithObjects();
|
||||
$oRestResultWithObject->AddObject(0, 'ok', $oLnkContactTestToServer,
|
||||
['lnkContactTestToServer' => ['contact_test_password']]);
|
||||
|
||||
$oRestResultWithObject->SanitizeContent();
|
||||
$this->assertEquals(
|
||||
'{"objects":{"}',
|
||||
|
||||
static::assertContains(
|
||||
'*****',
|
||||
json_encode($oRestResultWithObject));
|
||||
static::assertNotContains(
|
||||
self::SIMPLE_PASSWORD,
|
||||
json_encode($oRestResultWithObject));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSanitizeJsonOutputAttributeOnNNRelation()
|
||||
{
|
||||
$oContactTest = $this->CreateObject('ContactTest', array(
|
||||
'password' => '123456'));
|
||||
$oContactTest = $this->createObject('ContactTest', [
|
||||
'password' => self::SIMPLE_PASSWORD]);
|
||||
|
||||
$oTestServer = $this->CreateObject('TestServer', [
|
||||
'name' => 'testserver',
|
||||
$oTestServer = $this->createObject('TestServer', [
|
||||
'name' => 'test_server',
|
||||
]);
|
||||
|
||||
|
||||
// create lnkContactTestToServer
|
||||
$this->CreateObject('lnkContactTestToServer', array(
|
||||
$this->createObject('lnkContactTestToServer', [
|
||||
'contact_test_id' => $oContactTest->GetKey(),
|
||||
'testserver_id' => $oTestServer->GetKey()
|
||||
));
|
||||
'test_server_id' => $oTestServer->GetKey()
|
||||
]);
|
||||
|
||||
$oRestResultWithObject = new \RestResultWithObjects();
|
||||
$oRestResultWithObject->AddObject(0, "ok", $oTestServer,
|
||||
$oRestResultWithObject = new RestResultWithObjects();
|
||||
$oRestResultWithObject->AddObject(0, 'ok', $oTestServer,
|
||||
['TestServer' => ['contact_list']]);
|
||||
|
||||
$oRestResultWithObject->SanitizeContent();
|
||||
$this->assertEquals(
|
||||
'{"objects":{"}',
|
||||
static::assertContains(
|
||||
'*****',
|
||||
json_encode($oRestResultWithObject));
|
||||
static::assertNotContains(
|
||||
self::SIMPLE_PASSWORD,
|
||||
json_encode($oRestResultWithObject));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws CoreException
|
||||
* @throws CoreUnexpectedValue
|
||||
* @throws ArchivedObjectException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testSanitizeJsonOutputOn1NRelation()
|
||||
{
|
||||
// Impossible to query the class
|
||||
$oTestServer = $this->CreateObject('TestServer', [
|
||||
$oTestServer = $this->createObject('TestServer', [
|
||||
'name' => 'my_server',
|
||||
]);
|
||||
|
||||
$oPassword = new PasswordTest();
|
||||
$oPassword->Set('password', "123456");
|
||||
$oPassword->Set('password', self::SIMPLE_PASSWORD);
|
||||
$oPassword->Set('server_test_id', $oTestServer->GetKey());
|
||||
|
||||
$oContactList = $oTestServer->Get('contact_list');
|
||||
$oContactList->AddItem($oPassword);
|
||||
$oTestServer->Set('contact_list', $oContactList);
|
||||
|
||||
$oRestResultWithObject = new \RestResultWithObjects();
|
||||
$oRestResultWithObject->AddObject(0, "ok", $oTestServer, ['TestServer' => ['id', 'password_list']]);
|
||||
$oRestResultWithObject = new RestResultWithObjects();
|
||||
$oRestResultWithObject->AddObject(0, 'ok', $oTestServer, ['TestServer' => ['id', 'password_list']]);
|
||||
$oRestResultWithObject->SanitizeContent();
|
||||
$this->assertEquals(
|
||||
static::assertEquals(
|
||||
'{"objects":{"TestServer::-1":{"code":0,"message":"ok","class":"TestServer","key":-1,"fields":{"password_list":["*****"]}}},"code":0,"message":null}',
|
||||
json_encode($oRestResultWithObject));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Abs path to the XML delta to use for the tests of that class
|
||||
*/
|
||||
public function GetDatamodelDeltaAbsPath(): string
|
||||
{
|
||||
return __DIR__ . "/Delta/delta_test_sanitize_output.xml";
|
||||
return __DIR__ . '/Delta/delta_test_sanitize_output.xml';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user