From a3ddbca8352ed70d475017013f907fe68c9da536 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 13 Sep 2023 13:30:52 +0100 Subject: [PATCH] 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. --- lib/tests/filelib_test.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/tests/filelib_test.php b/lib/tests/filelib_test.php index 9685e9a3db3..1e6198429d0 100644 --- a/lib/tests/filelib_test.php +++ b/lib/tests/filelib_test.php @@ -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); }