3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Class CRM_Utils_SignerTest
32 class CRM_Utils_SignerTest
extends CiviUnitTestCase
{
34 public function setUp() {
38 public function testSignValidate() {
41 'signParams' => array(
46 'validateParams' => array(
54 'signParams' => array(
59 'validateParams' => array(
63 'irrelevant' => 'totally-irrelevant',
68 'signParams' => array(
73 'validateParams' => array(
81 'signParams' => array(
86 'validateParams' => array(
94 'signParams' => array(
99 'validateParams' => array(
107 'signParams' => array(
112 'validateParams' => array(
120 'signParams' => array(
125 'validateParams' => array(
133 'signParams' => array(
137 'validateParams' => array(
138 'a' => '1', // string
144 foreach ($cases as $caseId => $case) {
145 $signer = new CRM_Utils_Signer('secret', array('a', 'b', 'c'));
146 $signature = $signer->sign($case['signParams']);
147 $this->assertTrue(!empty($signature) && is_string($signature)); // arbitrary
149 $validator = new CRM_Utils_Signer('secret', array('a', 'b', 'c')); // same as $signer but physically separate
150 $isValid = $validator->validate($signature, $case['validateParams']);
152 if ($isValid !== $case['isValid']) {
153 $this->fail("Case ${caseId}: Mismatch: " . var_export($case, TRUE));
155 $this->assertTrue(TRUE, 'Validation yielded expected result');