public function testSaveAndOthers() { $oauthToken = OAuthToken::generate(); $oauthToken->save(); //test for record ID to verify that record is saved $this->assertTrue(isset($oauthToken->id)); $this->assertEquals(12, strlen($oauthToken->id)); //test load method $this->load($oauthToken->id); //test invalidate method $token = OAuthToken::load($oauthToken->id); $this->invalidate($token); //test authorize method $this->authorize($token); //test mark_deleted method $this->mark_deleted($oauthToken->id); }
/** * @ticket 62822 */ public function testCleanup() { // create request token $tok = OAuthToken::generate(); $tok->consumer = create_guid(); $tok->setState(OAuthToken::REQUEST); $tok->assigned_user_id = $GLOBALS['current_user']->id; $tok->save(); // create invalid token $tok = OAuthToken::generate(); $tok->consumer = create_guid(); $tok->setState(OAuthToken::INVALID); $tok->assigned_user_id = $GLOBALS['current_user']->id; $tok->save(); $cnt = $GLOBALS['db']->getOne("SELECT count(*) c FROM {$tok->table_name} WHERE assigned_user_id=" . $GLOBALS['db']->quoted($GLOBALS['current_user']->id)); $this->assertEquals(2, $cnt, "Wrong number of tokens in the table"); // set time way in the past $GLOBALS['db']->query("UPDATE {$tok->table_name} SET token_ts=1 WHERE assigned_user_id=" . $GLOBALS['db']->quoted($GLOBALS['current_user']->id)); // run cleanup OAuthToken::cleanup(); // ensure tokens are gone $cnt = $GLOBALS['db']->getOne("SELECT count(*) c FROM {$tok->table_name} WHERE assigned_user_id=" . $GLOBALS['db']->quoted($GLOBALS['current_user']->id)); $this->assertEquals(0, $cnt, "Tokens were not deleted"); }
/** * Generate access token string - must have validated request token * @return string */ public function accessToken() { $GLOBALS['log']->debug("OAUTH: accessToken"); if (empty($this->token) || $this->token->tstate != OAuthToken::REQUEST) { return null; } $this->token->invalidate(); $token = OAuthToken::generate(); $token->setState(OAuthToken::ACCESS); $token->setConsumer($this->consumer); // transfer user data from request token $token->copyAuthData($this->token); $token->save(); return $token->queryString(); }