[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / rsaauth / Tests / Functional / Storage / SplitStorageTest.php
1 <?php
2 namespace TYPO3\CMS\Rsaauth\Tests\Functional\Storage;
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
17 use TYPO3\CMS\Core\Database\ConnectionPool;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Rsaauth\Storage\SplitStorage;
20
21 /**
22 * Test case.
23 */
24 class SplitStorageTest extends \TYPO3\Components\TestingFramework\Core\Functional\FunctionalTestCase
25 {
26 /**
27 * XML database fixtures to be loaded into database.
28 *
29 * @var array
30 */
31 protected $xmlDatabaseFixtures = [
32 'typo3/sysext/rsaauth/Tests/Functional/Fixtures/tx_rsaauth_keys.xml'
33 ];
34
35 /**
36 * Core extensions to load
37 *
38 * @var array
39 */
40 protected $testExtensionsToLoad = [
41 'typo3/sysext/rsaauth'
42 ];
43
44 /**
45 * @var SplitStorage
46 */
47 protected $subject;
48
49 /**
50 * @var string
51 */
52 protected $testKey = '666cb6d79dc65973df67571bbdc5beca';
53
54 /**
55 * @var string
56 */
57 protected $testKeyLeftPart = '666cb6d79dc65973';
58
59 /**
60 * @var string
61 */
62 protected $testKeyRightPart = 'df67571bbdc5beca';
63
64 /**
65 * Sets up this test suite.
66 *
67 * @return void
68 */
69 protected function setUp()
70 {
71 parent::setUp();
72 foreach ($this->xmlDatabaseFixtures as $fixture) {
73 $this->importDataSet($fixture);
74 }
75 $this->subject = GeneralUtility::makeInstance(SplitStorage::class);
76 // same timestamp as in Fixtures/tx_rsaauth_keys.xml
77 $GLOBALS['EXEC_TIME'] = 1465391843;
78 $_SESSION['tx_rsaauth_key'] = [1, $this->testKeyLeftPart];
79 }
80
81 /**
82 * @test
83 */
84 public function getReturnsKeyFromDatabase()
85 {
86 $key = $this->subject->get();
87 $this->assertEquals($this->testKey, $key);
88 }
89
90 /**
91 * @test
92 */
93 public function putInsertsKeyIntoDatabase()
94 {
95 $this->subject->put($this->testKey);
96 $this->assertEquals($this->testKey, $this->subject->get());
97 }
98
99 /**
100 * @test
101 */
102 public function getDeletesKeysOlderThan30Minutes()
103 {
104 $outDatedKeyId = 3;
105 $_SESSION['tx_rsaauth_key'] = [1, $this->testKeyLeftPart];
106
107 $key = GeneralUtility::makeInstance(ConnectionPool::class)
108 ->getConnectionForTable('tx_rsaauth_keys')
109 ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
110 ->fetchColumn();
111
112 $this->assertEquals($this->testKeyRightPart, $key);
113
114 $this->subject->get();
115
116 $key = GeneralUtility::makeInstance(ConnectionPool::class)
117 ->getConnectionForTable('tx_rsaauth_keys')
118 ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
119 ->fetchColumn();
120
121 $this->assertFalse($key);
122 }
123
124 /**
125 * @test
126 */
127 public function putDeletesKeysOlderThan30Minutes()
128 {
129 $outDatedKeyId = 3;
130 $_SESSION['tx_rsaauth_key'] = [1, $this->testKeyLeftPart];
131
132 $key = GeneralUtility::makeInstance(ConnectionPool::class)
133 ->getConnectionForTable('tx_rsaauth_keys')
134 ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
135 ->fetchColumn();
136
137 $this->assertEquals($this->testKeyRightPart, $key);
138
139 $this->subject->put('testkey');
140
141 $key = GeneralUtility::makeInstance(ConnectionPool::class)
142 ->getConnectionForTable('tx_rsaauth_keys')
143 ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $outDatedKeyId])
144 ->fetchColumn();
145
146 $this->assertFalse($key);
147 }
148
149 /**
150 * @test
151 */
152 public function putDeletesCurrentKeyIfNullIsGiven()
153 {
154 $keyToBeDeleted = 1;
155 $_SESSION['tx_rsaauth_key'] = [$keyToBeDeleted, $this->testKeyLeftPart];
156
157 $key = GeneralUtility::makeInstance(ConnectionPool::class)
158 ->getConnectionForTable('tx_rsaauth_keys')
159 ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $keyToBeDeleted])
160 ->fetchColumn();
161
162 $this->assertEquals($this->testKeyRightPart, $key);
163
164 $this->subject->put(null);
165
166 $key = GeneralUtility::makeInstance(ConnectionPool::class)
167 ->getConnectionForTable('tx_rsaauth_keys')
168 ->select(['key_value'], 'tx_rsaauth_keys', ['uid' => $keyToBeDeleted])
169 ->fetchColumn();
170
171 $this->assertFalse($key);
172 }
173 }