-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLocalResponseV1Test.php
More file actions
132 lines (105 loc) · 4.36 KB
/
LocalResponseV1Test.php
File metadata and controls
132 lines (105 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace V1\Input;
use Mindee\Input\LocalResponse;
use PHPUnit\Framework\TestCase;
class LocalResponseV1Test extends TestCase
{
private string $signature;
private string $dummyKey;
private string $filePath;
protected function setUp(): void
{
$this->filePath = \TestingUtilities::getV1DataDir() . '/async/get_completed_empty.json';
$this->signature = "5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0";
$this->dummyKey = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH";
}
public function testValidFileLocalResponse()
{
$file = fopen($this->filePath, 'rb');
$localResponse = new LocalResponse($file);
fclose($file);
$this->assertNotNull($localResponse->toArray(), 'Local response file should not be null');
$invalidSignature = 'invalid_signature';
$this->assertFalse(
$localResponse->isValidHmacSignature($this->dummyKey, $invalidSignature),
'Invalid signature should not be valid'
);
$calculatedSignature = $localResponse->getHmacSignature($this->dummyKey);
$this->assertEquals(
$this->signature,
$calculatedSignature,
'Calculated signature should match the expected valid signature'
);
$this->assertTrue(
$localResponse->isValidHmacSignature($this->dummyKey, $this->signature),
'Valid signature should be valid'
);
}
public function testValidStringLocalResponse()
{
$file = file_get_contents($this->filePath);
$localResponse = new LocalResponse($file);
$this->assertNotNull($localResponse->toArray(), 'Local response file should not be null');
$invalidSignature = 'invalid_signature';
$this->assertFalse(
$localResponse->isValidHmacSignature($this->dummyKey, $invalidSignature),
'Invalid signature should not be valid'
);
$calculatedSignature = $localResponse->getHmacSignature($this->dummyKey);
$this->assertEquals(
$this->signature,
$calculatedSignature,
'Calculated signature should match the expected valid signature'
);
$this->assertTrue(
$localResponse->isValidHmacSignature($this->dummyKey, $this->signature),
'Valid signature should be valid'
);
}
public function testValidStreamLocalResponse()
{
// Create a stream from the file content
$stream = fopen('php://memory', 'r+');
fwrite($stream, file_get_contents($this->filePath));
rewind($stream);
// Create LocalResponse instance with the stream
$localResponse = new LocalResponse($stream);
$this->assertNotNull($localResponse->toArray(), 'Local response file should not be null');
$invalidSignature = 'invalid_signature';
$this->assertFalse(
$localResponse->isValidHmacSignature($this->dummyKey, $invalidSignature),
'Invalid signature should not be valid'
);
$calculatedSignature = $localResponse->getHmacSignature($this->dummyKey);
$this->assertEquals(
$this->signature,
$calculatedSignature,
'Calculated signature should match the expected valid signature'
);
$this->assertTrue(
$localResponse->isValidHmacSignature($this->dummyKey, $this->signature),
'Valid signature should be valid'
);
fclose($stream); // Close the stream after use
}
public function testValidFilePathLocalResponse()
{
$localResponse = new LocalResponse($this->filePath);
$this->assertNotNull($localResponse->toArray(), 'Local response file should not be null');
$invalidSignature = 'invalid_signature';
$this->assertFalse(
$localResponse->isValidHmacSignature($this->dummyKey, $invalidSignature),
'Invalid signature should not be valid'
);
$calculatedSignature = $localResponse->getHmacSignature($this->dummyKey);
$this->assertEquals(
$this->signature,
$calculatedSignature,
'Calculated signat match the expected valid signature'
);
$this->assertTrue(
$localResponse->isValidHmacSignature($this->dummyKey, $this->signature),
'Valid signature should be valid'
);
}
}