jenkins-bot has submitted this change and it was merged.

Change subject: Return '' from getTokenSalt to enable token check
......................................................................


Return '' from getTokenSalt to enable token check

If getTokenSalt is not overwritten, it returns false,
disabling the token check in ApiMain. We forget about
this, but I don't think this was a big issue, since we
do our own token check in EditEntity (not the API module)
anyway.

Change-Id: I9395b65473167a205fb1970f5232b36a9a26bdd6
---
M repo/includes/api/ApiWikibase.php
M repo/tests/phpunit/includes/api/LinkTitlesTest.php
M repo/tests/phpunit/includes/api/ModifyTermTestCase.php
M repo/tests/phpunit/includes/api/SetAliasesTest.php
M repo/tests/phpunit/includes/api/SetSiteLinkTest.php
M repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
6 files changed, 53 insertions(+), 32 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  WikidataJenkins: Verified
  jenkins-bot: Verified



diff --git a/repo/includes/api/ApiWikibase.php 
b/repo/includes/api/ApiWikibase.php
index a8ddaab..ea23b53 100644
--- a/repo/includes/api/ApiWikibase.php
+++ b/repo/includes/api/ApiWikibase.php
@@ -215,6 +215,13 @@
        }
 
        /**
+        * @see ApiBase::getTokenSalt()
+        */
+       public function getTokenSalt() {
+               return $this->needsToken() ? '' : false;
+       }
+
+       /**
         * @see ApiBase::mustBePosted()
         */
        public function mustBePosted() {
diff --git a/repo/tests/phpunit/includes/api/LinkTitlesTest.php 
b/repo/tests/phpunit/includes/api/LinkTitlesTest.php
index 7ee0d6e..4a126fc 100644
--- a/repo/tests/phpunit/includes/api/LinkTitlesTest.php
+++ b/repo/tests/phpunit/includes/api/LinkTitlesTest.php
@@ -87,28 +87,31 @@
 
        public static function provideLinkTitleExceptions(){
                return array(
-                       array( //0 badtoken
+                       array( //0 notoken
                                'p' => array( 'tosite' => 'nnwiki', 'totitle' 
=> 'Oslo', 'fromsite' => 'nowiki', 'fromtitle' => 'AnotherPage' ),
-                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'badtoken', 'message' => 'loss of session data' ) ) 
),
-                       array( //1 add two links already exist together
+                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'notoken', 'message' => 'The token parameter must 
be set' ) ) ),
+                       array( //1 badtoken
+                               'p' => array( 'tosite' => 'nnwiki', 'totitle' 
=> 'Oslo', 'fromsite' => 'nowiki', 'fromtitle' => 'AnotherPage', 'token' => 
'88888888888888888888888888888888+\\' ),
+                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'badtoken', 'message' => 'Invalid token' ) ) ),
+                       array( //2 add two links already exist together
                                'p' => array( 'tosite' => 'nnwiki', 'totitle' 
=> 'Oslo', 'fromsite' => 'nowiki', 'fromtitle' => 'Oslo' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'common-item') ) ),
-                       array( //2 add two links already exist together
+                       array( //3 add two links already exist together
                                'p' => array( 'tosite' => 'dewiki', 'totitle' 
=> 'Berlin', 'fromsite' => 'nlwiki', 'fromtitle' => 'Oslo' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'no-common-item') ) ),
-                       array( //3 add two links from the same site
+                       array( //4 add two links from the same site
                                'p' => array( 'tosite' => 'nnwiki', 'totitle' 
=> 'Hammerfest', 'fromsite' => 'nnwiki', 'fromtitle' => 'Hammerfest' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'param-illegal') ) ),
-                       array( //4 missing title
+                       array( //5 missing title
                                'p' => array( 'tosite' => 'nnwiki', 'totitle' 
=> '', 'fromsite' => 'dewiki', 'fromtitle' => 'Hammerfest' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'param-illegal') ) ),
-                       array( //5 bad tosite
+                       array( //6 bad tosite
                                'p' => array( 'tosite' => 'qwerty', 'totitle' 
=> 'Hammerfest', 'fromsite' => 'nnwiki', 'fromtitle' => 'Hammerfest' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'unknown_tosite') ) ),
-                       array( //6 bad fromsite
+                       array( //7 bad fromsite
                                'p' => array( 'tosite' => 'nnwiki', 'totitle' 
=> 'Hammerfest', 'fromsite' => 'qwerty', 'fromtitle' => 'Hammerfest' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'unknown_fromsite') ) ),
-                       array( //7 missing site
+                       array( //8 missing site
                                'p' => array( 'tosite' => 'nnwiki', 'totitle' 
=> 'APage', 'fromsite' => '', 'fromtitle' => 'Hammerfest' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'unknown_fromsite') ) ),
                );
diff --git a/repo/tests/phpunit/includes/api/ModifyTermTestCase.php 
b/repo/tests/phpunit/includes/api/ModifyTermTestCase.php
index a01e282..26d4098 100644
--- a/repo/tests/phpunit/includes/api/ModifyTermTestCase.php
+++ b/repo/tests/phpunit/includes/api/ModifyTermTestCase.php
@@ -136,20 +136,23 @@
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'modification-failed' ) ) ),
                        array( //2
                                'p' => array( 'language' => 'pt', 'value' => 
'normalValue' ),
-                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'badtoken', 'message' => 'loss of session data' ) ) 
),
+                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'notoken', 'message' => 'The token parameter must 
be set' ) ) ),
                        array( //3
+                               'p' => array( 'language' => 'pt', 'value' => 
'normalValue', 'token' => '88888888888888888888888888888888+\\' ),
+                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'badtoken', 'message' => 'Invalid token' ) ) ),
+                       array( //4
                                'p' => array( 'id' => 'noANid', 'language' => 
'fr', 'value' => 'normalValue' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'no-such-entity-id', 'message' => 'is not valid' ) 
) ),
-                       array( //4
+                       array( //5
                                'p' => array( 'site' => 'qwerty', 'language' => 
'pl', 'value' => 'normalValue' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'unknown_site', 'message' => "Unrecognized value 
for parameter 'site'" ) ) ),
-                       array( //5
+                       array( //6
                                'p' => array( 'site' => 'enwiki', 'title' => 
'GhskiDYiu2nUd', 'language' => 'en', 'value' => 'normalValue' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'no-such-entity-link', 'message' => 'No entity 
found matching site link' ) ) ),
-                       array( //6
+                       array( //7
                                'p' => array( 'title' => 'Blub', 'language' => 
'en', 'value' => 'normalValue' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'param-illegal', 'message' => 'Either provide the 
item "id" or pairs' ) ) ),
-                       array( //7
+                       array( //8
                                'p' => array( 'site' => 'enwiki', 'language' => 
'en', 'value' => 'normalValue' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'param-illegal', 'message' => 'Either provide the 
item "id" or pairs' ) ) ),
                );
diff --git a/repo/tests/phpunit/includes/api/SetAliasesTest.php 
b/repo/tests/phpunit/includes/api/SetAliasesTest.php
index c6488a4..7e1289e 100644
--- a/repo/tests/phpunit/includes/api/SetAliasesTest.php
+++ b/repo/tests/phpunit/includes/api/SetAliasesTest.php
@@ -150,20 +150,23 @@
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'modification-failed' ) ) ),
                        array( //2
                                'p' => array( 'language' => 'pt', 'remove' => 
'normalValue' ),
-                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'badtoken', 'message' => 'loss of session data' ) ) 
),
+                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'notoken', 'message' => 'The token parameter must 
be set' ) ) ),
                        array( //3
+                               'p' => array( 'language' => 'pt', 'value' => 
'normalValue', 'token' => '88888888888888888888888888888888+\\' ),
+                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'badtoken', 'message' => 'Invalid token' ) ) ),
+                       array( //4
                                'p' => array( 'id' => 'noANid', 'language' => 
'fr', 'add' => 'normalValue' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'no-such-entity-id', 'message' => 'is not valid' ) 
) ),
-                       array( //4
+                       array( //5
                                'p' => array( 'site' => 'qwerty', 'language' => 
'pl', 'set' => 'normalValue' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'unknown_site', 'message' => "Unrecognized value 
for parameter 'site'" ) ) ),
-                       array( //5
+                       array( //6
                                'p' => array( 'site' => 'enwiki', 'title' => 
'GhskiDYiu2nUd', 'language' => 'en', 'remove' => 'normalValue' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'no-such-entity-link', 'message' => 'No entity 
found matching site link' ) ) ),
-                       array( //6
+                       array( //7
                                'p' => array( 'title' => 'Blub', 'language' => 
'en', 'add' => 'normalValue' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'param-illegal', 'message' => 'Either provide the 
item "id" or pairs' ) ) ),
-                       array( //7
+                       array( //8
                                'p' => array( 'site' => 'enwiki', 'language' => 
'en', 'set' => 'normalValue' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'param-illegal' ) ) ),
                );
@@ -172,7 +175,7 @@
        /**
         * @dataProvider provideExceptionData
         */
-       public function testSetLabelExceptions( $params, $expected ){
+       public function testSetAliasesExceptions( $params, $expected ){
                self::doTestSetTermExceptions( $params, $expected );
        }
 }
diff --git a/repo/tests/phpunit/includes/api/SetSiteLinkTest.php 
b/repo/tests/phpunit/includes/api/SetSiteLinkTest.php
index 4bb21d3..4bbbe0d 100644
--- a/repo/tests/phpunit/includes/api/SetSiteLinkTest.php
+++ b/repo/tests/phpunit/includes/api/SetSiteLinkTest.php
@@ -107,37 +107,40 @@
                $basicCases = array(
                        array( //0 badtoken
                                'p' => array( 'site' => 'dewiki', 'title' => 
'Berlin', 'linksite' => 'svwiki', 'linktitle' => 'testSetLiteLinkWithNoToken' ),
-                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'badtoken', 'message' => 'loss of session data' ) ) 
),
-                       array( //1 testSetLiteLinkWithNoId
+                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'notoken', 'message' => 'The token parameter must 
be set' ) ) ),
+                       array( //1
+                               'p' => array( 'site' => 'dewiki', 'title' => 
'Berlin', 'linksite' => 'svwiki', 'linktitle' => 'testSetLiteLinkWithBadToken', 
'token' => '88888888888888888888888888888888+\\' ),
+                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'badtoken', 'message' => 'Invalid token' ) ) ),
+                       array( //2 testSetLiteLinkWithNoId
                                'p' => array( 'linksite' => 'enwiki', 
'linktitle' => 'testSetLiteLinkWithNoId' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException' ) ) ),
-                       array( //2 testSetLiteLinkWithBadId
+                       array( //3 testSetLiteLinkWithBadId
                                'p' => array( 'id' => 123456789, 'linksite' => 
'enwiki', 'linktitle' => 'testSetLiteLinkWithNoId' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException' ) ) ),
-                       array( //3 testSetLiteLinkWithBadSite
+                       array( //4 testSetLiteLinkWithBadSite
                                'p' => array( 'site' => 'dewiktionary', 'title' 
=> 'Berlin', 'linksite' => 'enwiki', 'linktitle' => 'Berlin' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException' ) ) ),
-                       array( //4 testSetLiteLinkWithBadTitle
+                       array( //5 testSetLiteLinkWithBadTitle
                                'p' => array( 'site' => 'dewiki', 'title' => 
'BadTitle_de', 'linksite' => 'enwiki', 'linktitle' => 'BadTitle_en' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException' ) ) ),
-                       array( //5 testSetLiteLinkWithBadTargetSite
+                       array( //6 testSetLiteLinkWithBadTargetSite
                                'p' => array( 'site' => 'dewiki', 'title' => 
'Berlin', 'linksite' => 'enwiktionary', 'linktitle' => 'Berlin' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException' ) ) ),
                );
                $badgesCases = array(
-                       array( //6 bad badge id
+                       array( //7 bad badge id
                                'p' => array( 'site' => 'enwiki', 'title' => 
'Berlin', 'linksite' => 'enwiki', 'linktitle' => 'Berlin', 'badges' => 
'abc|{faItem}' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'no-such-entity-id' ) ) ),
-                       array( //7 badge id is not an item id
+                       array( //8 badge id is not an item id
                                'p' => array( 'site' => 'enwiki', 'title' => 
'Berlin', 'linksite' => 'enwiki', 'linktitle' => 'Berlin', 'badges' => 
'P2|{faItem}' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'not-item' ) ) ),
-                       array( //8 badge item does not exist
+                       array( //9 badge item does not exist
                                'p' => array( 'site' => 'enwiki', 'title' => 
'Berlin', 'linksite' => 'enwiki', 'linktitle' => 'Berlin', 'badges' => 
'Q99999|{faItem}' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'no-such-entity' ) ) ),
-                       array( //9 badge id is not specified
+                       array( //10 badge id is not specified
                                'p' => array( 'site' => 'enwiki', 'title' => 
'Berlin', 'linksite' => 'enwiki', 'linktitle' => 'Berlin', 'badges' => 
'{faItem}|{otherItem}' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'not-badge' ) ) ),
-                       array( //10 no sitelink - cannot change badges
+                       array( //11 no sitelink - cannot change badges
                                'p' => array( 'site' => 'enwiki', 'title' => 
'Berlin', 'linksite' => 'svwiki', 'badges' => '{gaItem}|{faItem}' ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'no-such-sitelink' ) ) ),
                );
diff --git a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php 
b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
index 6077035..326b139 100644
--- a/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
+++ b/repo/tests/phpunit/includes/api/WikibaseApiTestCase.php
@@ -130,7 +130,9 @@
         */
        public function doTestQueryExceptions( $params, $exception ) {
                try {
-                       if ( array_key_exists( 'code', $exception ) && 
$exception['code'] == 'badtoken' ) {
+                       if ( array_key_exists( 'code', $exception )
+                                       && preg_match( '/^(no|bad)token$/', 
$exception['code'] ) ) {
+
                                $this->doApiRequest( $params );
                        } else {
                                $this->doApiRequestWithToken( $params );

-- 
To view, visit https://gerrit.wikimedia.org/r/148969
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9395b65473167a205fb1970f5232b36a9a26bdd6
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WikidataJenkins <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to