Skip to content

Commit ff7ece6

Browse files
authored
fix: undefined index error in cache trait (#617)
1 parent d6389aa commit ff7ece6

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/CacheTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private function getFullCacheKey($key)
9595
return null;
9696
}
9797

98-
$key = $this->cacheConfig['prefix'] . $key;
98+
$key = ($this->cacheConfig['prefix'] ?? '') . $key;
9999

100100
// ensure we do not have illegal characters
101101
$key = preg_replace('|[^a-zA-Z0-9_\.!]|', '', $key);

src/CredentialSource/AwsNativeSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ private static function hmacSign(string $key, string $msg): string
356356
*/
357357
private static function utf8Encode(string $string): string
358358
{
359-
return mb_convert_encoding($string, 'UTF-8', 'ISO-8859-1');
359+
return (string) mb_convert_encoding($string, 'UTF-8', 'ISO-8859-1');
360360
}
361361

362362
private static function getSignatureKey(

tests/Credentials/ImpersonatedServiceAccountCredentialsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ public function testGetServiceAccountNameID()
9898
$this->assertEquals('1234567890987654321', $creds->getClientName());
9999
}
100100

101+
public function testGetCacheKey()
102+
{
103+
$creds = new ImpersonatedServiceAccountCredentials(self::SCOPE, [
104+
'service_account_impersonation_url' => 'foo',
105+
'source_credentials' => [
106+
'type' => 'service_account',
107+
'client_email' => '123',
108+
'private_key' => 'abc'
109+
]
110+
]);
111+
$this->assertEquals('foo123.scope1scope2', $creds->getCacheKey());
112+
}
113+
101114
public function testMissingImpersonationUriThrowsException()
102115
{
103116
$this->expectException(LogicException::class);

0 commit comments

Comments
 (0)