public function testShouldReturnTokenInfo()
 {
     $wantedTokens = ['access_token' => '1/abdef1234567890', 'expires_in' => '57', 'token_type' => 'Bearer'];
     $jsonTokens = json_encode($wantedTokens);
     $httpHandler = getHandler([buildResponse(200, [GCECredentials::FLAVOR_HEADER => 'Google']), buildResponse(200, [], Psr7\stream_for($jsonTokens))]);
     $g = new GCECredentials();
     $this->assertEquals($wantedTokens, $g->fetchAuthToken($httpHandler));
 }
 public function testSuccedsIfNoDefaultFilesButIsOnGCE()
 {
     $wantedTokens = ['access_token' => '1/abdef1234567890', 'expires_in' => '57', 'token_type' => 'Bearer'];
     $jsonTokens = json_encode($wantedTokens);
     // simulate the response from GCE.
     $httpHandler = getHandler([buildResponse(200, [GCECredentials::FLAVOR_HEADER => 'Google']), buildResponse(200, [], Psr7\stream_for($jsonTokens))]);
     $this->assertNotNull(ApplicationDefaultCredentials::getSubscriber('a scope', $httpHandler));
 }
 public function testUpdatesTokenFieldsOnFetchMissingRefreshToken()
 {
     $testConfig = $this->fetchAuthTokenMinimal;
     $testConfig['refresh_token'] = 'a_refresh_token';
     $wanted_updates = ['expires_at' => '1', 'expires_in' => '57', 'issued_at' => '2', 'access_token' => 'an_access_token', 'id_token' => 'an_id_token'];
     $json = json_encode($wanted_updates);
     $httpHandler = getHandler([buildResponse(200, [], Psr7\stream_for($json))]);
     $o = new OAuth2($testConfig);
     $this->assertNull($o->getExpiresAt());
     $this->assertNull($o->getExpiresIn());
     $this->assertNull($o->getIssuedAt());
     $this->assertNull($o->getAccessToken());
     $this->assertNull($o->getIdToken());
     $this->assertEquals('a_refresh_token', $o->getRefreshToken());
     $tokens = $o->fetchAuthToken($httpHandler);
     $this->assertEquals(1, $o->getExpiresAt());
     $this->assertEquals(57, $o->getExpiresIn());
     $this->assertEquals(2, $o->getIssuedAt());
     $this->assertEquals('an_access_token', $o->getAccessToken());
     $this->assertEquals('an_id_token', $o->getIdToken());
     $this->assertEquals('a_refresh_token', $o->getRefreshToken());
 }
 public function testNoOpOnFetchAuthToken()
 {
     $testJson = $this->createTestJson();
     $sa = new ServiceAccountJwtAccessCredentials($testJson);
     $this->assertNotNull($sa);
     $httpHandler = getHandler([buildResponse(200)]);
     $result = $sa->fetchAuthToken($httpHandler);
     // authUri has not been set
     $this->assertNull($result);
 }
 public function testCanFetchCredsOK()
 {
     $testJson = createURCTestJson();
     $testJsonText = json_encode($testJson);
     $scope = ['scope/1', 'scope/2'];
     $httpHandler = getHandler([buildResponse(200, [], Psr7\stream_for($testJsonText))]);
     $sa = new UserRefreshCredentials($scope, $testJson);
     $tokens = $sa->fetchAuthToken($httpHandler);
     $this->assertEquals($testJson, $tokens);
 }
<?php

require_once '../includes/db.php';
$requestMethod = $_SERVER['REQUEST_METHOD'];
switch ($requestMethod) {
    case 'GET':
        getHandler();
        break;
    case 'POST':
        postHandler();
        break;
        //LOL can't find PUT and DELETE in php docs
        // case 'PUT':
        //     putHandler()
        //     break;
        // case 'DELETE':
        //     deleteHandler()
        //     break;
    //LOL can't find PUT and DELETE in php docs
    // case 'PUT':
    //     putHandler()
    //     break;
    // case 'DELETE':
    //     deleteHandler()
    //     break;
    default:
}
function getHandler()
{
    if (isset($_GET['deleteId'])) {
        //Hack for DELETE
Beispiel #7
0
    return $newJSON;
}
$help = "\nGenerate SQL commands to update keywords column to follow resto v2.2 interface\n";
$help .= "\n USAGE : updateKeywords -u <db user> -p <db password> \n";
$help .= "   OPTIONS:\n";
$help .= "          -u <db user> : Database user name with update rights on resto database\n";
$help .= "          -p <db password> : Database user password\n";
$options = getopt("u:p:h");
foreach ($options as $option => $value) {
    if ($option === "u") {
        $username = $value;
    }
    if ($option === "p") {
        $password = $value;
    }
    if ($option === "h") {
        echo $help;
        exit;
    }
}
if (!isset($username) || !isset($password)) {
    echo $help;
    exit;
}
$dbh = getHandler(array('dbname' => 'resto', 'host' => 'localhost', 'port' => 5432, 'user' => $username, 'password' => $password));
$results = pg_query($dbh, 'SELECT identifier, keywords FROM resto.features ORDER BY identifier');
while ($result = pg_fetch_assoc($results)) {
    $newJSON = upgradeJSON(json_decode($result['keywords'], true));
    echo 'UPDATE resto.features SET keywords=\'' . pg_escape_string(json_encode($newJSON)) . '\' WHERE identifier=\'' . $result['identifier'] . '\';' . "\n";
}
pg_close($dbh);