summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/App/AppManagerTest.php33
-rw-r--r--tests/lib/AppFramework/Http/RequestTest.php38
-rw-r--r--tests/lib/Files/Config/UserMountCacheTest.php32
-rw-r--r--tests/lib/NavigationManagerTest.php7
-rw-r--r--tests/lib/User/AvailabilityCoordinatorTest.php16
5 files changed, 97 insertions, 29 deletions
diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php
index 104b0941644..3733d6cd2e9 100644
--- a/tests/lib/App/AppManagerTest.php
+++ b/tests/lib/App/AppManagerTest.php
@@ -660,6 +660,17 @@ class AppManagerTest extends TestCase {
true,
'settings',
],
+ // system default app and user apporder
+ [
+ // system default is settings
+ 'unexist,settings',
+ '',
+ // apporder says default app is files (order is lower)
+ '{"files_id":{"app":"files","order":1},"settings_id":{"app":"settings","order":2}}',
+ true,
+ // system default should override apporder
+ 'settings'
+ ],
// user-customized defaultapp
[
'',
@@ -680,7 +691,7 @@ class AppManagerTest extends TestCase {
[
'unexist,settings',
'files',
- '{"settings":[1],"files":[2]}',
+ '{"settings_id":{"app":"settings","order":1},"files_id":{"app":"files","order":2}}',
true,
'files',
],
@@ -688,18 +699,34 @@ class AppManagerTest extends TestCase {
[
'',
'',
- '{"settings":[1],"files":[2]}',
+ '{"settings_id":{"app":"settings","order":1},"files":{"app":"files","order":2}}',
true,
'settings',
],
+ // user-customized apporder fallback with missing app key (entries added by closures does not always have an app key set (Nextcloud 27 spreed app for example))
+ [
+ '',
+ '',
+ '{"spreed":{"order":1},"files":{"app":"files","order":2}}',
+ true,
+ 'files',
+ ],
// user-customized apporder, but called without fallback
[
'',
'',
- '{"settings":[1],"files":[2]}',
+ '{"settings":{"app":"settings","order":1},"files":{"app":"files","order":2}}',
false,
'',
],
+ // user-customized apporder with an app that has multiple routes
+ [
+ '',
+ '',
+ '{"settings_id":{"app":"settings","order":1},"settings_id_2":{"app":"settings","order":3},"id_files":{"app":"files","order":2}}',
+ true,
+ 'settings',
+ ],
];
}
diff --git a/tests/lib/AppFramework/Http/RequestTest.php b/tests/lib/AppFramework/Http/RequestTest.php
index 0ce2e283bb5..4f53b3d8d5c 100644
--- a/tests/lib/AppFramework/Http/RequestTest.php
+++ b/tests/lib/AppFramework/Http/RequestTest.php
@@ -628,7 +628,33 @@ class RequestTest extends \Test\TestCase {
$this->stream
);
- $this->assertSame('10.4.0.5', $request->getRemoteAddress());
+ $this->assertSame('10.4.0.4', $request->getRemoteAddress());
+ }
+
+ public function testGetRemoteAddressWithMultipleTrustedRemotes() {
+ $this->config
+ ->expects($this->exactly(2))
+ ->method('getSystemValue')
+ ->willReturnMap([
+ ['trusted_proxies', [], ['10.0.0.2', '::1']],
+ ['forwarded_for_headers', ['HTTP_X_FORWARDED_FOR'], ['HTTP_X_FORWARDED']],
+ ]);
+
+ $request = new Request(
+ [
+ 'server' => [
+ 'REMOTE_ADDR' => '10.0.0.2',
+ 'HTTP_X_FORWARDED' => '10.4.0.5, 10.4.0.4, ::1',
+ 'HTTP_X_FORWARDED_FOR' => '192.168.0.233'
+ ],
+ ],
+ $this->requestId,
+ $this->config,
+ $this->csrfTokenManager,
+ $this->stream
+ );
+
+ $this->assertSame('10.4.0.4', $request->getRemoteAddress());
}
public function testGetRemoteAddressIPv6WithSingleTrustedRemote() {
@@ -657,7 +683,7 @@ class RequestTest extends \Test\TestCase {
$this->stream
);
- $this->assertSame('10.4.0.5', $request->getRemoteAddress());
+ $this->assertSame('10.4.0.4', $request->getRemoteAddress());
}
public function testGetRemoteAddressVerifyPriorityHeader() {
@@ -670,9 +696,9 @@ class RequestTest extends \Test\TestCase {
)-> willReturnOnConsecutiveCalls(
['10.0.0.2'],
[
- 'HTTP_CLIENT_IP',
- 'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
+ 'HTTP_X_FORWARDED_FOR',
+ 'HTTP_CLIENT_IP',
],
);
@@ -703,9 +729,9 @@ class RequestTest extends \Test\TestCase {
)-> willReturnOnConsecutiveCalls(
['2001:db8:85a3:8d3:1319:8a2e:370:7348'],
[
- 'HTTP_CLIENT_IP',
+ 'HTTP_X_FORWARDED',
'HTTP_X_FORWARDED_FOR',
- 'HTTP_X_FORWARDED'
+ 'HTTP_CLIENT_IP',
],
);
diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php
index ccad4671ae9..0a9355e9a46 100644
--- a/tests/lib/Files/Config/UserMountCacheTest.php
+++ b/tests/lib/Files/Config/UserMountCacheTest.php
@@ -118,6 +118,10 @@ class UserMountCacheTest extends TestCase {
$this->invokePrivate($this->cache, 'mountsForUsers', [new CappedMemoryCache()]);
}
+ private function keyForMount(MountPoint $mount): string {
+ return $mount->getStorageRootId().'::'.$mount->getMountPoint();
+ }
+
public function testNewMounts() {
$user = $this->userManager->get('u1');
@@ -131,7 +135,7 @@ class UserMountCacheTest extends TestCase {
$cachedMounts = $this->cache->getMountsForUser($user);
$this->assertCount(1, $cachedMounts);
- $cachedMount = $cachedMounts[0];
+ $cachedMount = $cachedMounts[$this->keyForMount($mount)];
$this->assertEquals('/asd/', $cachedMount->getMountPoint());
$this->assertEquals($user, $cachedMount->getUser());
$this->assertEquals($storage->getCache()->getId(''), $cachedMount->getRootId());
@@ -155,7 +159,7 @@ class UserMountCacheTest extends TestCase {
$cachedMounts = $this->cache->getMountsForUser($user);
$this->assertCount(1, $cachedMounts);
- $cachedMount = $cachedMounts[0];
+ $cachedMount = $cachedMounts[$this->keyForMount($mount)];
$this->assertEquals('/asd/', $cachedMount->getMountPoint());
$this->assertEquals($user, $cachedMount->getUser());
$this->assertEquals($storage->getCache()->getId(''), $cachedMount->getRootId());
@@ -200,7 +204,7 @@ class UserMountCacheTest extends TestCase {
$cachedMounts = $this->cache->getMountsForUser($user);
$this->assertCount(1, $cachedMounts);
- $cachedMount = $cachedMounts[0];
+ $cachedMount = $cachedMounts[$this->keyForMount($mount)];
$this->assertEquals('/foo/', $cachedMount->getMountPoint());
}
@@ -223,7 +227,7 @@ class UserMountCacheTest extends TestCase {
$cachedMounts = $this->cache->getMountsForUser($user);
$this->assertCount(1, $cachedMounts);
- $cachedMount = $cachedMounts[0];
+ $cachedMount = $cachedMounts[$this->keyForMount($mount)];
$this->assertEquals(1, $cachedMount->getMountId());
}
@@ -248,15 +252,15 @@ class UserMountCacheTest extends TestCase {
$cachedMounts = $this->cache->getMountsForUser($user1);
$this->assertCount(2, $cachedMounts);
- $this->assertEquals('/foo/', $cachedMounts[0]->getMountPoint());
- $this->assertEquals($user1, $cachedMounts[0]->getUser());
- $this->assertEquals($id1, $cachedMounts[0]->getRootId());
- $this->assertEquals(1, $cachedMounts[0]->getStorageId());
+ $this->assertEquals('/foo/', $cachedMounts[$this->keyForMount($mount1)]->getMountPoint());
+ $this->assertEquals($user1, $cachedMounts[$this->keyForMount($mount1)]->getUser());
+ $this->assertEquals($id1, $cachedMounts[$this->keyForMount($mount1)]->getRootId());
+ $this->assertEquals(1, $cachedMounts[$this->keyForMount($mount1)]->getStorageId());
- $this->assertEquals('/bar/', $cachedMounts[1]->getMountPoint());
- $this->assertEquals($user1, $cachedMounts[1]->getUser());
- $this->assertEquals($id2, $cachedMounts[1]->getRootId());
- $this->assertEquals(2, $cachedMounts[1]->getStorageId());
+ $this->assertEquals('/bar/', $cachedMounts[$this->keyForMount($mount2)]->getMountPoint());
+ $this->assertEquals($user1, $cachedMounts[$this->keyForMount($mount2)]->getUser());
+ $this->assertEquals($id2, $cachedMounts[$this->keyForMount($mount2)]->getRootId());
+ $this->assertEquals(2, $cachedMounts[$this->keyForMount($mount2)]->getStorageId());
$cachedMounts = $this->cache->getMountsForUser($user3);
$this->assertEmpty($cachedMounts);
@@ -521,7 +525,7 @@ class UserMountCacheTest extends TestCase {
$cachedMounts = $this->cache->getMountsForUser($user1);
$this->assertCount(1, $cachedMounts);
- $this->assertEquals('', $cachedMounts[0]->getMountProvider());
+ $this->assertEquals('', $cachedMounts[$this->keyForMount($mount1)]->getMountProvider());
$mount1 = new MountPoint($storage1, '/foo/', null, null, null, null, 'dummy');
$this->cache->registerMounts($user1, [$mount1], ['dummy']);
@@ -530,6 +534,6 @@ class UserMountCacheTest extends TestCase {
$cachedMounts = $this->cache->getMountsForUser($user1);
$this->assertCount(1, $cachedMounts);
- $this->assertEquals('dummy', $cachedMounts[0]->getMountProvider());
+ $this->assertEquals('dummy', $cachedMounts[$this->keyForMount($mount1)]->getMountProvider());
}
}
diff --git a/tests/lib/NavigationManagerTest.php b/tests/lib/NavigationManagerTest.php
index 8edf7ecb9cc..63160e78de7 100644
--- a/tests/lib/NavigationManagerTest.php
+++ b/tests/lib/NavigationManagerTest.php
@@ -365,7 +365,6 @@ class NavigationManagerTest extends TestCase {
'unread' => 0,
'default' => true,
'app' => 'test',
- 'key' => 0,
]],
['logout' => $defaults['logout']]
),
@@ -416,7 +415,6 @@ class NavigationManagerTest extends TestCase {
'unread' => 0,
'default' => false,
'app' => 'test',
- 'key' => 0,
],
'test1' => [
'id' => 'test1',
@@ -430,7 +428,6 @@ class NavigationManagerTest extends TestCase {
'unread' => 0,
'default' => true, // because of order
'app' => 'test',
- 'key' => 1,
]],
['logout' => $defaults['logout']]
),
@@ -458,7 +455,6 @@ class NavigationManagerTest extends TestCase {
'unread' => 0,
'default' => true,
'app' => 'test',
- 'key' => 0,
]],
['logout' => $defaults['logout']]
),
@@ -514,7 +510,6 @@ class NavigationManagerTest extends TestCase {
'unread' => 0,
'default' => true,
'app' => 'test',
- 'key' => 0,
],
];
$navigation = ['navigations' => [
@@ -528,7 +523,7 @@ class NavigationManagerTest extends TestCase {
function (string $userId, string $appName, string $key, mixed $default = '') use ($testOrder) {
$this->assertEquals('user001', $userId);
if ($key === 'apporder') {
- return json_encode(['test' => [$testOrder]]);
+ return json_encode(['test' => ['app' => 'test', 'order' => $testOrder]]);
}
return $default;
}
diff --git a/tests/lib/User/AvailabilityCoordinatorTest.php b/tests/lib/User/AvailabilityCoordinatorTest.php
index 8e847f7e5d5..fd850fcdfd7 100644
--- a/tests/lib/User/AvailabilityCoordinatorTest.php
+++ b/tests/lib/User/AvailabilityCoordinatorTest.php
@@ -32,7 +32,9 @@ use OCA\DAV\Db\Absence;
use OCA\DAV\Db\AbsenceMapper;
use OCP\ICache;
use OCP\ICacheFactory;
+use OCP\IConfig;
use OCP\IUser;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@@ -40,6 +42,7 @@ class AvailabilityCoordinatorTest extends TestCase {
private AvailabilityCoordinator $availabilityCoordinator;
private ICacheFactory $cacheFactory;
private ICache $cache;
+ private IConfig|MockObject $config;
private AbsenceMapper $absenceMapper;
private LoggerInterface $logger;
@@ -49,6 +52,7 @@ class AvailabilityCoordinatorTest extends TestCase {
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->cache = $this->createMock(ICache::class);
$this->absenceMapper = $this->createMock(AbsenceMapper::class);
+ $this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->cacheFactory->expects(self::once())
@@ -58,10 +62,22 @@ class AvailabilityCoordinatorTest extends TestCase {
$this->availabilityCoordinator = new AvailabilityCoordinator(
$this->cacheFactory,
$this->absenceMapper,
+ $this->config,
$this->logger,
);
}
+ public function testIsEnabled(): void {
+ $this->config->expects(self::once())
+ ->method('getAppValue')
+ ->with('dav', 'hide_absence_settings', 'no')
+ ->willReturn('no');
+
+ $isEnabled = $this->availabilityCoordinator->isEnabled();
+
+ self::assertTrue($isEnabled);
+ }
+
public function testGetOutOfOfficeData(): void {
$absence = new Absence();
$absence->setId(420);