WMDE-leszek has uploaded a new change for review.
https://gerrit.wikimedia.org/r/319321
Change subject: Check if the EntityId belongs to the right repository in
WikiPageEntityRevisionLookup
......................................................................
Check if the EntityId belongs to the right repository in
WikiPageEntityRevisionLookup
Bug: T149581
Change-Id: Ib999422e876bf1874ce13debdd25bb7c1b3e65bc
---
M lib/includes/Store/Sql/WikiPageEntityRevisionLookup.php
M repo/tests/phpunit/includes/Store/WikiPageEntityRevisionLookupTest.php
2 files changed, 71 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/21/319321/1
diff --git a/lib/includes/Store/Sql/WikiPageEntityRevisionLookup.php
b/lib/includes/Store/Sql/WikiPageEntityRevisionLookup.php
index f845f88..3349ac6 100644
--- a/lib/includes/Store/Sql/WikiPageEntityRevisionLookup.php
+++ b/lib/includes/Store/Sql/WikiPageEntityRevisionLookup.php
@@ -3,6 +3,7 @@
namespace Wikibase\Lib\Store;
use DBAccessBase;
+use InvalidArgumentException;
use MWContentSerializationException;
use Revision;
use stdClass;
@@ -75,6 +76,8 @@
wfDebugLog( __CLASS__, __FUNCTION__ . ': Looking up entity ' .
$entityId
. " (revision $revisionId)." );
+ $this->assertEntityIdFromRightRepository( $entityId );
+
/** @var EntityRevision $entityRevision */
$entityRevision = null;
@@ -137,6 +140,8 @@
* @return int|false
*/
public function getLatestRevisionId( EntityId $entityId, $mode =
self::LATEST_FROM_SLAVE ) {
+ $this->assertEntityIdFromRightRepository( $entityId );
+
$rows = $this->entityMetaDataAccessor->loadRevisionInformation(
array( $entityId ), $mode );
$row = $rows[$entityId->getSerialization()];
@@ -148,6 +153,19 @@
}
/**
+ * @param EntityId $entityId
+ *
+ * @throws InvalidArgumentException
+ */
+ private function assertEntityIdFromRightRepository( EntityId $entityId
) {
+ $entityIdRepository = $entityId->getRepositoryName();
+ $lookupDatabaseName = $this->wiki ?: '';
+ if ( $entityIdRepository !== $lookupDatabaseName ) {
+ throw new InvalidArgumentException( 'Cannot load data
from database of repository: ' . $entityIdRepository );
+ }
+ }
+
+ /**
* Construct an EntityRevision object from a database row from the
revision and text tables.
*
* @see loadEntityBlob()
diff --git
a/repo/tests/phpunit/includes/Store/WikiPageEntityRevisionLookupTest.php
b/repo/tests/phpunit/includes/Store/WikiPageEntityRevisionLookupTest.php
index 506c5fa..879de83 100644
--- a/repo/tests/phpunit/includes/Store/WikiPageEntityRevisionLookupTest.php
+++ b/repo/tests/phpunit/includes/Store/WikiPageEntityRevisionLookupTest.php
@@ -2,6 +2,7 @@
namespace Wikibase\Lib\Tests\Store;
+use InvalidArgumentException;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Entity\EntityRedirect;
use Wikibase\DataModel\Entity\ItemId;
@@ -154,4 +155,56 @@
$this->assertSame( $revisionId,
$entityRevision->getRevisionId() );
}
+ public function
testGivenEntityFromForeignRepository_getEntityRevisionOfLocalLookupThrowsException()
{
+ $foreignEntityId = new ItemId( 'foo:Q123' );
+
+ $lookup = new WikiPageEntityRevisionLookup(
+
WikibaseRepo::getDefaultInstance()->getEntityContentDataCodec(),
+ new WikiPageEntityMetaDataLookup(
$this->getEntityNamespaceLookup() ),
+ false
+ );
+
+ $this->setExpectedException( InvalidArgumentException::class );
+ $lookup->getEntityRevision( $foreignEntityId );
+ }
+
+ public function
testGivenEntityFromAnotherRepository_getEntityRevisionOfForeignLookupThrowsException()
{
+ $foreignEntityId = new ItemId( 'bar:Q123' );
+
+ $lookup = new WikiPageEntityRevisionLookup(
+
WikibaseRepo::getDefaultInstance()->getEntityContentDataCodec(),
+ new WikiPageEntityMetaDataLookup(
$this->getEntityNamespaceLookup() ),
+ 'foo'
+ );
+
+ $this->setExpectedException( InvalidArgumentException::class );
+ $lookup->getEntityRevision( $foreignEntityId );
+ }
+
+ public function
testGivenEntityFromForeignRepository_getLatestRevisionIdOfLocalLookupThrowsException()
{
+ $foreignEntityId = new ItemId( 'foo:Q123' );
+
+ $lookup = new WikiPageEntityRevisionLookup(
+
WikibaseRepo::getDefaultInstance()->getEntityContentDataCodec(),
+ new WikiPageEntityMetaDataLookup(
$this->getEntityNamespaceLookup() ),
+ false
+ );
+
+ $this->setExpectedException( InvalidArgumentException::class );
+ $lookup->getEntityRevision( $foreignEntityId );
+ }
+
+ public function
testGivenEntityFromAnotherRepository_getLatestRevisionIdOfForeignLookupThrowsException()
{
+ $foreignEntityId = new ItemId( 'bar:Q123' );
+
+ $lookup = new WikiPageEntityRevisionLookup(
+
WikibaseRepo::getDefaultInstance()->getEntityContentDataCodec(),
+ new WikiPageEntityMetaDataLookup(
$this->getEntityNamespaceLookup() ),
+ 'foo'
+ );
+
+ $this->setExpectedException( InvalidArgumentException::class );
+ $lookup->getEntityRevision( $foreignEntityId );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/319321
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib999422e876bf1874ce13debdd25bb7c1b3e65bc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: WMDE-leszek <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits