Skip to content

Commit

Permalink
Merge pull request #34 from strotgen/master
Browse files Browse the repository at this point in the history
  • Loading branch information
cindreta authored May 7, 2022
2 parents 659d67c + 91f51f5 commit 81a8335
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Middlewares/TreblleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ public function maskFields($data): array
}
}
} else {
$data[$key] = str_repeat('*', strlen($value));
$data[$key] = $value != null
? str_repeat('*', strlen($value))
: $value;
}
}
}
Expand Down
40 changes: 40 additions & 0 deletions tests/Middlewares/TreblleMiddlewareTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Treblle\Tests\Middlewares;

use Treblle\Middlewares\TreblleMiddleware;
use Treblle\Tests\TestCase;

class TreblleMiddlewareTest extends TestCase
{
/**
* @var TreblleMiddleware
*/
private $treblleMiddleware;

protected function setUp(): void
{
parent::setUp();

$this->treblleMiddleware = new TreblleMiddleware();
}

public function testRequestWithNullValueIsMaskedCorrectly(): void
{
$requestWithNullField = [
'cc' => null,
'otherValue' => 'something',
'password' => '1234',
];

$maskedRequest = $this->treblleMiddleware->maskFields($requestWithNullField);

$this->assertEquals($maskedRequest, [
'cc' => null, // Should be left as null value
'otherValue' => 'something',
'password' => '****', // Should be masked
]);
}
}

0 comments on commit 81a8335

Please sign in to comment.