From 159a131989d5a12c9ab81e8adfbd267ac03516a6 Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Fri, 5 May 2023 10:18:51 +0800 Subject: [PATCH] MDL-77990 enrol_lti: test covering the response header parsing Makes sure the http_client shim properly returns the correct, final http headers, not intermediate headers such as 302, 100 etc. --- .../local/ltiadvantage/lib/http_client_test.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/enrol/lti/tests/local/ltiadvantage/lib/http_client_test.php b/enrol/lti/tests/local/ltiadvantage/lib/http_client_test.php index 392f57d534eb7..578e11a14f723 100644 --- a/enrol/lti/tests/local/ltiadvantage/lib/http_client_test.php +++ b/enrol/lti/tests/local/ltiadvantage/lib/http_client_test.php @@ -24,7 +24,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @coversDefaultClass \enrol_lti\local\ltiadvantage\lib\http_client */ -class http_client_test extends \basic_testcase { +class http_client_test extends \advanced_testcase { /** * Verify the http_client delegates to curl during a "GET" request. @@ -116,4 +116,17 @@ public function unsupported_methods_provider() { 'delete' => ['DELETE'], ]; } + + /** + * Verify that the response headers are properly read from curl, and exclude things like redirect headers, or 100-continues. + * @covers ::request + */ + public function test_header_parsing(): void { + $testurl = $this->getExternalTestFileUrl('/test_redir.php'); + $client = new http_client(new \curl()); + $response = $client->request('POST', "$testurl?redir=1", + ['headers' => ['Expect' => '100-continue'], 'body' => 'foo']); + $headers = $response->getHeaders(); + $this->assertEquals('200 OK', reset($headers)); + } }