Example #1
0
 public function Status400TimeGateErrorResponseCommonTests($URIG, $statuscode, $outputfile, $debugfile)
 {
     global $sessionCookieString;
     $uagent = "Memento-Mediawiki-Plugin/Test";
     $curlCmd = "curl -v -s -A '{$uagent}' -b '{$sessionCookieString}' -k -i -H 'Accept-Datetime: bad-input' --url '{$URIG}'";
     $response = `{$curlCmd} 2> {$debugfile} | tee "{$outputfile}"`;
     $statusline = extractStatusLineFromResponse($response);
     $entity = extractEntityFromResponse($response);
     $headers = extractHeadersFromResponse($response);
     $this->assertEquals($statuscode, $statusline["code"]);
     $this->assertArrayHasKey('Vary', $headers);
     $varyItems = extractItemsFromVary($headers['Vary']);
     $this->assertContains('Accept-Datetime', $varyItems, "Accept-Datetime not present in Vary header");
     # To catch any PHP errors that the test didn't notice
     $this->assertFalse(strpos($entity, "<b>Fatal error</b>"));
     # To catch any PHP notices that the test didn't notice
     $this->assertFalse(strpos($entity, "<b>Notice</b>"));
     # To catch any PHP notices that the test didn't notice
     $this->assertFalse(strpos($entity, "<b>Warning</b>"));
     # To ensure that the error message actually exists in the output
     $expected = acquireFormattedI18NString('en', 'timegate-400-date');
     $this->assertStringMatchesFormat("%A" . $expected . "%A", $entity);
 }
Example #2
0
function authenticateWithMediawiki()
{
    global $mwLoginFormUrl;
    global $mwLoginActionUrl;
    global $wpName;
    global $wpPassword;
    global $wpRemember;
    global $wpLoginAttempt;
    global $wpLoginToken;
    global $sessionCookieString;
    global $mwDbName;
    global $HOST;
    $uagent = "Memento-Mediawiki-Plugin/Test";
    $response = `curl -s -e '{$uagent}' -k -i --url '{$mwLoginFormUrl}'`;
    $headers = extractHeadersFromResponse($response);
    $statusline = extractStatuslineFromResponse($response);
    $entity = extractEntityFromResponse($response);
    $cookies = extractCookiesSetInResponse($response);
    $matches = array();
    $pattern = '/\\<input type="hidden" name="wpLoginToken" value="([^"]*)" \\/\\>/';
    preg_match($pattern, $entity, $matches);
    $wpLoginToken = $matches[1];
    $requestEntity = "wpName={$wpName}&wpPassword={$wpPassword}&wpLoginAttempt=Log+in&wpLoginToken={$wpLoginToken}";
    $cookie_session = $cookies["{$mwDbName}_session"];
    $cookies = "{$mwDbName}_session={$cookie_session}";
    $response = `curl -s -i -X POST -d '{$requestEntity}' -H 'Content-Type: application/x-www-form-urlencoded' -b '{$cookies}' --url '{$mwLoginActionUrl}'`;
    $statusline = extractStatuslineFromResponse($response);
    if ($statusline['code'] != "302") {
        echo 'TESTUSERNAME = [' . getenv('TESTUSERNAME') . "]\n";
        echo 'TESTPASSWORD = [' . getenv('TESTPASSWORD') . "]\n";
        echo 'wpName = [' . $wpName . "]\n";
        echo 'wpPassword = [' . $wpPassword . "]\n";
        trigger_error("Authentication failed, check that the TESTUSERNAME and TESTPASSWORD environment variables are set correctly.", E_USER_ERROR);
    }
    $cookies = extractCookiesSetInResponse($response);
    $cookieUserID = $cookies["{$mwDbName}UserID"];
    $cookieUserName = $cookies["{$mwDbName}UserName"];
    $cookieToken = $cookies["{$mwDbName}Token"];
    $cookie_session = $cookies["{$mwDbName}_session"];
    $sessionCookieString = "{$mwDbName}_session={$cookie_session}; {$mwDbName}UserID={$cookieUserID}; {$mwDbName}UserName={$cookieUserName}";
    return $sessionCookieString;
}
Example #3
0
 /**
  * @group all
  *
  * @dataProvider acquireDiffUrls()
  */
 public function testDiffPage($URIR)
 {
     global $sessionCookieString;
     $uagent = "Memento-Mediawiki-Plugin/Test";
     $outputfile = __CLASS__ . '.' . __FUNCTION__ . '.' . self::$instance . '.txt';
     $debugfile = __CLASS__ . '.' . __FUNCTION__ . '-debug-' . self::$instance . '.txt';
     $curlCmd = "curl -v -s -A '{$uagent}' -b '{$sessionCookieString}' -k -i --url \"{$URIR}\"";
     $response = `{$curlCmd} 2> {$debugfile} | tee "{$outputfile}"`;
     $headers = extractHeadersFromResponse($response);
     $statusline = extractStatuslineFromResponse($response);
     $entity = extractEntityFromResponse($response);
     $this->assertEquals($statusline["code"], "200");
     $this->StandardEntityTests($entity, $URIR);
 }