Skip to content

Commit

Permalink
Merge pull request #419 from kbrabrand/array-adapter-validation
Browse files Browse the repository at this point in the history
Add check for public key duplicates
  • Loading branch information
rexxars committed Dec 7, 2015
2 parents 0ab2bc7 + 29dd8df commit 21ffea1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
23 changes: 23 additions & 0 deletions library/Imbo/Auth/AccessControl/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function __construct(array $accessList = [], $groups = []) {
$this->accessList = $accessList;
$this->groups = $groups;
$this->keys = $this->getKeysFromAcl();

$this->validateAccessList();
}

/**
Expand Down Expand Up @@ -174,4 +176,25 @@ private function getKeysFromAcl() {

return $keys;
}

/**
* Validate access list data
*
* @throws InvalidArgumentException
*/
private function validateAccessList() {
// Get all user lists
$declaredPublicKeys = array_map(function($acl) {
return $acl['publicKey'];
}, $this->accessList);

$publicKeys = [];
foreach ($declaredPublicKeys as $key) {
if (in_array($key, $publicKeys)) {
throw new InvalidArgumentException('Public key declared twice in config: ' . $key, 500);
}

$publicKeys[] = $key;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,15 @@ public function getAuthConfig() {
'public key does not exist' => [$users, 'publicKey3', null],
];
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Public key declared twice in config: pubkey
*/
public function testThrowsErrorOnDuplicatePublicKey() {
$accessControl = new ArrayAdapter([
['publicKey' => 'pubkey', 'privateKey' => 'privkey', 'acl' => []],
['publicKey' => 'pubkey', 'privateKey' => 'privkey', 'acl' => []]
]);
}
}

0 comments on commit 21ffea1

Please sign in to comment.