Repository navigation
[#213] Read an entry's uid by the search's rule in authenticate, getObject, update and delete, so an empty own __UID__ falls back to the name - #220
Conversation
…and authenticate, so an empty own __UID__ falls back to the name
…ts name in getObject, update and delete
… renames an entry without a __UID__ value, and refuse a name that is another entry's __UID__
…own __UID__ that has no value; another holder still refuses it update's __UID__ clash check asked the index whether any entry holds the new name as __UID__. The index keys an own __UID__ that starts with a comment by its text, while uidOf reads no value from it, so such an entry could not be renamed to that text: it clashed with itself. The check now skips the entry itself, by identity, and still refuses when another entry holds the name too. Module 400/400.
…he comment-first name in authenticate and the __GROUP__ guard of the __UID__ clash check - uidLookupByNameSkipsEntriesWithAUid and uidLookupByNameMatchesOnlyTheLastName also go through update and delete, so a getEntry that bypasses the uidOf filter fails. - authenticateOnACommentFirstNameHasNoUid runs what the PR body only traced: an own __NAME__ that starts with a comment gives no uid, and authenticate throws IllegalArgumentException, as the search does. - renamingAGroupIgnoresAStrayUid pins the isSupportUid guard of update's __UID__ clash check. - The Javadoc of uidOf and entriesByUid says that the uid lookup takes its candidates from the index, which keys ICF elements by their whole text, and only then applies uidOf's rule; the comment in authenticate names the case in which an entry found by name has no uid. Module 402/402.
vharseko
left a comment
There was a problem hiding this comment.
Reviewed at 93d869c. I found no regressions.
The change addresses #213: authentication and search use the same UID selection rule, and a simple UID lookup finds entries with an empty or missing UID by their name. Renaming such an entry returns its new name as the UID and checks for another entry holding that UID before modifying the document.
I checked the discussion behind #213 and #209 against the implementation and tests. The real-UID precedence, compound-filter limitations, and namespace/comment edge cases are explicitly documented; I am not raising them again.
Validation: all 402 XML connector tests passed locally on JDK 21, with no failures, errors, or skips. The reactor package build passed with Javadoc generation skipped. GitHub CI is green.
Closes #213.
The connector read an entry's uid in three ways:
ConnectorObjectCreator) reads only elements whose first child is text. It took the last own__UID__with a value and, without one, the last own__NAME__with a value. So it reports the entry from the issue, with<icf:__UID__/>, under its name.authenticatetook the text of the first own__UID__element, empty or not, and the first own__NAME__only when there was no__UID__element. On<icf:__UID__/>it callednew Uid(""), which throwsIllegalArgumentException: Uid value must not be blank!. On an entry with two__UID__values it returned the first, while the search reports the last.getObject,updateanddeletelooked the uid up among__UID__values only. For an entry without a__UID__value, the uid the search reports is its name, and that lookup found nothing:getObjectreturned null, andupdateanddeletethrewUnknownUidException.Now
ConnectorObjectCreator.uidOfis the one rule, the search's: the last own__UID__with a value, else the last own__NAME__with a value, in any namespace. An element has a value if its first child is a text node. An empty__UID__has none, and neither has one that held only whitespace, which loading the file empties. The search andauthenticateuse this rule.A uid lookup (the
__UID__ = vfilter ofgetObject,updateanddelete) first takes the entries with a__UID__ofv, as before. Only if there are none, and only for a class with a__UID__, it takes the entries namedvwhoseuidOfisv. Unless an entry has a__UID__outside the ICF namespace, these are the entries without a__UID__value whose last name isv. This fallback lives outside the index, so the index keeps agreeing with the XQuery path.Changes in behaviour
authenticatereturns the uid the search reports.__UID__gets its name instead of anIllegalArgumentException.__UID__values gets the last, not the first.__UID__value and with two names gets the last name, not the first.getObject,updateanddeletefind an__ACCOUNT__without a__UID__value by its name when no entry has that__UID__. This covers an empty element and no element at all. Through the facade,authenticate,getObject,updateanddeletenow work on the entry from the issue.updatethat renames an entry without a__UID__value returns the new name as the uid, as it already did for__GROUP__, which has no__UID__. Before, it returned the old name, which no longer found the entry.updaterefuses to rename an entry without a__UID__value to a name that is another entry's__UID__. It throwsAlreadyExistsException: Could not update entry. An entry with the __UID__ of <name> already exists.before any change. Otherwise the renamed entry's uid would be that name, and a lookup by it would find the other entry. An entry with a__UID__value keeps its uid and may take such a name. The entry's own__UID__element does not count: one that starts with a comment, such as<icf:__UID__><!--c-->v</icf:__UID__>, has no value, and the entry may be renamed tov.__UID__element whose__NAME__starts with a comment, such as<icf:__NAME__><!--c-->bob</icf:__NAME__>,authenticatenow throwsIllegalArgumentException: Uid value must not be blank!. Before, it returnedUid("bob"). The search reads no value from such a__NAME__and already threw on this entry on master.Tests
The new tests are in
XMLHandlerOwnElementsTestsunless named otherwise.authenticate and the search
authenticateReportsTheUidTheSearchReportsreplacesauthenticateReadsTheFirstOwnPasswordAndUid.__UID__valuesu40,u41and passwordsp40,p41.p40givesu41, andp41gives null. On masterp40givesu40.authenticateWithAnEmptyOwnUidReturnsItsName:<icf:__UID__/>and<icf:__UID__> </icf:__UID__>each give the entry's name, which is also the uid the search reports. On master:IllegalArgumentException.aValuedUidBesideAnEmptyOneIsTheUid: a valued__UID__before an empty one, and one after an empty one, is the uid inauthenticateand in the search. On master:IllegalArgumentExceptionwhere the empty one comes first.authenticateReportsTheNameTheSearchReportsAsUid: an entry with an empty__UID__and namesname-a,name-bgetsname-b. On master:IllegalArgumentException.authenticateOnACommentFirstNameHasNoUid: an entry without a__UID__element and with<icf:__NAME__><!--c-->bob</icf:__NAME__>getsIllegalArgumentException: Uid value must not be blank!. On master it getsUid("bob").aFullSearchReportsTheLastValuedUidOfTwo: the search reportsu41for the two-uid entry. Passes on master. Fails ifuidOftakes the first value.Uid lookup
uidLookupFindsAnEntryWithoutAUidByItsName: by the name, the__UID__ = emptyuidfilter finds the entry,updatechanges it anddeleteremoves it. The file is checked. On master the filter finds nothing.uidLookupFindsAnEntryWithoutAUidElement: the same for an entry with no__UID__element, under the ICF prefixx. On master:UnknownUidException.uidLookupByNameSkipsEntriesWithAUid: two entries are namedshared, one with__UID__valuesu90andu91. A lookup bysharedfinds only the other, anddeletebysharedremoves only the other. On master the lookup finds nothing.uidLookupByNameMatchesOnlyTheLastName: for the entry namedname-athenname-b,name-afinds nothing andname-bfinds it.updateanddeletebyname-athrowUnknownUidException. On mastername-bfinds nothing.uidLookupPrefersARealUid: an entry with__UID__xwins over an entry without a uid namedx, in the search and inupdate. Passes on master. Fails if the fallback adds to the real matches or replaces them.eitherUidFindsAnEntryWithTwoForUpdateAndDelete:updatebyu40, thendeletebyu41. Passes on master. Fails if the lookup comparesuidOf.Rename
renamingAnEntryWithoutAUidReturnsTheNewName: the rename returnsUid("renamed"), and the__UID__ = renamedfilter finds the entry. On master:UnknownUidException.renamingAnEntryWithoutAUidToAnotherEntrysUidIsRefused:__UID__renamed to another entry's uid keeps its own uid.UnknownUidException.renamingToTheTextOfAnOwnUidWithoutAValueClashesOnlyWithAnotherEntry: two entries whose own__UID__starts with a comment,<!--c-->v1and<!--c-->v2, and a third with__UID__v2.v1returnsUid("v1"), and the__UID__ = v1filter finds it.v2is refused, because the third entry holdsv2too.UnknownUidException, since the lookup by the first entry's name finds nothing.renamingAGroupIgnoresAStrayUid: a__GROUP__, which has no__UID__in the XSD, renamed to the text of another group's stray__UID__element returns the new name. Passes on master. Fails if the__UID__clash check also runs for a class without a__UID__.Facade and index
XMLConnectorTests#entryWithAnEmptyUidIsFoundByTheUidAuthenticateReturnsruns, through the facade and on the entry from the issue:authenticate,getObject,update,getObjectwith the new value,delete, thengetObject, which returns null. On masterauthenticatethrowsIllegalArgumentException.XMLHandlerIndexTests.PROBESgets__UID__ = no-uid.index-fixture.xmlhas an account namedno-uidwith<icf:__UID__/>, and the index and the XQuery must both find nothing. This fails if the fallback moves into the index.Run against master's main code, these tests give 13 failures, all of them with an "On master" result above. The module runs 402 tests with no failures; master runs 386.
Not covered
__UID__with more than one part goes through XQuery, which does not find an entry by its name.__UID__equal to the name of an entry without a__UID__value wins. A lookup finds only the entry with the__UID__, and a full search reports both entries with the same uid.__UID__and__NAME__in the ICF namespace only, while reads take them in any namespace. If an entry's last name is in another namespace, it reports a uid that no lookup finds.__UID__value nor a__NAME__value getsIllegalArgumentException: Uid value must not be blank!from the search, as before.authenticatethrows it too when it finds such an entry by name.__UID__values:updateanddeletefind it by either value, andupdatereturns the uid it was given.getObjectby the first value returns null, as on master: the facade drops a result whose uid is not the one asked for, and the search reports the last.__UID__elements.