-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api tester): enable specific user authentication for given endpoint
- Loading branch information
Showing
6 changed files
with
98 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
namespace APITester\Config; | ||
|
||
use APITester\Util\Filterable; | ||
use Symfony\Component\Yaml\Tag\TaggedValue; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
final class Filters | ||
|
@@ -116,4 +118,60 @@ private function getBaseLineData(): array | |
/** @var array{'exclude': ?array<int, array<string, string>>} */ | ||
return Yaml::parseFile($this->getBaseline()); | ||
} | ||
|
||
/** | ||
* @param array<array<string, string>> $includeFilters | ||
* @param array<array<string, string>> $excludeFilters | ||
*/ | ||
public function includes(Filterable $object): bool | ||
Check failure on line 126 in src/Config/Filters.php GitHub Actions / PHPStan
Check failure on line 126 in src/Config/Filters.php GitHub Actions / PHPStan
|
||
{ | ||
$include = true; | ||
foreach ($this->getInclude() as $item) { | ||
$include = true; | ||
foreach ($item as $key => $value) { | ||
[$operator, $value] = $this->handleTags($value); | ||
if (!$object->has($key, $value, $operator)) { | ||
$include = false; | ||
continue 2; | ||
} | ||
} | ||
break; | ||
} | ||
|
||
if (!$include) { | ||
return false; | ||
} | ||
|
||
foreach ($this->getExclude() as $item) { | ||
foreach ($item as $key => $value) { | ||
[$operator, $value] = $this->handleTags($value); | ||
if (!$object->has($key, $value, $operator)) { | ||
continue 2; | ||
} | ||
} | ||
$include = false; | ||
break; | ||
} | ||
|
||
return $include; | ||
} | ||
|
||
|
||
|
||
/** | ||
* @return array{0: string, 1: string|int} | ||
*/ | ||
private function handleTags(string|int|TaggedValue $value): array | ||
{ | ||
$operator = '='; | ||
|
||
if ($value instanceof TaggedValue) { | ||
if ($value->getTag() === 'NOT') { | ||
$operator = '!='; | ||
} | ||
$value = (string) $value->getValue(); | ||
} | ||
|
||
return [$operator, $value]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters