Skip to content

Commit

Permalink
ensures onAppEngine returns true on Dev AppServer (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored Sep 29, 2017
1 parent dc59009 commit 1d66066
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Credentials/AppIdentityCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,25 @@ public function __construct($scope = array())
}

/**
* Determines if this an App Engine instance, by accessing the SERVER_SOFTWARE
* environment variable.
* Determines if this an App Engine instance, by accessing the
* SERVER_SOFTWARE environment variable (prod) or the APPENGINE_RUNTIME
* environment variable (dev).
*
* @return true if this an App Engine Instance, false otherwise
*/
public static function onAppEngine()
{
return isset($_SERVER['SERVER_SOFTWARE']) &&
strpos($_SERVER['SERVER_SOFTWARE'], 'Google App Engine') !== false;
$appEngineProduction = isset($_SERVER['SERVER_SOFTWARE']) &&
0 === strpos($_SERVER['SERVER_SOFTWARE'], 'Google App Engine');
if ($appEngineProduction) {
return true;
}
$appEngineDevAppServer = isset($_SERVER['APPENGINE_RUNTIME']) &&
$_SERVER['APPENGINE_RUNTIME'] == 'php';
if ($appEngineDevAppServer) {
return true;
}
return false;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Credentials/AppIndentityCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public function testIsTrueWhenServerSoftwareIsGoogleAppEngine()
$_SERVER['SERVER_SOFTWARE'] = 'Google App Engine';
$this->assertTrue(AppIdentityCredentials::onAppEngine());
}

public function testIsTrueWhenAppEngineRuntimeIsPhp()
{
$_SERVER['APPENGINE_RUNTIME'] = 'php';
$this->assertTrue(AppIdentityCredentials::onAppEngine());
}
}

class AppIdentityCredentialsGetCacheKeyTest extends \PHPUnit_Framework_TestCase
Expand Down

0 comments on commit 1d66066

Please sign in to comment.