public function testGeneratesTokenWithData() { // Arrange // This sessionId is a fixture designed by using a known but bogus apiKey and apiSecret $sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI'; $bogusApiKey = '12345678'; $bogusApiSecret = '0123456789abcdef0123456789abcdef0123456789'; $opentok = new OpenTok($bogusApiKey, $bogusApiSecret); // Act $userStatus = '{nick:"johnny",status:"hey there fellas!"}'; $token = $opentok->generateToken($sessionId, array('data' => $userStatus)); // Assert $this->assertInternalType('string', $token); $decodedToken = TestHelpers::decodeToken($token); $this->assertEquals($sessionId, $decodedToken['session_id']); $this->assertEquals($bogusApiKey, $decodedToken['partner_id']); $this->assertNotEmpty($decodedToken['nonce']); $this->assertNotEmpty($decodedToken['create_time']); $this->assertEquals($userStatus, $decodedToken['connection_data']); $this->assertNotEmpty($decodedToken['role']); // TODO: should all tokens have a default expire time even if it wasn't specified? //$this->assertNotEmpty($decodedToken['expire_time']); $this->assertNotEmpty($decodedToken['sig']); $this->assertEquals(hash_hmac('sha1', $decodedToken['dataString'], $bogusApiSecret), $decodedToken['sig']); }
public function testGeneratesToken() { $sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI'; $bogusApiKey = '12345678'; $bogusApiSecret = '0123456789abcdef0123456789abcdef0123456789'; $opentok = new OpenTok($bogusApiKey, $bogusApiSecret); $session = new Session($opentok, $sessionId); $token = $session->generateToken(); $this->assertInternalType('string', $token); $decodedToken = TestHelpers::decodeToken($token); $this->assertEquals($sessionId, $decodedToken['session_id']); $this->assertEquals($bogusApiKey, $decodedToken['partner_id']); $this->assertNotEmpty($decodedToken['nonce']); $this->assertNotEmpty($decodedToken['create_time']); $this->assertArrayNotHasKey('connection_data', $decodedToken); // TODO: should all tokens have a role of publisher even if this wasn't specified? //$this->assertNotEmpty($decodedToken['role']); // TODO: should all tokens have a default expire time even if it wasn't specified? //$this->assertNotEmpty($decodedToken['expire_time']); $this->assertNotEmpty($decodedToken['sig']); $this->assertEquals(hash_hmac('sha1', $decodedToken['dataString'], $bogusApiSecret), $decodedToken['sig']); }