|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2017 American Express Travel Related Services Company, Inc. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
|
15
|
|
|
* or implied. See the License for the specific language governing |
|
16
|
|
|
* permissions and limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
declare(strict_types=1); |
|
20
|
|
|
|
|
21
|
|
|
namespace AmericanExpressTest\HyperledgerFabricClient\Signatory; |
|
22
|
|
|
|
|
23
|
|
|
use AmericanExpress\HyperledgerFabricClient\Signatory\MdanterEccSignatory; |
|
24
|
|
|
use AmericanExpressTest\HyperledgerFabricClient\Chaincode\AbstractChaincodeTest; |
|
25
|
|
|
use Hyperledger\Fabric\Protos\Peer\Proposal; |
|
26
|
|
|
use Hyperledger\Fabric\Protos\Peer\SignedProposal; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @covers \AmericanExpress\HyperledgerFabricClient\Signatory\MdanterEccSignatory |
|
30
|
|
|
*/ |
|
31
|
|
|
class MdanterEccSignatoryTest extends AbstractChaincodeTest |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var MdanterEccSignatory |
|
35
|
|
|
*/ |
|
36
|
|
|
private $sut; |
|
37
|
|
|
|
|
38
|
|
|
protected function setUp() |
|
39
|
|
|
{ |
|
40
|
|
|
parent::setUp(); |
|
41
|
|
|
$this->sut = new MdanterEccSignatory(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testSignEmptyProposal() |
|
45
|
|
|
{ |
|
46
|
|
|
$result = $this->sut->signProposal(new Proposal(), $this->privateKeyFile); |
|
47
|
|
|
|
|
48
|
|
|
self::assertInstanceOf(SignedProposal::class, $result); |
|
49
|
|
|
self::assertInternalType('string', $result->getProposalBytes()); |
|
50
|
|
|
self::assertEmpty($result->getProposalBytes()); |
|
51
|
|
|
self::assertInternalType('string', $result->getSignature()); |
|
52
|
|
|
self::assertNotEmpty($result->getSignature()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testSignProposal() |
|
56
|
|
|
{ |
|
57
|
|
|
$proposal = new Proposal(); |
|
58
|
|
|
$proposal->setHeader('HEADER-STRING'); |
|
59
|
|
|
$proposal->setPayload('PAYLOAD-STRING'); |
|
60
|
|
|
$result = $this->sut->signProposal($proposal, $this->privateKeyFile); |
|
61
|
|
|
|
|
62
|
|
|
self::assertEquals( |
|
63
|
|
|
'Cg1IRUFERVItU1RSSU5HEg5QQVlMT0FELVNUUklORw==', |
|
64
|
|
|
base64_encode($result->getProposalBytes()) |
|
65
|
|
|
); |
|
66
|
|
|
self::assertEquals( |
|
67
|
|
|
'MEQCIEfgYNT2Rve6kGy7Ter1/77KcJin1MImCroLqIzdiLmtAiBRjOCkd7aW6KM+qRzDxWmC1+X9aP/tzWD6/Z5a2E9zOA==', |
|
68
|
|
|
base64_encode($result->getSignature()) |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @dataProvider getProposalSignatureCharacterizationData |
|
74
|
|
|
* @param string $encodedProposalBytes |
|
75
|
|
|
* @param string $encodedSignature |
|
76
|
|
|
* @param string $proposalHeader |
|
77
|
|
|
* @param string $proposalPayload |
|
78
|
|
|
* @param string $proposalExtension |
|
79
|
|
|
*/ |
|
80
|
|
|
public function testGetSCharacterization( |
|
81
|
|
|
string $encodedProposalBytes, |
|
82
|
|
|
string $encodedSignature, |
|
83
|
|
|
string $proposalHeader, |
|
84
|
|
|
string $proposalPayload, |
|
85
|
|
|
string $proposalExtension |
|
86
|
|
|
) { |
|
87
|
|
|
$proposal = new Proposal(); |
|
88
|
|
|
$proposal->setHeader(base64_decode($proposalHeader)); |
|
|
|
|
|
|
89
|
|
|
$proposal->setPayload(base64_decode($proposalPayload)); |
|
|
|
|
|
|
90
|
|
|
$proposal->setExtension(base64_decode($proposalExtension)); |
|
|
|
|
|
|
91
|
|
|
$result = $this->sut->signProposal($proposal, new \SplFileObject($this->privateKey->url())); |
|
92
|
|
|
|
|
93
|
|
|
self::assertInstanceOf(SignedProposal::class, $result); |
|
94
|
|
|
self::assertEquals($encodedProposalBytes, base64_encode($result->getProposalBytes())); |
|
95
|
|
|
self::assertEquals($encodedSignature, base64_encode($result->getSignature())); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @covers \AmericanExpress\HyperledgerFabricClient\Signatory\MdanterEccSignatory::getS |
|
100
|
|
|
* @dataProvider dataGetS |
|
101
|
|
|
* @param string $dateTime |
|
102
|
|
|
* @param string $encodedProposalBytes |
|
103
|
|
|
* @param string $encodedSignature |
|
104
|
|
|
*/ |
|
105
|
|
|
public function testGetS(string $dateTime, string $encodedProposalBytes, string $encodedSignature) |
|
106
|
|
|
{ |
|
107
|
|
|
$proposal = $this->createChaincodeProposal($dateTime, $this->getPrivateKeyFile()); |
|
108
|
|
|
$result = $this->sut->signProposal($proposal, new \SplFileObject($this->privateKey->url())); |
|
109
|
|
|
|
|
110
|
|
|
self::assertInstanceOf(SignedProposal::class, $result); |
|
111
|
|
|
self::assertEquals($encodedProposalBytes, base64_encode($result->getProposalBytes())); |
|
112
|
|
|
self::assertEquals($encodedSignature, base64_encode($result->getSignature())); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
View Code Duplication |
public function getProposalSignatureCharacterizationData() |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
$data = $this->loadStaticData(); |
|
118
|
|
|
|
|
119
|
|
|
return array_map( |
|
120
|
|
|
function ($value) { |
|
121
|
|
|
return array_intersect_key( |
|
122
|
|
|
$value, |
|
123
|
|
|
array_flip([ |
|
124
|
|
|
'encodedProposalBytes', |
|
125
|
|
|
'encodedSignature', |
|
126
|
|
|
'proposalHeader', |
|
127
|
|
|
'proposalPayload', |
|
128
|
|
|
'proposalExtension', |
|
129
|
|
|
]) |
|
130
|
|
|
); |
|
131
|
|
|
}, |
|
132
|
|
|
$data |
|
133
|
|
|
); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function dataGetS() |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->loadStaticData(); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|