Skip to content

Commit da93771

Browse files
committed
test: add test for maskSensitiveData()
1 parent 006d755 commit da93771

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

tests/system/Debug/ExceptionsTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,53 @@ public function testRenderBacktrace(): void
147147
);
148148
}
149149
}
150+
151+
public function testMaskSensitiveData(): void
152+
{
153+
$maskSensitiveData = $this->getPrivateMethodInvoker($this->exception, 'maskSensitiveData');
154+
155+
$trace = [
156+
0 => [
157+
'file' => '/var/www/CodeIgniter4/app/Controllers/Home.php',
158+
'line' => 15,
159+
'function' => 'f',
160+
'class' => 'App\\Controllers\\Home',
161+
'type' => '->',
162+
'args' => [
163+
0 => (object) [
164+
'password' => 'secret1',
165+
],
166+
1 => (object) [
167+
'default' => [
168+
'password' => 'secret2',
169+
],
170+
],
171+
2 => [
172+
'password' => 'secret3',
173+
],
174+
3 => [
175+
'default' => ['password' => 'secret4'],
176+
],
177+
],
178+
],
179+
1 => [
180+
'file' => '/var/www/CodeIgniter4/system/CodeIgniter.php',
181+
'line' => 932,
182+
'function' => 'index',
183+
'class' => 'App\\Controllers\\Home',
184+
'type' => '->',
185+
'args' => [
186+
],
187+
],
188+
];
189+
$keysToMask = ['password'];
190+
$path = '';
191+
192+
$newTrace = $maskSensitiveData($trace, $keysToMask, $path);
193+
194+
$this->assertSame(['password' => '******************'], (array) $newTrace[0]['args'][0]);
195+
$this->assertSame(['password' => '******************'], $newTrace[0]['args'][1]->default);
196+
$this->assertSame(['password' => '******************'], $newTrace[0]['args'][2]);
197+
$this->assertSame(['password' => '******************'], $newTrace[0]['args'][3]['default']);
198+
}
150199
}

0 commit comments

Comments
 (0)