SecurityTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Settings\Admin;
  24. use OC\Encryption\Manager;
  25. use OC\Settings\Admin\Security;
  26. use OCP\AppFramework\Http\TemplateResponse;
  27. use OCP\IUserManager;
  28. use Test\TestCase;
  29. class SecurityTest extends TestCase {
  30. /** @var Security */
  31. private $admin;
  32. /** @var Manager */
  33. private $manager;
  34. /** @var IUserManager */
  35. private $userManager;
  36. public function setUp() {
  37. parent::setUp();
  38. $this->manager = $this->getMockBuilder('\OC\Encryption\Manager')->disableOriginalConstructor()->getMock();
  39. $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
  40. $this->admin = new Security(
  41. $this->manager,
  42. $this->userManager
  43. );
  44. }
  45. /**
  46. * @return array
  47. */
  48. public function encryptionSettingsProvider() {
  49. return [
  50. [true],
  51. [false],
  52. ];
  53. }
  54. /**
  55. * @dataProvider encryptionSettingsProvider
  56. * @param bool $enabled
  57. */
  58. public function testGetFormWithOnlyOneBackend($enabled) {
  59. $this->manager
  60. ->expects($this->once())
  61. ->method('isEnabled')
  62. ->willReturn($enabled);
  63. $this->manager
  64. ->expects($this->once())
  65. ->method('isReady')
  66. ->willReturn($enabled);
  67. $this->manager
  68. ->expects($this->once())
  69. ->method('getEncryptionModules')
  70. ->willReturn([]);
  71. $this->userManager
  72. ->expects($this->once())
  73. ->method('getBackends')
  74. ->willReturn(['entry']);
  75. $expected = new TemplateResponse(
  76. 'settings',
  77. 'settings/admin/security',
  78. [
  79. 'encryptionEnabled' => $enabled,
  80. 'encryptionReady' => $enabled,
  81. 'externalBackendsEnabled' => false,
  82. 'encryptionModules' => []
  83. ],
  84. ''
  85. );
  86. $this->assertEquals($expected, $this->admin->getForm());
  87. }
  88. /**
  89. * @dataProvider encryptionSettingsProvider
  90. * @param bool $enabled
  91. */
  92. public function testGetFormWithMultipleBackends($enabled) {
  93. $this->manager
  94. ->expects($this->once())
  95. ->method('isEnabled')
  96. ->willReturn($enabled);
  97. $this->manager
  98. ->expects($this->once())
  99. ->method('isReady')
  100. ->willReturn($enabled);
  101. $this->manager
  102. ->expects($this->once())
  103. ->method('getEncryptionModules')
  104. ->willReturn([]);
  105. $this->userManager
  106. ->expects($this->once())
  107. ->method('getBackends')
  108. ->willReturn(['entry', 'entry']);
  109. $expected = new TemplateResponse(
  110. 'settings',
  111. 'settings/admin/security',
  112. [
  113. 'encryptionEnabled' => $enabled,
  114. 'encryptionReady' => $enabled,
  115. 'externalBackendsEnabled' => true,
  116. 'encryptionModules' => []
  117. ],
  118. ''
  119. );
  120. $this->assertEquals($expected, $this->admin->getForm());
  121. }
  122. public function testGetSection() {
  123. $this->assertSame('security', $this->admin->getSection());
  124. }
  125. public function testGetPriority() {
  126. $this->assertSame(10, $this->admin->getPriority());
  127. }
  128. }