‪TYPO3CMS  9.5
CommandLineBackendTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪CommandLineBackendTest extends UnitTestCase
27 {
31  protected ‪$resetSingletonInstances = true;
32 
36  protected function ‪setUp()
37  {
38  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['rsaauth']['temporaryDirectory'] = '';
39  }
40 
45  {
46  $this->‪skipIfWindows();
47  $subject = new ‪CommandLineBackend();
48  $keyPair = $subject->createNewKeyPair();
49  if ($keyPair === null) {
50  $this->markTestSkipped('KeyPair could not be generated. Maybe openssl was not found.');
51  }
52 
53  $this->assertTrue($keyPair->isReady());
54  }
55 
60  {
61  $this->‪skipIfWindows();
62  $subject = new ‪CommandLineBackend();
63  $keyPair = $subject->createNewKeyPair();
64  if ($keyPair === null) {
65  $this->markTestSkipped('KeyPair could not be generated. Maybe openssl was not found.');
66  }
67 
68  $this->assertSame(
70  $keyPair->getExponent()
71  );
72  }
73 
78  {
79  $this->‪skipIfWindows();
80  $subject = new ‪CommandLineBackend();
81  $this->assertSame(
82  $subject->createNewKeyPair(),
83  $subject->createNewKeyPair()
84  );
85  }
86 
90  public function ‪doesNotAllowUnserialization(): void
91  {
92  $this->expectException(\RuntimeException::class);
93  $this->expectExceptionCode(1531336156);
94 
95  $subject = new ‪CommandLineBackend();
96  $serialized = serialize($subject);
97  unserialize($serialized);
98  }
99 
103  public function ‪unsetsPathsOnUnserialization(): void
104  {
105  try {
106  $subject = $this->getAccessibleMock(CommandLineBackend::class);
107  $subject->_set('opensslPath', 'foo');
108  $subject->_set('temporaryDirectory', 'foo');
109  $serialized = serialize($subject);
110  unserialize($serialized);
111  } catch (\RuntimeException $e) {
112  $this->assertNull($subject->_get('opensslPath'));
113  $this->assertNull($subject->_get('temporaryDirectory'));
114  }
115  }
116 
117  protected function ‪skipIfWindows(): void
118  {
120  $this->markTestSkipped(
121  'This test is not available on Windows as auto-detection of openssl path will fail.'
122  );
123  }
124  }
125 }
‪TYPO3\CMS\Rsaauth\Tests\Unit\Backend\CommandLineBackendTest\createNewKeyPairCreatesReadyKeyPair
‪createNewKeyPairCreatesReadyKeyPair()
Definition: CommandLineBackendTest.php:43
‪TYPO3\CMS\Rsaauth\Tests\Unit\Backend
Definition: CommandLineBackendTest.php:4
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static bool isWindows()
Definition: Environment.php:266
‪TYPO3\CMS\Rsaauth\Tests\Unit\Backend\CommandLineBackendTest\doesNotAllowUnserialization
‪doesNotAllowUnserialization()
Definition: CommandLineBackendTest.php:89
‪TYPO3\CMS\Rsaauth\Tests\Unit\Backend\CommandLineBackendTest\skipIfWindows
‪skipIfWindows()
Definition: CommandLineBackendTest.php:116
‪TYPO3\CMS\Rsaauth\Tests\Unit\Backend\CommandLineBackendTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: CommandLineBackendTest.php:30
‪TYPO3\CMS\Rsaauth\Tests\Unit\Backend\CommandLineBackendTest\unsetsPathsOnUnserialization
‪unsetsPathsOnUnserialization()
Definition: CommandLineBackendTest.php:102
‪TYPO3\CMS\Rsaauth\Backend\CommandLineBackend\DEFAULT_EXPONENT
‪const DEFAULT_EXPONENT
Definition: CommandLineBackend.php:33
‪TYPO3\CMS\Rsaauth\Backend\CommandLineBackend
Definition: CommandLineBackend.php:29
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Rsaauth\Tests\Unit\Backend\CommandLineBackendTest\createNewKeyPairCalledTwoTimesReturnsSameKeyPairInstance
‪createNewKeyPairCalledTwoTimesReturnsSameKeyPairInstance()
Definition: CommandLineBackendTest.php:76
‪TYPO3\CMS\Rsaauth\Tests\Unit\Backend\CommandLineBackendTest
Definition: CommandLineBackendTest.php:27
‪TYPO3\CMS\Rsaauth\Tests\Unit\Backend\CommandLineBackendTest\setUp
‪setUp()
Definition: CommandLineBackendTest.php:35
‪TYPO3\CMS\Rsaauth\Tests\Unit\Backend\CommandLineBackendTest\createNewKeyPairCreatesKeyPairWithDefaultExponent
‪createNewKeyPairCreatesKeyPairWithDefaultExponent()
Definition: CommandLineBackendTest.php:58