Skip to content

Commit 0617922

Browse files
authored
Merge pull request #63566 from default50/fix/s3-external-missing-key-warning
fix(files_external): guard optional S3 key in storage id computation
2 parents 5ca65b6 + 63e8e9b commit 0617922

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)