0, 'live_streaming_pass' => 'streaming-pass']; $rKey = Encryption::encrypt(self::SECRET, 'streaming-pass', OPENSSL_EXTRA); $GLOBALS['db'] = new class($rKey) { public function __construct(private string $rKey) { } public function query($rQuery) { return true; } public function get_rows() { return [['id' => 9, 'key' => $this->rKey]]; } }; } private function check(string $rHMAC) { return AuthService::validateHMAC($rHMAC, '', 1, 'ts', '', '', self::IDENTIFIER, 0); } public function testTheKeysHmacIsAccepted(): void { $rGenuine = hash_hmac('sha256', '1##ts######' . self::IDENTIFIER . '##0', self::SECRET); $this->assertSame('0e554217211296920002813236859630', md5($rGenuine), 'fixture'); $this->assertSame(9, $this->check($rGenuine)); } public function testAValueWhoseMd5ReadsAsZeroIsNotTheKey(): void { $this->assertSame('0e462097431906509019562988736854', md5('240610708'), 'fixture'); $this->assertNull($this->check('240610708')); } public function testAnotherHmacIsRefused(): void { $this->assertNull($this->check(hash_hmac('sha256', '1##ts######' . self::IDENTIFIER . '##0', 'other-secret'))); $this->assertNull($this->check('')); } }