Fixed encryption in nested fields
This commit is contained in:
parent
f657563711
commit
63e442293c
|
@ -172,6 +172,14 @@ $collections = [
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'array' => true,
|
'array' => true,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'$collection' => Database::SYSTEM_COLLECTION_RULES,
|
||||||
|
'label' => 'Filter',
|
||||||
|
'key' => 'filter',
|
||||||
|
'type' => Database::SYSTEM_VAR_TYPE_TEXT,
|
||||||
|
'required' => false,
|
||||||
|
'array' => true,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
Database::SYSTEM_COLLECTION_USERS => [
|
Database::SYSTEM_COLLECTION_USERS => [
|
||||||
|
|
|
@ -455,13 +455,28 @@ class Database
|
||||||
|
|
||||||
foreach ($rules as $key => $rule) {
|
foreach ($rules as $key => $rule) {
|
||||||
$key = $rule->getAttribute('key', null);
|
$key = $rule->getAttribute('key', null);
|
||||||
$filters = $rule->getAttribute('filter', null);
|
$type = $rule->getAttribute('type', null);
|
||||||
|
$array = $rule->getAttribute('array', false);
|
||||||
|
$filters = $rule->getAttribute('filter', []);
|
||||||
$value = $document->getAttribute($key, null);
|
$value = $document->getAttribute($key, null);
|
||||||
|
|
||||||
if (($value !== null) && is_array($filters)) {
|
if (($value !== null)) {
|
||||||
foreach ($filters as $filter) {
|
if ($type === self::SYSTEM_VAR_TYPE_DOCUMENT) {
|
||||||
$value = $this->encodeAttribute($filter, $value);
|
if($array) {
|
||||||
$document->setAttribute($key, $value);
|
$list = [];
|
||||||
|
foreach ($value as $child) {
|
||||||
|
$list[] = $this->encode($child);
|
||||||
|
}
|
||||||
|
|
||||||
|
$document->setAttribute($key, $list);
|
||||||
|
} else {
|
||||||
|
$document->setAttribute($key, $this->encode($value));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($filters as $filter) {
|
||||||
|
$value = $this->encodeAttribute($filter, $value);
|
||||||
|
$document->setAttribute($key, $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -476,13 +491,28 @@ class Database
|
||||||
|
|
||||||
foreach ($rules as $key => $rule) {
|
foreach ($rules as $key => $rule) {
|
||||||
$key = $rule->getAttribute('key', null);
|
$key = $rule->getAttribute('key', null);
|
||||||
$filters = $rule->getAttribute('filter', null);
|
$type = $rule->getAttribute('type', null);
|
||||||
|
$array = $rule->getAttribute('array', false);
|
||||||
|
$filters = $rule->getAttribute('filter', []);
|
||||||
$value = $document->getAttribute($key, null);
|
$value = $document->getAttribute($key, null);
|
||||||
|
|
||||||
if (($value !== null) && is_array($filters)) {
|
if (($value !== null)) {
|
||||||
foreach (array_reverse($filters) as $filter) {
|
if ($type === self::SYSTEM_VAR_TYPE_DOCUMENT) {
|
||||||
$value = $this->decodeAttribute($filter, $value);
|
if($array) {
|
||||||
$document->setAttribute($key, $value);
|
$list = [];
|
||||||
|
foreach ($value as $child) {
|
||||||
|
$list[] = $this->decode($child);
|
||||||
|
}
|
||||||
|
|
||||||
|
$document->setAttribute($key, $list);
|
||||||
|
} else {
|
||||||
|
$document->setAttribute($key, $this->decode($value));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach (array_reverse($filters) as $filter) {
|
||||||
|
$value = $this->decodeAttribute($filter, $value);
|
||||||
|
$document->setAttribute($key, $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,6 +529,7 @@ class Database
|
||||||
static protected function encodeAttribute(string $name, $value)
|
static protected function encodeAttribute(string $name, $value)
|
||||||
{
|
{
|
||||||
if (!isset(self::$filters[$name])) {
|
if (!isset(self::$filters[$name])) {
|
||||||
|
return $value;
|
||||||
throw new Exception('Filter not found');
|
throw new Exception('Filter not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,6 +551,7 @@ class Database
|
||||||
static protected function decodeAttribute(string $name, $value)
|
static protected function decodeAttribute(string $name, $value)
|
||||||
{
|
{
|
||||||
if (!isset(self::$filters[$name])) {
|
if (!isset(self::$filters[$name])) {
|
||||||
|
return $value;
|
||||||
throw new Exception('Filter not found');
|
throw new Exception('Filter not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -221,10 +221,10 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertNotEmpty($response['body']['$id']);
|
$this->assertNotEmpty($response['body']['$id']);
|
||||||
$this->assertEquals('Project Test 2', $response['body']['name']);
|
$this->assertEquals('Project Test 2', $response['body']['name']);
|
||||||
// $this->assertArrayHasKey('platforms', $response['body']); // TODO enable when response model is enabled
|
$this->assertArrayHasKey('platforms', $response['body']);
|
||||||
// $this->assertArrayHasKey('webhooks', $response['body']); // TODO enable when response model is enabled
|
$this->assertArrayHasKey('webhooks', $response['body']);
|
||||||
// $this->assertArrayHasKey('keys', $response['body']); // TODO enable when response model is enabled
|
$this->assertArrayHasKey('keys', $response['body']);
|
||||||
// $this->assertArrayHasKey('tasks', $response['body']); // TODO enable when response model is enabled
|
$this->assertArrayHasKey('tasks', $response['body']);
|
||||||
|
|
||||||
$projectId = $response['body']['$id'];
|
$projectId = $response['body']['$id'];
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
$this->assertIsBool($response['body']['security']);
|
$this->assertIsBool($response['body']['security']);
|
||||||
$this->assertEquals(false, $response['body']['security']);
|
$this->assertEquals(false, $response['body']['security']);
|
||||||
$this->assertEquals('', $response['body']['httpUser']);
|
$this->assertEquals('', $response['body']['httpUser']);
|
||||||
// $this->assertEquals('', $response['body']['httpPass']); // TODO add after encrypt refactor
|
$this->assertEquals('', $response['body']['httpPass']);
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/webhooks/'.$webhookId, array_merge([
|
$response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/webhooks/'.$webhookId, array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
@ -462,7 +462,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
$this->assertIsBool($response['body']['security']);
|
$this->assertIsBool($response['body']['security']);
|
||||||
$this->assertEquals(false, $response['body']['security']);
|
$this->assertEquals(false, $response['body']['security']);
|
||||||
$this->assertEquals('', $response['body']['httpUser']);
|
$this->assertEquals('', $response['body']['httpUser']);
|
||||||
// $this->assertEquals('', $response['body']['httpPass']); // TODO add after encrypt refactor
|
$this->assertEquals('', $response['body']['httpPass']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
|
@ -759,7 +759,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
$this->assertContains('demo:value', $response['body']['httpHeaders']);
|
$this->assertContains('demo:value', $response['body']['httpHeaders']);
|
||||||
$this->assertCount(1, $response['body']['httpHeaders']);
|
$this->assertCount(1, $response['body']['httpHeaders']);
|
||||||
$this->assertEquals('username', $response['body']['httpUser']);
|
$this->assertEquals('username', $response['body']['httpUser']);
|
||||||
// $this->assertEquals('password', $response['body']['httpPass']); // TODO add after encrypt refactor
|
$this->assertEquals('password', $response['body']['httpPass']);
|
||||||
|
|
||||||
$data = array_merge($data, ['taskId' => $response['body']['$id']]);
|
$data = array_merge($data, ['taskId' => $response['body']['$id']]);
|
||||||
|
|
||||||
|
@ -901,7 +901,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
$this->assertContains('demo:value', $response['body']['httpHeaders']);
|
$this->assertContains('demo:value', $response['body']['httpHeaders']);
|
||||||
$this->assertCount(1, $response['body']['httpHeaders']);
|
$this->assertCount(1, $response['body']['httpHeaders']);
|
||||||
$this->assertEquals('username', $response['body']['httpUser']);
|
$this->assertEquals('username', $response['body']['httpUser']);
|
||||||
// $this->assertEquals('password', $response['body']['httpPass']); // TODO add after encrypt refactor
|
$this->assertEquals('password', $response['body']['httpPass']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
|
@ -952,7 +952,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
$this->assertContains('demo2:value2', $response['body']['httpHeaders']);
|
$this->assertContains('demo2:value2', $response['body']['httpHeaders']);
|
||||||
$this->assertCount(2, $response['body']['httpHeaders']);
|
$this->assertCount(2, $response['body']['httpHeaders']);
|
||||||
$this->assertEquals('username1', $response['body']['httpUser']);
|
$this->assertEquals('username1', $response['body']['httpUser']);
|
||||||
// $this->assertEquals('password1', $response['body']['httpPass']); // TODO add after encrypt refactor
|
$this->assertEquals('password1', $response['body']['httpPass']);
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
|
$response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/tasks/'.$taskId, array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
@ -972,7 +972,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
$this->assertContains('demo2:value2', $response['body']['httpHeaders']);
|
$this->assertContains('demo2:value2', $response['body']['httpHeaders']);
|
||||||
$this->assertCount(2, $response['body']['httpHeaders']);
|
$this->assertCount(2, $response['body']['httpHeaders']);
|
||||||
$this->assertEquals('username1', $response['body']['httpUser']);
|
$this->assertEquals('username1', $response['body']['httpUser']);
|
||||||
// $this->assertEquals('password1', $response['body']['httpPass']); // TODO add after encrypt refactor
|
$this->assertEquals('password1', $response['body']['httpPass']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
|
|
Loading…
Reference in a new issue