Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
40.00% |
4 / 10 |
|
28.57% |
2 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ResourceSignatureValidator | |
40.00% |
4 / 10 |
|
28.57% |
2 / 7 |
17.58 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| evaluate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOptions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMessage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setMessage | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| setOptions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2017 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\helpers\form\validators; |
| 23 | |
| 24 | use InvalidArgumentException; |
| 25 | use oat\oatbox\validator\ValidatorInterface; |
| 26 | use oat\tao\model\security\SecurityException; |
| 27 | use oat\tao\model\security\SignatureValidator; |
| 28 | |
| 29 | final class ResourceSignatureValidator implements ValidatorInterface |
| 30 | { |
| 31 | /** @var string */ |
| 32 | private $uri; |
| 33 | |
| 34 | /** string */ |
| 35 | private $message = 'Signature is not valid'; |
| 36 | /** |
| 37 | * @var SignatureValidator |
| 38 | */ |
| 39 | private $signatureValidator; |
| 40 | |
| 41 | /** |
| 42 | * @param SignatureValidator $signatureValidator |
| 43 | * @param string $uri |
| 44 | */ |
| 45 | public function __construct(SignatureValidator $signatureValidator, $uri) |
| 46 | { |
| 47 | $this->uri = $uri; |
| 48 | $this->signatureValidator = $signatureValidator; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @param string $signature |
| 53 | * |
| 54 | * @return boolean true only if valid |
| 55 | * |
| 56 | * @throws SecurityException |
| 57 | * @throws \oat\tao\model\metadata\exception\InconsistencyConfigException |
| 58 | */ |
| 59 | public function evaluate($signature) |
| 60 | { |
| 61 | $this->signatureValidator->checkSignature($signature, $this->uri); |
| 62 | |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @return string |
| 68 | */ |
| 69 | public function getName() |
| 70 | { |
| 71 | return __CLASS__; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @return array |
| 76 | */ |
| 77 | public function getOptions() |
| 78 | { |
| 79 | return []; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @return string |
| 84 | */ |
| 85 | public function getMessage() |
| 86 | { |
| 87 | return $this->message; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @param string $message |
| 92 | * |
| 93 | * @return $this |
| 94 | */ |
| 95 | public function setMessage($message) |
| 96 | { |
| 97 | $this->message = $message; |
| 98 | |
| 99 | return $this; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @param array $options |
| 104 | */ |
| 105 | public function setOptions(array $options) |
| 106 | { |
| 107 | throw new InvalidArgumentException('This validator does not have any options'); |
| 108 | } |
| 109 | } |