Skip to content

Commit

Permalink
Merge pull request #189 from google/issue-188
Browse files Browse the repository at this point in the history
Fixes usage of deprecated env var for GAE Flex
  • Loading branch information
Takashi Matsuo authored Apr 6, 2018
2 parents f008253 + 8108a81 commit 79b1fd0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Credentials/GCECredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ public static function getTokenUri()

/**
* Determines if this an App Engine Flexible instance, by accessing the
* GAE_VM environment variable.
* GAE_INSTANCE environment variable.
*
* @return true if this an App Engine Flexible Instance, false otherwise
*/
public static function onAppEngineFlexible()
{
return isset($_SERVER['GAE_VM']) && 'true' === $_SERVER['GAE_VM'];
return substr(getenv('GAE_INSTANCE'), 0, 4) === 'aef-';
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/ApplicationDefaultCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ protected function tearDown()
// removes it if assigned
putenv('HOME=' . $this->originalHome);
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $this->originalServiceAccount);
putenv('GAE_INSTANCE');
}

public function testAppEngineStandard()
Expand All @@ -231,7 +232,7 @@ public function testAppEngineStandard()
public function testAppEngineFlexible()
{
$_SERVER['SERVER_SOFTWARE'] = 'Google App Engine';
$_SERVER['GAE_VM'] = 'true';
putenv('GAE_INSTANCE=aef-default-20180313t154438');
$httpHandler = getHandler([
buildResponse(200, [GCECredentials::FLAVOR_HEADER => 'Google']),
]);
Expand Down
10 changes: 8 additions & 2 deletions tests/Credentials/GCECredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ public function testIsFalseByDefault()
$this->assertFalse(GCECredentials::onAppEngineFlexible());
}

public function testIsTrueWhenGaeVmIsTrue()
public function testIsTrueWhenGaeInstanceHasAefPrefix()
{
$_SERVER['GAE_VM'] = 'true';
putenv('GAE_INSTANCE=aef-default-20180313t154438');
$this->assertTrue(GCECredentials::onAppEngineFlexible());
}

protected function tearDown()
{
// removes it if assigned
putenv('GAE_INSTANCE');
}
}

class GCECredentialsGetCacheKeyTest extends TestCase
Expand Down

0 comments on commit 79b1fd0

Please sign in to comment.