Commit graph

187 commits

Author SHA1 Message Date
Amir Sarabadani 5be8a76d0f Reduce CPU timeout time in testTimeLimit
This makes these tests the slowest ones to run

Change-Id: Ibfb021d63432f556d1eb5de31341a5bc64d76a85
2019-07-23 14:47:14 +00:00
Brad Jorsch 88be4ec461 LuaInterpreterTest: Limit the busy loop
The test currently runs a busy loop that does string operations 1
billion times, when really it just needs something that takes more than
2 seconds of CPU time. On the other hand, there's another test that uses
the same method to run only 100 string operations for a different test.

Add a second parameter to have it exit early if enough CPU time has been
used, and use it in the first test.

Bug: T220685
Change-Id: I32309f049bcfb2e1310651818ff8674f0a311f40
2019-06-20 12:11:40 -04:00
Brad Jorsch 2e79d0a719 mw.uri: Support IP-Literal syntax
RFC 3986 allows IPv6 literals (and future IP versions) by having the
"host" enclosed in brackets, like `http://[2001:db8::]`. mw.uri should
handle these appropriately.

Bug: T223267
Change-Id: I6f712b87bc376cf606c6c2ebbe80176037d6dddb
2019-05-19 07:55:29 +00:00
Kunal Mehta 8328acb9b1 Upgrade to newer phan
Bug: T216940
Change-Id: If8c2027f6bb7b91504fb51a3d2668b6d929b5da1
2019-03-20 21:19:37 -07:00
Arlo Breault cd9de940eb Update tests to match parser changes
Bug: T208070
Bug: T218702
Depends-On: I8b6a8c8241a8766fdccdcac45553298fa23a5046
Change-Id: I15c81a2c15311406b643fee5ec0ae597c1887b3f
2019-03-19 13:38:48 -04:00
MGChecker 4bc7abb0ac Set "TemplateSandboxEditNamespaces" in extension.json
If TemplateStyles installed, then enable it in the Module namespace
by default. This change is analogous to I96d9601ff80c2d3eb052c01.

Since both extensions use the ContentHandlerDefaultModelFor hook, Scribunto
will check if the sanitized-css model has already been set, and if so, not
override it. If the page is in NS_MODULE, it will set the content model to
Scribunto, but allow further hooks to override it, in which case it is
expected that TemplateStyles would set it to sanitized-css.

Bug: T200914
Depends-On: I2fa9b822ee39bcc5f95a293c8c4aad4d53ede30a
Change-Id: I7a9b445accde35e4a5e7d13100c646f211d21afe
2019-01-15 09:39:30 -08:00
Kunal Mehta 3b0082e6b2 Add test for ScribuntoHooks::contentHandlerDefaultModelFor()
Change-Id: Ibce964bb308aa88b14a179310436db9c48640f76
2019-01-14 17:36:52 +00:00
Brad Jorsch ec103b6966 Scribunto_LuaError: Make ->getMessage() return UTF-8 text
It's easily possible for Lua to raise errors where the string is not
valid UTF-8. When we turn that into a Scribunto_LuaError, we should
normalize it so other things don't break.

Bug: T208689
Change-Id: Idc5514261e99d64222b86877dd0500d425a26988
2018-12-11 14:46:56 -05:00
Marius Hoch ab15dfe4ff Make sure interface functions with the same name don't clash
Test case (greatly simplified) by Anomie.

Bug: T211203
Change-Id: Id05c226b80343b1c333ae622d7390a96ff88ea99
2018-12-06 08:15:43 +01:00
Lucas Werkmeister (WMDE) a55cfc2078 Revert "Adding a unit test for CVE-2014-5461 in Scribunto."
This test causes spurious CI failures in other projects; to unblock them
for now, remove the test again until we can figure out how to make it
work better.

This reverts commit 7a7f522676.

Bug: T209232
Change-Id: Id2eeeb781b7a8a6298ba06d78bab238b37dac9ca
2018-11-30 14:14:40 +00:00
Mogmog123 7a7f522676 Adding a unit test for CVE-2014-5461 in Scribunto.
Bug: T209232
Change-Id: I84a4ec014875764bcba4d603b0e27d210d4a9308
2018-11-26 20:36:45 +00:00
Umherirrender 55bd9d22bb Add method scope visibility
Change-Id: I2efe0f71266d70e9a41e044406d82ef7daa31296
2018-11-19 21:18:12 +00:00
Brad Jorsch 18c08c23fc ustring: Match undocumented string.gsub behavior
As documented, string.gub( 'foo', '%a', '%1' ) should raise an invalid
capture index error because there is no capture with index 1 in the
pattern. But in fact it treats %1 as %0 in this situation. The ustring
library should match this behavior.

This patch also adds some tests for the behavior of gsub with table and
function replacements when the pattern does have captures.

Bug: T207623
Change-Id: Ie3e6c2eafa4a05989815c62c7037167642581751
2018-11-01 03:59:35 +00:00
libraryupgrader 8b489ca160 build: Updating mediawiki/mediawiki-codesniffer to 22.0.0
And updating CoC link to use Special:MyLanguage (T202047).

Change-Id: I091003f69b82c7cacc4cda320a38b1b07f3cdb6b
2018-09-03 21:33:35 +00:00
Max Semenik eb8ccf03db Get rid of call_user_func_array()
Yay PHP7!

Change-Id: I777ed78d22efbddacaab22c4614a0defa6ad3f94
2018-07-03 19:40:19 -07:00
Kunal Mehta d91a8cf8a0 Add @covers tags to all tests
Bug: T195160
Change-Id: I77ce544e9c166fef6c6fb02f67d1de6ddf0c2465
2018-05-29 11:37:27 -07:00
Kunal Mehta f76ba3c465 Disable Squiz.Classes.ValidClassName.NotCamelCaps globally
Instead of per-file. This happens to also fix a false positive with the
PhpunitAnnotations sniff.

Change-Id: I22621c37217ed2db9d8b3591df1a1421c25fa7f6
2018-05-24 22:26:11 -07:00
Brad Jorsch 32718af677 ustring: Handle invalid types in gsub
If the replacement table or function results in a value that isn't a
string or number (or nil), string.gsub raises an error. Have ustring
raise the same error.

Bug: T195326
Change-Id: Ic36f9f5d7adc0c14e7a4a94d3747335107acd8b6
2018-05-22 18:55:49 -04:00
Kunal Mehta d245edbb94 Add phan configuration
Manually import LuaSandbox's git repository as a composer dependency to
provide the PHP stubs for phan.

Change-Id: I6226b9211f31d829da5a2775c6f5cf3599dd8ebc
2018-05-14 18:41:59 -07:00
Jayprakash12345 7da38c8e10 Update extensions to take advantage of parser test autodiscovery
Bug: T170037
Change-Id: Ifeffbf7a27dfd4915998159617d37d4d9b9a1c17
2018-04-13 15:07:17 +00:00
Umherirrender 44fe3df9bf Rename test classes to end with Test
Change-Id: I510e5516d56b28d26510423da840b4b496a10833
2018-03-10 14:25:38 +01:00
Kunal Mehta 27a7eb0f58 Use namespaced PHPUnit\Framework\TestCase
For future compatibility with PHPUnit 6.

Bug: T188166
Change-Id: Id1e951d7e9a2092500408ab865427db45c025bde
2018-02-24 00:23:15 -08:00
libraryupgrader 6d1a6ffb01 build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
The following sniffs are failing and were disabled:
* MediaWiki.Commenting.MissingCovers.MissingCovers

Change-Id: I07b2cf945f44fd5532812a712f7dd40d2f208be2
2018-02-15 13:57:18 +00:00
Brad Jorsch 790311faa3 Sanify handling of array keys
When passing an array from PHP to Lua, stringify integer array keys
beyond the range a lua_Number can represent.

When passing a table from Lua to PHP,
* Avoid exponential encoding for integer keys beyond 1e14, so Zend PHP
  will interpret them as integers.
* Always encode integer keys as integers, so HHVM will interpret them as
  integers.
* Detect collisions, e.g. { [0] = 'foo', ["0"] = 'bar' }

Bug: T186240
Change-Id: I078068ed57df078248a307608381614bdfc70801
2018-02-06 17:13:20 -05:00
Kunal Mehta ec7b1b05cf Fix Scribunto_LuaStandaloneInterpreterTest::testGetStatus on 7.1+
The extraneous whitespace in the return value from wfShellExec() causes
multiplying $size to trigger the newly introduced "A non well formed
numeric value encountered" warning in PHP 7.1+.

Work around that by using trim() to get rid of the whitespace.

Bug: T186299
Change-Id: I3d47ef6cc7fb99b4d4840dc847d150c3939ee535
2018-02-01 21:08:32 -08:00
jenkins-bot 252d117fdd Merge "Improve some parameter docs" 2018-01-16 16:21:51 +00:00
Umherirrender cfbd0a1a1b Improve some parameter docs
Change-Id: Ic85f74fc8dcefe86a3620e2d12f0b2ad2386ee23
2018-01-11 21:27:53 +01:00
Kunal Mehta 76dbe5d804 Treat phpdbg as being run from the command-line
The two lualib/ustring generation scripts run independently of MediaWiki, so
the new wfIsCLI() isn't usable there.

Bug: T184043
Change-Id: I217657d12e16a7b76dc814be5fed03540c461e7c
2018-01-10 19:47:19 +05:30
Marius Hoch 12acfa95ef Make Scribunto_LuaSandboxTests::testArgumentParsingTime more robust
This should make sure the tests still work, even if the running
node is heavily overloaded.

Bug: T143389
Change-Id: Ic40c8d76c8799c2e9d11f53945276747c199fd02
2017-10-10 10:38:23 +02:00
Brad Jorsch 9fefb11d56 Replace uses of each()
It's deprecated in PHP 7.2, may as well replace it now.

Bug: T174354
Change-Id: I2c37229d69a9646edaa61e25e28b13e8190a8359
2017-09-19 16:46:51 -04:00
Brad Jorsch 7418a571ac Fix tests
Iaa880531 added extra frames in the call stack, so the frame being
tested by the "setfenv invalid level" and "getfenv invalid level" tests
was no longer invalid.

Bug: T175065
Change-Id: Id1028e7c8bbb92fb9d7d01ebeabd94e8ba284b1c
2017-09-05 15:44:55 -04:00
Brad Jorsch ca85f20099 Make mw.uri.encode 'WIKI' mode match core {{urlencode:}}
The core {{urlencode:}} parser function doesn't encode various
characters in WIKI mode that it does in other modes. mw.uri.encode
should match that.

Bug: T174239
Change-Id: I2be0811cf39c02c5c0ad3433e4b0ef9030350e24
2017-08-28 10:34:16 -04:00
Kunal Mehta b8ff734aa4 Use namespaced ScopedCallback
The non-namespaced version is deprecated since 1.28

Change-Id: Icb3fed78882913a26aad4bdb1a84cb5a3e8ca6bb
2017-08-21 14:06:34 -07:00
WMDE-Fisch e1763ff69a Updating mediawiki-codesniffer to 0.10.1 and fix issues
Change-Id: Iac61e49ab0f1318fcb7b23b4c90b6a427fe8957f
2017-07-25 17:16:47 +00:00
Umherirrender 18b22b3a3d build: Updating mediawiki/mediawiki-codesniffer to 0.10.0
Change-Id: I92b9fb936cb8fa8411850b97804e2aacf3984322
2017-07-08 15:42:23 +02:00
Kunal Mehta 31820c673a Move tests into tests/phpunit and remove UnitTestsList hook
This takes advantage of extension.json's unit tests autodiscovery
mechanism.

Bug: T142120
Change-Id: Id526f3368fc73ba7e6ef1d793ea70ab05fbd9517
2017-07-07 13:50:39 -07:00
Umherirrender 4abed1d7c7 Use short array syntax
Done by phpcbf over composer fix

Change-Id: I9b7419e025ef499ff68be79789d76ad4b886d256
2017-06-16 13:26:30 +00:00
Tim Starling 0cf603ca9d Make the maximum language cache size configurable
Make the language cache size configurable, and increase the default from
20 to 30. It needs to be fairly small on default installations, but can
be essentially unlimited if $wgLocalisationCacheConf['manualRecache'] is
true.

Bug: T85461
Change-Id: Idb17691b30b0d2565a1624e5159df7d9b795764d
2017-03-23 15:24:00 +11:00
Brad Jorsch 7f94d88733 LuaStandalone: Fix signal handling
I252ec046 noticeably broke things by adding a dependency on the pcntl
functions, which tend not to be present under Apache.

It also subtly broke exit handling by using proc_close()'s return value,
which PHP mangles in such a way that we can't tell the difference
between an actual XCPU kill and exit( SIGXCPU ). This one wasn't noticed
because the pcntl functions interpret everything proc_close() is going
to return as a signal kill and we didn't test the 'exited' code path.

I'm not sure what was going on in I57cdf8aa since it provides no details
about what it was trying to fix, but that would have broken signal
handling in the other way: Ibf5f4656 worked because proc_open() on Linux
executes the command by passing it to /bin/sh -c, and that shell is
going to turn any signal that kills Lua (e.g. the SIGXCPU) into an exit
status of 128+signum.

To avoid proc_close()'s broken return value while also avoiding the
race, we can loop on proc_get_status() until $status['running'] is
false.

To have signals that kill Lua actually be interpreted as signals, we
have two options: add an "exec" in front of the command so proc_open()'s
/bin/sh -c is execed away, or detect shell-style signal reporting and
convert it. We may as well do both.

Bug: T128048
Change-Id: I8a62e1660fe1694e9ba5de77d01960c1ab4580aa
2017-03-09 23:16:28 +00:00
Antoine Musso 1cf6339a1b test: change interwiki to a meaningful name
When investigating a test failure on T155600 I found the title
'scribuntotitletest:Module:TestFramework' to be rather obscure.  Had to
browse the code to findout 'scribuntotitletest' is an interwiki prefix.

Update TitleLibraryTest php/lua and change the interwiki prefix to the
more meaningful 'interwikiprefix'.

Bug: T155600
Change-Id: Iec63734c82b0835a7f2444ea9af35617876831d5
2017-01-19 09:48:55 +01:00
jenkins-bot ae677fbc0d Merge "Ustring: Let gcodepoint work with moderately long strings" 2016-12-16 00:42:02 +00:00
Brad Jorsch db07787390 Cleanup backwards-compatibility code
https://www.mediawiki.org/wiki/Extension:Scribunto says that master
requires 1.25+, so let's remove checks for stuff that was added before
that.

* PPFrame::getTTL() was in 1.24.
* PPFrame::setTTL() was in 1.24.
* PPFrame::isVolatile() was in 1.24.
* Parser::fetchCurrentRevisionOfTitle() was in 1.24.
* ObjectCache::getLocalServerInstance() was added in 1.27, so restore the call to ObjectCache::newAccelerator() as BC.

This also removes BC with the php-luasandbox extension older than 1.6, which
was released before MediaWiki 1.22.

Bug: T148012
Change-Id: I36e37f3b65d0f167e1d28b00e0842d9721feee31
2016-10-13 11:07:44 -04:00
Brad Jorsch 629f11d0dd Fix pure-Lua ustring and empty patterns
An empty pattern isn't "safe" since it could match in between the
bytes of a UTF-8 character.

Also, it turns out there's a bug in PHP <5.6.9 preg_replace() that we
need to work around too.

Change-Id: I282e5909e4663461d60c5386693db182de2fd44c
2016-10-05 14:32:27 -04:00
jenkins-bot c48bda0698 Merge "Add handling for PCRE errors in ustringGsub" 2016-10-05 18:15:10 +00:00
Kunal Mehta 48748a6046 Improve validation of ScribuntoContent
Implement Content::prepareSave() to ensure that any content
directly passed to WikiPage::doEditContent() that doesn't run edit
filters will still be validated. We have to use prepareSave() instead of
Content::isValid() because validation depends upon the current Title.

Create a ScribuntoContent::validate() convenience function to hold the
logic for that and add a todo to use it in the EditFilterMerged hook.

Also, remove a parser test that depended upon being able to save invalid
modules directly, as what it is testing is no longer possible (unless it
pre-dates making valid syntax a requirement).

Bug: T145548
Change-Id: Ie57eff36100963f02899d669df7375577f7375e1
2016-09-14 11:50:07 -07:00
Marius Hoch 0f4db74148 Add mw.hash to Scribunto
Provides a simple wrapper for PHP's hash() and
hash_algos() functions.

I will add docs to the Lua reference manual once
this is merged.

Bug: T142585
Change-Id: I6697463974a175e99f9b77428a1085247165ebc9
2016-08-18 04:39:04 +02:00
Brad Jorsch ba19a82c06 Add handling for PCRE errors in ustringGsub
Bug: T130823
Change-Id: I6fab71c82ddab92daf6b369cb9857d9892f2d246
2016-07-15 15:43:58 -04:00
Brad Jorsch d643f40de9 Ustring: Let gcodepoint work with moderately long strings
For the PHP implementation, return the codepoints as a table instead of
multiple return values that get table-ified in Lua, to avoid hitting
too-many-values stack limits.

For the pure-Lua version, inline most of ustring.codepoint instead of
calling it to avoid what's effectively "{ unpack( stuff ) }".

Bug: T118687
Change-Id: I105f388cc23ab55d4124739700ef89d5354b7dbc
2016-07-15 19:35:58 +00:00
Brad Jorsch c9de00aeff SECURITY: Don't escape strip markers when escaping attributes in mw.html
Core strip markers were changed in T110143 to include characters that
are normally encoded in attributes, however we want to pass them through
here so they can be unstripped correctly in the output wikitext.

This fix makes "Strip markers in CSS" parser test pass again.

Bug: T110143
Bug: T135961
Change-Id: I1353931a53c668d8a453dfa2300a99f59fdb01c5
2016-05-22 21:40:32 -04:00
Brad Jorsch aa4d72e3ff Fix uncontroversial phpcs errors
The following continue to be ignored:
* Generic.Arrays.DisallowLongArraySyntax.Found, because I'm not sure
  Scribunto is ready to abandon old version support in master.
* MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures,
  because it's overly strict for its purpose.

Squiz.Classes.ValidClassName.NotCamelCaps isn't ignored globally, we
just ignore it explicitly every place it's needed.

Change-Id: I307668da6ef7b3e23da19b1fd1e08914239b99b3
2016-05-18 16:31:28 -04:00