jenkins-bot has submitted this change and it was merged.
Change subject: Add integration test for MWHttpRequest user/pass options
......................................................................
Add integration test for MWHttpRequest user/pass options
Change-Id: I5bcb263a725e8042ee51109080d2075744fe7001
---
M tests/integration/includes/http/MWHttpRequestTestCase.php
1 file changed, 36 insertions(+), 0 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/integration/includes/http/MWHttpRequestTestCase.php
b/tests/integration/includes/http/MWHttpRequestTestCase.php
index fb52de9..4fd1cde 100644
--- a/tests/integration/includes/http/MWHttpRequestTestCase.php
+++ b/tests/integration/includes/http/MWHttpRequestTestCase.php
@@ -175,8 +175,33 @@
$this->assertArrayHasKey( 'origin', $data );
}
+ public function testBasicAuthentication() {
+ $request = MWHttpRequest::factory(
'http://httpbin.org/basic-auth/user/pass', [
+ 'username' => 'user',
+ 'password' => 'pass',
+ ] );
+ $status = $request->execute();
+ $this->assertTrue( $status->isGood() );
+ $this->assertResponseFieldValue( 'authenticated', true,
$request );
+
+ $request = MWHttpRequest::factory(
'http://httpbin.org/basic-auth/user/pass', [
+ 'username' => 'user',
+ 'password' => 'wrongpass',
+ ] );
+ $status = $request->execute();
+ $this->assertFalse( $status->isOK() );
+ $this->assertSame( 401, $request->getStatus() );
+ }
+
// --------------------
+ /**
+ * Verifies that the request was successful, returned valid JSON and
the given field of that
+ * JSON data is as expected.
+ * @param string|string[] $key Path to the data in the response object
+ * @param mixed $expectedValue
+ * @param MWHttpRequest $response
+ */
protected function assertResponseFieldValue( $key, $expectedValue,
MWHttpRequest $response ) {
$this->assertSame( 200, $response->getStatus(), 'response
status is not 200' );
$data = json_decode( $response->getContent(), true );
@@ -190,6 +215,12 @@
$this->assertSame( $expectedValue, $data );
}
+ /**
+ * Asserts that the cookie jar has the given cookie with the given
value.
+ * @param string $expectedName Cookie name
+ * @param string $expectedValue Cookie value
+ * @param CookieJar $cookieJar
+ */
protected function assertHasCookie( $expectedName, $expectedValue,
CookieJar $cookieJar ) {
$cookieJar = TestingAccessWrapper::newFromObject( $cookieJar );
$cookies = array_change_key_case( $cookieJar->cookie,
CASE_LOWER );
@@ -199,6 +230,11 @@
$this->assertSame( $expectedValue, $cookie->value );
}
+ /**
+ * Asserts that the cookie jar does not have the given cookie.
+ * @param string $expectedName Cookie name
+ * @param CookieJar $cookieJar
+ */
protected function assertNotHasCookie( $name, CookieJar $cookieJar ) {
$cookieJar = TestingAccessWrapper::newFromObject( $cookieJar );
$this->assertArrayNotHasKey( strtolower( $name ),
--
To view, visit https://gerrit.wikimedia.org/r/325136
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5bcb263a725e8042ee51109080d2075744fe7001
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits