MDL-79341 core: more robust testing of user-agent curl response.

The external test file URL concerns itself only with HTTP_USER_AGENT
matching, not sending response headers, which can differ according to
HTTP protocol in use by the endpoint (1.1 vs 2).

Given the returned response code itself is irrelevant to the testcase,
there's not much benefit to asserting it and risking random failures.
This commit is contained in:
Paul Holden
2023-09-13 13:36:28 +01:00
parent d1bc94905e
commit a3ddbca835
+4 -6
View File
@@ -1254,18 +1254,16 @@ EOF;
$this->assertTrue(in_array("User-Agent: $moodlebot", $curl->header));
// Finally, test it via exttests, to ensure the agent is sent properly.
// Matching.
$testurl = $this->getExternalTestFileUrl('/test_agent.php');
$extcurl = new \curl();
// Matching (assert we don't receive an error, and get back the content "OK").
$contents = $extcurl->get($testurl, array(), array('CURLOPT_USERAGENT' => 'AnotherUserAgent/1.2'));
$response = $extcurl->getResponse();
$this->assertSame('200 OK', reset($response));
$this->assertSame(0, $extcurl->get_errno());
$this->assertSame('OK', $contents);
// Not matching.
// Not matching (assert we don't receive an error, and get back empty content - not "OK").
$contents = $extcurl->get($testurl, array(), array('CURLOPT_USERAGENT' => 'NonMatchingUserAgent/1.2'));
$response = $extcurl->getResponse();
$this->assertSame('200 OK', reset($response));
$this->assertSame(0, $extcurl->get_errno());
$this->assertSame('', $contents);
}