1
0

EmptyFeaturePolicyTest.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace Test\AppFramework\Http;
  25. use OCP\AppFramework\Http\EmptyFeaturePolicy;
  26. class EmptyFeaturePolicyTest extends \Test\TestCase {
  27. /** @var EmptyFeaturePolicy */
  28. private $policy;
  29. protected function setUp(): void {
  30. parent::setUp();
  31. $this->policy = new EmptyFeaturePolicy();
  32. }
  33. public function testGetPolicyDefault() {
  34. $defaultPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'";
  35. $this->assertSame($defaultPolicy, $this->policy->buildPolicy());
  36. }
  37. public function testGetPolicyAutoplayDomainValid() {
  38. $expectedPolicy = "autoplay www.nextcloud.com;camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'";
  39. $this->policy->addAllowedAutoplayDomain('www.nextcloud.com');
  40. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  41. }
  42. public function testGetPolicyAutoplayDomainValidMultiple() {
  43. $expectedPolicy = "autoplay www.nextcloud.com www.nextcloud.org;camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'";
  44. $this->policy->addAllowedAutoplayDomain('www.nextcloud.com');
  45. $this->policy->addAllowedAutoplayDomain('www.nextcloud.org');
  46. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  47. }
  48. public function testGetPolicyCameraDomainValid() {
  49. $expectedPolicy = "autoplay 'none';camera www.nextcloud.com;fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'";
  50. $this->policy->addAllowedCameraDomain('www.nextcloud.com');
  51. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  52. }
  53. public function testGetPolicyCameraDomainValidMultiple() {
  54. $expectedPolicy = "autoplay 'none';camera www.nextcloud.com www.nextcloud.org;fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'";
  55. $this->policy->addAllowedCameraDomain('www.nextcloud.com');
  56. $this->policy->addAllowedCameraDomain('www.nextcloud.org');
  57. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  58. }
  59. public function testGetPolicyFullScreenDomainValid() {
  60. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen www.nextcloud.com;geolocation 'none';microphone 'none';payment 'none'";
  61. $this->policy->addAllowedFullScreenDomain('www.nextcloud.com');
  62. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  63. }
  64. public function testGetPolicyFullScreenDomainValidMultiple() {
  65. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen www.nextcloud.com www.nextcloud.org;geolocation 'none';microphone 'none';payment 'none'";
  66. $this->policy->addAllowedFullScreenDomain('www.nextcloud.com');
  67. $this->policy->addAllowedFullScreenDomain('www.nextcloud.org');
  68. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  69. }
  70. public function testGetPolicyGeoLocationDomainValid() {
  71. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation www.nextcloud.com;microphone 'none';payment 'none'";
  72. $this->policy->addAllowedGeoLocationDomain('www.nextcloud.com');
  73. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  74. }
  75. public function testGetPolicyGeoLocationDomainValidMultiple() {
  76. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation www.nextcloud.com www.nextcloud.org;microphone 'none';payment 'none'";
  77. $this->policy->addAllowedGeoLocationDomain('www.nextcloud.com');
  78. $this->policy->addAllowedGeoLocationDomain('www.nextcloud.org');
  79. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  80. }
  81. public function testGetPolicyMicrophoneDomainValid() {
  82. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone www.nextcloud.com;payment 'none'";
  83. $this->policy->addAllowedMicrophoneDomain('www.nextcloud.com');
  84. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  85. }
  86. public function testGetPolicyMicrophoneDomainValidMultiple() {
  87. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone www.nextcloud.com www.nextcloud.org;payment 'none'";
  88. $this->policy->addAllowedMicrophoneDomain('www.nextcloud.com');
  89. $this->policy->addAllowedMicrophoneDomain('www.nextcloud.org');
  90. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  91. }
  92. public function testGetPolicyPaymentDomainValid() {
  93. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment www.nextcloud.com";
  94. $this->policy->addAllowedPaymentDomain('www.nextcloud.com');
  95. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  96. }
  97. public function testGetPolicyPaymentDomainValidMultiple() {
  98. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment www.nextcloud.com www.nextcloud.org";
  99. $this->policy->addAllowedPaymentDomain('www.nextcloud.com');
  100. $this->policy->addAllowedPaymentDomain('www.nextcloud.org');
  101. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  102. }
  103. }