1
0

AccessTokenMapperTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace OCA\OAuth2\Tests\Db;
  22. use OCA\OAuth2\Db\AccessToken;
  23. use OCA\OAuth2\Db\AccessTokenMapper;
  24. use Test\TestCase;
  25. /**
  26. * @group DB
  27. */
  28. class AccessTokenMapperTest extends TestCase {
  29. /** @var AccessTokenMapper */
  30. private $accessTokenMapper;
  31. public function setUp() {
  32. parent::setUp();
  33. $this->accessTokenMapper = new AccessTokenMapper(\OC::$server->getDatabaseConnection());
  34. }
  35. public function testGetByCode() {
  36. $this->accessTokenMapper->deleteByClientId(1234);
  37. $token = new AccessToken();
  38. $token->setClientId(1234);
  39. $token->setTokenId((string)time());
  40. $token->setEncryptedToken('MyEncryptedToken');
  41. $token->setHashedCode(hash('sha512', 'MyAwesomeToken'));
  42. $this->accessTokenMapper->insert($token);
  43. $token->resetUpdatedFields();
  44. $result = $this->accessTokenMapper->getByCode('MyAwesomeToken');
  45. $this->assertEquals($token, $result);
  46. $this->accessTokenMapper->delete($token);
  47. }
  48. /**
  49. * @expectedException \OCA\OAuth2\Exceptions\AccessTokenNotFoundException
  50. */
  51. public function testDeleteByClientId() {
  52. $this->accessTokenMapper->deleteByClientId(1234);
  53. $token = new AccessToken();
  54. $token->setClientId(1234);
  55. $token->setTokenId((string)time());
  56. $token->setEncryptedToken('MyEncryptedToken');
  57. $token->setHashedCode(hash('sha512', 'MyAwesomeToken'));
  58. $this->accessTokenMapper->insert($token);
  59. $token->resetUpdatedFields();
  60. $this->accessTokenMapper->deleteByClientId(1234);
  61. $this->accessTokenMapper->getByCode('MyAwesomeToken');
  62. }
  63. }