/** * Sample key: * abcdef1234566890 * Sample timestamp: * 1332470760 * Encoded key: * cc80462bfc0da7e614237d7cab4b7971b0e71e9f|1332470760 */ function test_sso_key_encoding() { $key = "abcdef1234566890"; iclicker_service::setSharedKey($key); // test expired timestamp $encodedKey = "cc80462bfc0da7e614237d7cab4b7971b0e71e9f|1332470760"; try { iclicker_service::verifyKey($encodedKey); $this->fail("should have died"); } catch (ClickerSecurityException $e) { $this->assertNotNull($e->getMessage()); } // test invalid format try { iclicker_service::verifyKey("xxxxxxxxxxxxx"); $this->fail("should have died"); } catch (InvalidArgumentException $e) { $this->assertNotNull($e->getMessage()); } try { iclicker_service::verifyKey("xxxxxxxxxxxxx|"); $this->fail("should have died"); } catch (InvalidArgumentException $e) { $this->assertNotNull($e->getMessage()); } try { iclicker_service::verifyKey("xxxxxxxx|12344ffff"); $this->fail("should have died"); } catch (InvalidArgumentException $e) { $this->assertNotNull($e->getMessage()); } // test valid encoded key $timestamp = time(); $encodedKey = sha1($key . ":" . $timestamp) . '|' . $timestamp; $result = iclicker_service::verifyKey($encodedKey); $this->assertTrue($result); echo "<div><b>SSO key:</b> key={$key}, ts={$timestamp} <br/> encoded=<input type='text' size='" . (strlen($encodedKey) + 2) . "' value='{$encodedKey}'/></div>" . PHP_EOL; }