Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F27208177
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/github/tests/XHubSignatureConstants.php b/github/tests/XHubSignatureConstants.php
index e7da00d..c48eb74 100644
--- a/github/tests/XHubSignatureConstants.php
+++ b/github/tests/XHubSignatureConstants.php
@@ -1,13 +1,18 @@
<?php
define('SECRET', 'secret123');
define('TIGER_ALGO', 'tiger192,4');
define('TIGER_PAYLOAD', 'lorem ipsum dolor');
define('TIGER_SIGNATURE', '7081ac97e50ad97e13b2fb9364b9df376c26b920080245ce');
-// Current default algo is sha-1.
+// Current default algo is sha-256. This test uses documentation values.
+define('DEFAULT_256_PAYLOAD', "Hello, World!");
+define('DEFAULT_256_SECRET', "It's a Secret to Everybody");
+define('DEFAULT_256_SIGNATURE', "757107ea0eb2509fc211221cce984b8a37570b6d7586c22c46f4379c8b043e17");
+
+// Legacy default algo is sha-1.
define('DEFAULT_PAYLOAD', file_get_contents(__DIR__ . '/payload.json'));
define('DEFAULT_SIGNATURE', 'ab05a3aef13696b60a60a8064b9fda31a8c77582');
define('EMPTY_DEFAULT_HASH_ALGO_SIGNATURE', 'fbdb1d1b18aa6c08324b7d64b71fb76370690e1d');
diff --git a/github/tests/XHubSignatureTest.php b/github/tests/XHubSignatureTest.php
index fbc3f96..29cf5d5 100644
--- a/github/tests/XHubSignatureTest.php
+++ b/github/tests/XHubSignatureTest.php
@@ -1,82 +1,95 @@
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use Keruald\GitHub\XHubSignature;
require 'XHubSignatureConstants.php';
class XHubSignatureTest extends TestCase {
protected $defaultInstance;
protected $tigerInstance;
protected function setUp() : void {
$this->defaultInstance = new XHubSignature(SECRET);
$this->tigerInstance = new XHubSignature(SECRET, TIGER_ALGO);
$this->defaultInstance->payload = DEFAULT_PAYLOAD;
$this->tigerInstance->payload = TIGER_PAYLOAD;
}
public function testValidate () : void {
$this->defaultInstance->signature = "";
$this->assertFalse($this->defaultInstance->validate());
$this->defaultInstance->signature = "bad signature";
$this->assertFalse($this->defaultInstance->validate());
$this->defaultInstance->signature = DEFAULT_SIGNATURE;
$this->assertTrue($this->defaultInstance->validate());
}
public function testCompute () : void {
$this->assertSame(
DEFAULT_SIGNATURE,
$this->defaultInstance->compute()
);
$this->assertSame(
TIGER_SIGNATURE,
$this->tigerInstance->compute()
);
}
+ ///
+ /// Tests for X-Hub-Signature-256 / SHA-256 (T2310)
+ ///
+
+ public function testCompute256 () : void {
+ $instance = new XHubSignature(DEFAULT_256_SECRET, "sha256");
+ $instance->payload = DEFAULT_256_PAYLOAD;
+ $this->assertSame(
+ DEFAULT_256_SIGNATURE,
+ $instance->compute()
+ );
+ }
+
///
/// Test static helper methods
///
#[CoversFunction(XHubSignature::validatePayload)]
public function testhashPayload () : void {
$this->assertSame(
EMPTY_DEFAULT_HASH_ALGO_SIGNATURE,
XHubSignature::hashPayload("", "")
);
$this->assertSame(
TIGER_SIGNATURE,
XHubSignature::hashPayload(SECRET, TIGER_PAYLOAD, TIGER_ALGO)
);
}
#[CoversFunction(XHubSignature::validatePayload)]
public function testValidatePayload () : void {
$this->assertFalse(XHubSignature::validatePayload("", "", ""));
$this->assertTrue(XHubSignature::validatePayload(
SECRET,
TIGER_PAYLOAD,
TIGER_SIGNATURE,
TIGER_ALGO
));
}
public function testParseSignature () : void {
$this->assertSame(
TIGER_SIGNATURE,
XHubSignature::parseSignature(TIGER_SIGNATURE)
);
$this->assertSame(
TIGER_SIGNATURE,
XHubSignature::parseSignature(TIGER_ALGO . '=' . TIGER_SIGNATURE)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, May 3, 06:53 (17 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3672092
Default Alt Text
(3 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment