aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/api/ApiMessageTest.php
diff options
context:
space:
mode:
authorBrad Jorsch <bjorsch@wikimedia.org>2018-11-07 11:25:40 -0500
committerAnomie <bjorsch@wikimedia.org>2018-11-26 18:41:08 +0000
commit4eace785e66d199cb8fe1ec224bdc49831949a6d (patch)
tree5ee9d1fa57f0c734619b6a486050c6f9e3a976b6 /tests/phpunit/includes/api/ApiMessageTest.php
parent30bd6d78e5edc60e02d42812870d369702971042 (diff)
downloadmediawikicore-4eace785e66d199cb8fe1ec224bdc49831949a6d.tar.gz
mediawikicore-4eace785e66d199cb8fe1ec224bdc49831949a6d.zip
API: Validate API error codes
Validate them in ApiMessageTrait when the message is created, and again in ApiMain before they're included in the header. This also introduces an "api-warning" log channel, since "api" is too spammy for real use, and converts a few existing things to use it. Bug: T208926 Change-Id: Ib2d8bd4d4a5d58af76431835ba783c148de7792a Depends-On: Iced44f2602d57eea9a2d15aee5b8c9a50092b49c Depends-On: I5c2747f527c30ded7a614feb26f5777d901bd512 Depends-On: I9c9bd8f5309518fcbab7179fb71d209c005e5e64
Diffstat (limited to 'tests/phpunit/includes/api/ApiMessageTest.php')
-rw-r--r--tests/phpunit/includes/api/ApiMessageTest.php7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/phpunit/includes/api/ApiMessageTest.php b/tests/phpunit/includes/api/ApiMessageTest.php
index c6f5a8e791f8..70114c2593b6 100644
--- a/tests/phpunit/includes/api/ApiMessageTest.php
+++ b/tests/phpunit/includes/api/ApiMessageTest.php
@@ -38,6 +38,10 @@ class ApiMessageTest extends MediaWikiTestCase {
$msg = new ApiMessage( 'apiwarn-baz' );
$this->assertSame( 'baz', $msg->getApiCode() );
+ // Weird "message key"
+ $msg = new ApiMessage( "<foo> bar\nbaz" );
+ $this->assertSame( '_foo__bar_baz', $msg->getApiCode() );
+
// BC case
$msg = new ApiMessage( 'actionthrottledtext' );
$this->assertSame( 'ratelimited', $msg->getApiCode() );
@@ -72,6 +76,9 @@ class ApiMessageTest extends MediaWikiTestCase {
return [
[ '' ],
[ 42 ],
+ [ 'A bad code' ],
+ [ 'Project:A_page_title' ],
+ [ "WTF\nnewlines" ],
];
}