Skip to content

Commit

Permalink
fix the ALIBABA_CLOUD_ECS_IMDSV2_ENABLE judge
Browse files Browse the repository at this point in the history
  • Loading branch information
peze authored and yndu13 committed May 10, 2024
1 parent 429bbbe commit 22dc2e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Providers/EcsRamRoleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ public function get()

protected function getEnableECSIMDSv2()
{
$enableIMDSv2 = Helper::envNotEmpty('ALIBABA_CLOUD_ECS_IMDSV2_ENABLE');
if ($enableIMDSv2) {
return strtolower($enableIMDSv2) === 'false' ? false : (bool)$enableIMDSv2;
if (Helper::envNotEmpty('ALIBABA_CLOUD_ECS_IMDSV2_ENABLE')) {
return Helper::env('ALIBABA_CLOUD_ECS_IMDSV2_ENABLE') === true ? true : false;
}
if(isset($this->config['enableIMDSv2'])) {
return $this->config['enableIMDSv2'];
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/EcsRamRoleProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ public function testGetEnableECSIMDSv2()

self::assertEquals(true, $this->invokeProtectedFunc($sessionCredential, 'getEnableECSIMDSv2'));

putenv('ALIBABA_CLOUD_ECS_IMDSV2_ENABLE=TRUE');

self::assertEquals(true, $this->invokeProtectedFunc($sessionCredential, 'getEnableECSIMDSv2'));

putenv('ALIBABA_CLOUD_ECS_IMDSV2_ENABLE=ok');

self::assertEquals(false, $this->invokeProtectedFunc($sessionCredential, 'getEnableECSIMDSv2'));

putenv('ALIBABA_CLOUD_ECS_IMDSV2_ENABLE=1');

self::assertEquals(false, $this->invokeProtectedFunc($sessionCredential, 'getEnableECSIMDSv2'));

putenv('ALIBABA_CLOUD_ECS_IMDSV2_ENABLE=false');

self::assertEquals(false, $this->invokeProtectedFunc($sessionCredential, 'getEnableECSIMDSv2'));
Expand Down

0 comments on commit 22dc2e4

Please sign in to comment.