Skip to content

Commit

Permalink
SecurityExtension: password can be dynamic [Closes #74]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 4, 2024
1 parent 4391db3 commit d698efe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Bridges/SecurityDI/SecurityExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function getConfigSchema(): Nette\Schema\Schema
'debugger' => Expect::bool(),
'users' => Expect::arrayOf(
Expect::anyOf(
Expect::string(), // user => password
Expect::string()->dynamic(), // user => password
Expect::structure([ // user => password + roles + data
'password' => Expect::string(),
'password' => Expect::string()->dynamic(),
'roles' => Expect::anyOf(Expect::string(), Expect::listOf('string')),
'data' => Expect::array(),
])->castTo('array'),
Expand Down
6 changes: 6 additions & 0 deletions tests/Security.DI/SecurityExtension.authenticator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ security:
admin: {password: admin123, roles: [admin, user]}
user: {password: user123}
moderator: {password: moderator123, roles: moderator}
dynamic1: ::trim(xxx)
dynamic2: {password: ::trim(xxx)}
', 'neon'));

eval($compiler->addConfig($config)->compile());
Expand All @@ -43,12 +45,16 @@ $userList = [
'admin' => 'admin123',
'user' => 'user123',
'moderator' => 'moderator123',
'dynamic1' => 'xxx',
'dynamic2' => 'xxx',
];
$expectedRoles = [
'john' => [],
'admin' => ['admin', 'user'],
'user' => [],
'moderator' => ['moderator'],
'dynamic1' => [],
'dynamic2' => [],
];

foreach ($userList as $username => $password) {
Expand Down

0 comments on commit d698efe

Please # to comment.