Skip to content

Commit 1079161

Browse files
default50backportbot[bot]
authored andcommitted
fix(files_external): default optional S3 key in parseParams
S3 mounts that authenticate via the AWS SDK default credential chain (env vars, EC2 instance profile, ECS task role) carry no static `key` param. AmazonS3::__construct() read $this->params['key'] unconditionally when deriving the storage id, emitting an "Undefined array key" warning on every storage construction for such mounts. Default `key` to an empty string in S3ConnectionTrait::parseParams(), alongside the other normalized params, so it is always set before the id is derived. The only other reader, paramCredentialProvider(), uses an empty() check that treats '' the same as an absent key, so the SDK default provider chain is still used when no key is configured. Fixes #63564 Assisted-by: Kiro:claude-opus-4.8 Signed-off-by: Sebastian Cruz <default50@gmail.com>
1 parent 980e5ee commit 1079161

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Files_External\Tests\Storage;
10+
11+
use OCA\Files_External\Lib\Storage\AmazonS3;
12+
use Test\TestCase;
13+
14+
/**
15+
* Regression test for the storage id computation in AmazonS3::__construct().
16+
*
17+
* Constructs the storage directly (no live S3 backend) to exercise only the id
18+
* derivation, which runs unconditionally in the constructor.
19+
*/
20+
#[\PHPUnit\Framework\Attributes\Group('S3')]
21+
class Amazons3IdTest extends TestCase {
22+
/**
23+
* Mounts authenticating via the AWS SDK default credential chain (env, EC2
24+
* instance profile, ECS task role) carry no static `key` param. The id must
25+
* still be derivable without emitting an "Undefined array key" warning
26+
* (PHPUnit fails the test on any emitted warning).
27+
*/
28+
public function testConstructWithoutKey(): void {
29+
$storage = new AmazonS3(['bucket' => 'test-bucket']);
30+
$this->assertNotEmpty($storage->getId());
31+
}
32+
}

lib/private/Files/ObjectStore/S3ConnectionTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ protected function parseParams($params) {
6464
$this->retriesMaxAttempts = $params['retriesMaxAttempts'] ?? 5;
6565
$params['region'] = empty($params['region']) ? 'eu-west-1' : $params['region'];
6666
$params['hostname'] = empty($params['hostname']) ? 's3.' . $params['region'] . '.amazonaws.com' : $params['hostname'];
67+
$params['key'] = $params['key'] ?? '';
6768
$params['s3-accelerate'] = $params['hostname'] === 's3-accelerate.amazonaws.com' || $params['hostname'] === 's3-accelerate.dualstack.amazonaws.com';
6869
if (!isset($params['port']) || $params['port'] === '') {
6970
$params['port'] = (isset($params['use_ssl']) && $params['use_ssl'] === false) ? 80 : 443;

0 commit comments

Comments
 (0)