Skip to content

Commit d5b01a3

Browse files
Merge pull request #70 from paragonie/improve-test-coverage
Add test case to prevent regressions
2 parents 2947162 + 8ceb73a commit d5b01a3

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

tests/Base64Test.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function getNextChar(string $c): string
137137
);
138138
}
139139

140-
public function testUnpadded()
140+
public function testUnpadded(): void
141141
{
142142
for ($i = 1; $i < 32; ++$i) {
143143
$random = random_bytes($i);
@@ -160,11 +160,27 @@ public static function invalidCharactersProvider(): array
160160
];
161161
}
162162

163+
/**
164+
* Detect issue underlying #67 with ext-sodium
165+
*
166+
* @return void
167+
* @throws Exception
168+
*/
169+
public function testStrictPaddingSodium(): void
170+
{
171+
for ($i = 1; $i < 32; ++$i) {
172+
$random = random_bytes($i);
173+
$encoded = Base64::encode($random);
174+
$decoded = Base64::decode($encoded, true);
175+
$this->assertSame($decoded, $random);
176+
}
177+
}
178+
163179
/**
164180
* @dataProvider invalidCharactersProvider
165181
*/
166182
#[DataProvider("invalidCharactersProvider")]
167-
public function testInvalidCharacters(string $encoded)
183+
public function testInvalidCharacters(string $encoded): void
168184
{
169185
$this->expectException(RangeException::class);
170186
Base64::decode($encoded);

tests/Base64UrlSafeTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,22 @@ public static function invalidCharactersProvider(): array
120120
];
121121
}
122122

123+
/**
124+
* Detect issue underlying #67 with ext-sodium
125+
*
126+
* @return void
127+
* @throws Exception
128+
*/
129+
public function testStrictPaddingSodium(): void
130+
{
131+
for ($i = 1; $i < 32; ++$i) {
132+
$random = random_bytes($i);
133+
$encoded = Base64UrlSafe::encode($random);
134+
$decoded = Base64UrlSafe::decode($encoded, true);
135+
$this->assertSame($decoded, $random);
136+
}
137+
}
138+
123139
/**
124140
* @dataProvider invalidCharactersProvider
125141
*/

0 commit comments

Comments
 (0)