1
0

EmptyFeaturePolicyTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\AppFramework\Http;
  8. use OCP\AppFramework\Http\EmptyFeaturePolicy;
  9. class EmptyFeaturePolicyTest extends \Test\TestCase {
  10. /** @var EmptyFeaturePolicy */
  11. private $policy;
  12. protected function setUp(): void {
  13. parent::setUp();
  14. $this->policy = new EmptyFeaturePolicy();
  15. }
  16. public function testGetPolicyDefault(): void {
  17. $defaultPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'";
  18. $this->assertSame($defaultPolicy, $this->policy->buildPolicy());
  19. }
  20. public function testGetPolicyAutoplayDomainValid(): void {
  21. $expectedPolicy = "autoplay www.nextcloud.com;camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'";
  22. $this->policy->addAllowedAutoplayDomain('www.nextcloud.com');
  23. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  24. }
  25. public function testGetPolicyAutoplayDomainValidMultiple(): void {
  26. $expectedPolicy = "autoplay www.nextcloud.com www.nextcloud.org;camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'";
  27. $this->policy->addAllowedAutoplayDomain('www.nextcloud.com');
  28. $this->policy->addAllowedAutoplayDomain('www.nextcloud.org');
  29. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  30. }
  31. public function testGetPolicyCameraDomainValid(): void {
  32. $expectedPolicy = "autoplay 'none';camera www.nextcloud.com;fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'";
  33. $this->policy->addAllowedCameraDomain('www.nextcloud.com');
  34. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  35. }
  36. public function testGetPolicyCameraDomainValidMultiple(): void {
  37. $expectedPolicy = "autoplay 'none';camera www.nextcloud.com www.nextcloud.org;fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'";
  38. $this->policy->addAllowedCameraDomain('www.nextcloud.com');
  39. $this->policy->addAllowedCameraDomain('www.nextcloud.org');
  40. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  41. }
  42. public function testGetPolicyFullScreenDomainValid(): void {
  43. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen www.nextcloud.com;geolocation 'none';microphone 'none';payment 'none'";
  44. $this->policy->addAllowedFullScreenDomain('www.nextcloud.com');
  45. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  46. }
  47. public function testGetPolicyFullScreenDomainValidMultiple(): void {
  48. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen www.nextcloud.com www.nextcloud.org;geolocation 'none';microphone 'none';payment 'none'";
  49. $this->policy->addAllowedFullScreenDomain('www.nextcloud.com');
  50. $this->policy->addAllowedFullScreenDomain('www.nextcloud.org');
  51. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  52. }
  53. public function testGetPolicyGeoLocationDomainValid(): void {
  54. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation www.nextcloud.com;microphone 'none';payment 'none'";
  55. $this->policy->addAllowedGeoLocationDomain('www.nextcloud.com');
  56. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  57. }
  58. public function testGetPolicyGeoLocationDomainValidMultiple(): void {
  59. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation www.nextcloud.com www.nextcloud.org;microphone 'none';payment 'none'";
  60. $this->policy->addAllowedGeoLocationDomain('www.nextcloud.com');
  61. $this->policy->addAllowedGeoLocationDomain('www.nextcloud.org');
  62. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  63. }
  64. public function testGetPolicyMicrophoneDomainValid(): void {
  65. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone www.nextcloud.com;payment 'none'";
  66. $this->policy->addAllowedMicrophoneDomain('www.nextcloud.com');
  67. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  68. }
  69. public function testGetPolicyMicrophoneDomainValidMultiple(): void {
  70. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone www.nextcloud.com www.nextcloud.org;payment 'none'";
  71. $this->policy->addAllowedMicrophoneDomain('www.nextcloud.com');
  72. $this->policy->addAllowedMicrophoneDomain('www.nextcloud.org');
  73. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  74. }
  75. public function testGetPolicyPaymentDomainValid(): void {
  76. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment www.nextcloud.com";
  77. $this->policy->addAllowedPaymentDomain('www.nextcloud.com');
  78. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  79. }
  80. public function testGetPolicyPaymentDomainValidMultiple(): void {
  81. $expectedPolicy = "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment www.nextcloud.com www.nextcloud.org";
  82. $this->policy->addAllowedPaymentDomain('www.nextcloud.com');
  83. $this->policy->addAllowedPaymentDomain('www.nextcloud.org');
  84. $this->assertSame($expectedPolicy, $this->policy->buildPolicy());
  85. }
  86. }