Skip to content

Commit

Permalink
bugfix: unserliaze accountid (#2996)
Browse files Browse the repository at this point in the history
Co-authored-by: Sean O'Brien <obrien.sean.dev@gmail.com>
  • Loading branch information
stobrien89 and Sean O'Brien authored Sep 5, 2024
1 parent 986326e commit 88cf178
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changes/nextrelease/creds-unserialize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "bugfix",
"category": "Credentials",
"description": "Fixes issue with unserializing cached credentials without newly added `accountId` property"
}
]
2 changes: 1 addition & 1 deletion src/Credentials/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function __unserialize($data)
$this->secret = $data['secret'];
$this->token = $data['token'];
$this->expires = $data['expires'];
$this->accountId = $data['accountId'];
$this->accountId = $data['accountId'] ?? null;
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Credentials/CredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,23 @@ public function testIsInstanceOfIdentity()
$credentials = new Credentials('key-value', 'secret-value');
$this->assertInstanceOf(AwsCredentialIdentity::class, $credentials);
}

public function testCanUnserializeWithoutAccountId()
{
$oldSerializedData = json_encode([
'key' => 'test-key',
'secret' => 'test-secret',
'token' => 'test-token',
'expires' => time() + 3600
]);

$credentials = new Credentials('foo', 'bar');
$credentials->unserialize($oldSerializedData);

$this->assertEquals('test-key', $credentials->getAccessKeyId());
$this->assertEquals('test-secret', $credentials->getSecretKey());
$this->assertEquals('test-token', $credentials->getSecurityToken());
$this->assertNotNull($credentials->getExpiration());
$this->assertNull($credentials->getAccountId());
}
}

0 comments on commit 88cf178

Please sign in to comment.