Skip to content

Commit

Permalink
make placeholder a const for reuse
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz authored and backportbot-nextcloud[bot] committed Jun 16, 2022
1 parent ff1b29f commit 95f0eb1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/private/Log/ExceptionSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
use OCA\Encryption\Session;

class ExceptionSerializer {
public const SENSITIVE_VALUE_PLACEHOLDER = '*** sensitive parameters replaced ***';

public const methodsWithSensitiveParameters = [
// Session/User
'completeLogin',
Expand Down Expand Up @@ -180,7 +182,7 @@ private function editTrace(array &$sensitiveValues, array $traceLine): array {
if (isset($traceLine['args'])) {
$sensitiveValues = array_merge($sensitiveValues, $traceLine['args']);
}
$traceLine['args'] = ['*** sensitive parameters replaced ***'];
$traceLine['args'] = [self::SENSITIVE_VALUE_PLACEHOLDER];
return $traceLine;
}

Expand Down Expand Up @@ -211,7 +213,7 @@ private function removeValuesFromArgs($args, $values) {
$workArgs = [];
foreach ($args as $arg) {
if (in_array($arg, $values, true)) {
$arg = '*** sensitive parameter replaced ***';
$arg = self::SENSITIVE_VALUE_PLACEHOLDER;
} elseif (is_array($arg)) {
$arg = $this->removeValuesFromArgs($arg, $values);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/Log/ExceptionSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testSerializer() {
} catch (\Exception $e) {
$serializedData = $this->serializer->serializeException($e);
$this->assertSame(['Secret'], $secret);
$this->assertSame('*** sensitive parameters replaced ***', $serializedData['Trace'][0]['args'][0]);
$this->assertSame(ExceptionSerializer::SENSITIVE_VALUE_PLACEHOLDER, $serializedData['Trace'][0]['args'][0]);
}
}
}

0 comments on commit 95f0eb1

Please sign in to comment.