‪TYPO3CMS  9.5
SplitStorageTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
24 class ‪SplitStorageTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
25 {
31  protected ‪$xmlDatabaseFixtures = [
32  'typo3/sysext/rsaauth/Tests/Functional/Fixtures/tx_rsaauth_keys.xml'
33  ];
34 
40  protected ‪$testExtensionsToLoad = [
41  'typo3/sysext/rsaauth'
42  ];
43 
47  protected ‪$subject;
48 
52  protected ‪$testKey = '666cb6d79dc65973df67571bbdc5beca';
53 
57  protected ‪$testKeyLeftPart = '666cb6d79dc65973';
58 
62  protected ‪$testKeyRightPart = 'df67571bbdc5beca';
63 
67  protected function ‪setUp()
68  {
69  parent::setUp();
70  foreach ($this->xmlDatabaseFixtures as $fixture) {
71  $this->importDataSet($fixture);
72  }
73  $this->subject = GeneralUtility::makeInstance(SplitStorage::class);
74  // same timestamp as in Fixtures/tx_rsaauth_keys.xml
75  ‪$GLOBALS['EXEC_TIME'] = 1465391843;
76  $_SESSION['tx_rsaauth_key'] = [1, ‪$this->testKeyLeftPart];
77  }
78 
82  public function ‪getReturnsKeyFromDatabase()
83  {
84  $key = $this->subject->get();
85  $this->assertEquals($this->testKey, $key);
86  }
87 
91  public function ‪putInsertsKeyIntoDatabase()
92  {
93  $this->subject->put($this->testKey);
94  $this->assertEquals($this->testKey, $this->subject->get());
95  }
96 
100  public function ‪getDeletesKeysOlderThan30Minutes()
101  {
102  $outDatedKeyId = 3;
103  $_SESSION['tx_rsaauth_key'] = [1, ‪$this->testKeyLeftPart];
104 
105  $key = GeneralUtility::makeInstance(ConnectionPool::class)
106  ->getConnectionForTable('tx_rsaauth_keys')
107  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
108  ->fetchColumn();
109 
110  $this->assertEquals($this->testKeyRightPart, $key);
111 
112  $this->subject->get();
113 
114  $key = GeneralUtility::makeInstance(ConnectionPool::class)
115  ->getConnectionForTable('tx_rsaauth_keys')
116  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
117  ->fetchColumn();
118 
119  $this->assertFalse($key);
120  }
121 
125  public function ‪putDeletesKeysOlderThan30Minutes()
126  {
127  $outDatedKeyId = 3;
128  $_SESSION['tx_rsaauth_key'] = [1, ‪$this->testKeyLeftPart];
129 
130  $key = GeneralUtility::makeInstance(ConnectionPool::class)
131  ->getConnectionForTable('tx_rsaauth_keys')
132  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
133  ->fetchColumn();
134 
135  $this->assertEquals($this->testKeyRightPart, $key);
136 
137  $this->subject->put('testkey');
138 
139  $key = GeneralUtility::makeInstance(ConnectionPool::class)
140  ->getConnectionForTable('tx_rsaauth_keys')
141  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
142  ->fetchColumn();
143 
144  $this->assertFalse($key);
145  }
146 
150  public function ‪putDeletesCurrentKeyIfNullIsGiven()
151  {
152  $keyToBeDeleted = 1;
153  $_SESSION['tx_rsaauth_key'] = [$keyToBeDeleted, ‪$this->testKeyLeftPart];
154 
155  $key = GeneralUtility::makeInstance(ConnectionPool::class)
156  ->getConnectionForTable('tx_rsaauth_keys')
157  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $keyToBeDeleted])
158  ->fetchColumn();
159 
160  $this->assertEquals($this->testKeyRightPart, $key);
161 
162  $this->subject->put(null);
163 
164  $key = GeneralUtility::makeInstance(ConnectionPool::class)
165  ->getConnectionForTable('tx_rsaauth_keys')
166  ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $keyToBeDeleted])
167  ->fetchColumn();
168 
169  $this->assertFalse($key);
170  }
171 }
‪TYPO3\CMS\Rsaauth\Storage\SplitStorage
Definition: SplitStorage.php:28
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\putInsertsKeyIntoDatabase
‪putInsertsKeyIntoDatabase()
Definition: SplitStorageTest.php:85
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\$subject
‪SplitStorage $subject
Definition: SplitStorageTest.php:44
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\getDeletesKeysOlderThan30Minutes
‪getDeletesKeysOlderThan30Minutes()
Definition: SplitStorageTest.php:94
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: SplitStorageTest.php:38
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\setUp
‪setUp()
Definition: SplitStorageTest.php:61
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\$xmlDatabaseFixtures
‪array $xmlDatabaseFixtures
Definition: SplitStorageTest.php:30
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\$testKey
‪string $testKey
Definition: SplitStorageTest.php:48
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\putDeletesCurrentKeyIfNullIsGiven
‪putDeletesCurrentKeyIfNullIsGiven()
Definition: SplitStorageTest.php:144
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage
Definition: SplitStorageTest.php:2
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\$testKeyRightPart
‪string $testKeyRightPart
Definition: SplitStorageTest.php:56
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\getReturnsKeyFromDatabase
‪getReturnsKeyFromDatabase()
Definition: SplitStorageTest.php:76
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest
Definition: SplitStorageTest.php:25
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\putDeletesKeysOlderThan30Minutes
‪putDeletesKeysOlderThan30Minutes()
Definition: SplitStorageTest.php:119
‪TYPO3\CMS\Rsaauth\Tests\Functional\Storage\SplitStorageTest\$testKeyLeftPart
‪string $testKeyLeftPart
Definition: SplitStorageTest.php:52