Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] registered import-uris have precedence #5576

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

line-o
Copy link
Member

@line-o line-o commented Dec 10, 2024

When importing stylesheets the URIs are resolved in order

  • registered import-uris in package repo
  • XMLDB-locations (relative, absolute and with or without scheme)
  • any other location is treated as an exteranal source

The test class and its cases were renamed to reflect their purpose. Some inline comments were added to help describing the intent.

follow-up for #5574

@line-o line-o requested a review from a team as a code owner December 10, 2024 14:00
@line-o line-o added bug issue confirmed as bug needs 6.x.x backport labels Dec 10, 2024
@line-o line-o force-pushed the hotfix/transform-import branch from f0c6961 to 401ac6e Compare December 10, 2024 15:07
@adamretter
Copy link
Contributor

I don't think this works... What about the catalog?

@line-o
Copy link
Member Author

line-o commented Dec 10, 2024

@adamretter If you have a test case that shows an issue please post it here. Otherwise, I can only judge by the tests that are already present and I can come up with.

@line-o
Copy link
Member Author

line-o commented Dec 10, 2024

At least now the registered import uri is really resolved against the repo instead of trying to resolve it via http request.

@adamretter
Copy link
Contributor

You're missing the point of the test, please restore the original test

@reinhapa
Copy link
Member

You're missing the point of the test, please restore the original test

@adamretter could you please explain to us the point that we missing, instead of just telling us to restore a test as it was that we did no understand in the fist place.

As from #5574

@reinhapa Then why not just ask?

I personally would like to learn from that. Just rolling back will not help me (and may others in the future) in getting reasoning behind the current test. as the discussion seems to prove already. I would like see this issue as a chance to improve the test and the understanding for regression it wants to cover.

@line-o
Copy link
Member Author

line-o commented Dec 11, 2024

You're missing the point of the test, please restore the original test

The first test case is importing the stylesheet from the repo using the registered import-uri. So "the original test" is reinstated.

     @Test
     public void fromRegisteredImportUri() throws XMLDBException {
         final String xquery = getQuery("http://www.functx.com/functx.xsl");
         final ResourceSet result = existXmldbEmbeddedServer.executeQuery(xquery);
         assertTransformationResult(result);
     }

@line-o
Copy link
Member Author

line-o commented Dec 11, 2024

To better understand the current situation and the proposed solution:

The feature, to be able to import stylesheets using an import-uri that is registered in the databases package repository, did not work. The order of URI resolvers prevented that from happening, as the first resolver captured the URI and resolved it as an external resource.

By putting the PkgXsltModuleURIResolver first, all stylesheet import URIs will be matched against the ones registered in the package repo. That way we can be sure that they take precedence.

@adamretter
Copy link
Contributor

adamretter commented Dec 11, 2024

I would like see this issue as a chance to improve the test

@reinhapa But it doesn't improve the original test. Instead it removes the original test and adds different tests that prove something completely different.

in getting reasoning behind the current test

@reinhapa You could just talk to me. Even after all the nonsense and abuse I have been shovelled lately, I am still here and trying to help. If you want to understand the original purpose of the test, then the obvious thing would be to have a conversation with me (the original author of the test).

did not work

@line-o That is not my impression. It looks to me like this test only started recently failing, before that it was passing just fine.

@line-o
Copy link
Member Author

line-o commented Dec 11, 2024

this test only started recently failing, before that it was passing just fine

@adamretter because of curl -i http://www.functx.com/functx.xsl

public void testImportNoScheme() throws XMLDBException {
final String xquery = getQuery(moduleLocation);
public void fromRegisteredImportUri() throws XMLDBException {
final String xquery = getQuery("http://www.functx.com/functx.xsl");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@line-o I found a working document here: https://www.datypic.com/xsl/functx-1.0.1-doc.xsl that we may should use instead...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely not. The test is about importing a locally available Stylesheet and the fact that it was resolved from an external source was the problem I fixed.

Copy link
Member Author

@line-o line-o Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just coincidentally was also available at that address and not just registered with that namespace URI in exist-db's package repository.
It is non-obvious to use HTTP-addresses to uniquely name packages without also guaranteeing the source is available there but this is the status-quo, not the use-case this test is about and also a different discussion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see also what @adamretter wrote:

This test was to ensure the loading of XSLT imports from within EXPath packages.

@dizzzz
Copy link
Member

dizzzz commented Dec 17, 2024

@line-o by default curl does not follow redirects; I think the -L flag will make tha happen...

curl -Li http://www.functx.com/functx.xsl

(cant check right now)

If so, we could consider if we can enforce the HTTP-resolver in the test to follow redirects too?

@line-o
Copy link
Member Author

line-o commented Dec 17, 2024

But the test is clearly about importing the Stylesheet from within the db. The fact that an HTTP connection es even attempted is a failure.
The test would need to test for that as well. Sadly, it's easier said than done. We would need to either mock a lot or spy on the expected resolver to be called.

@line-o line-o requested review from reinhapa and a team December 17, 2024 07:41
@adamretter
Copy link
Contributor

Absolutely not. The test is about importing a locally available Stylesheet and the fact that it was resolved from an external source was the problem I fixed.

But the test is clearly about importing the Stylesheet from within the db.

@line-o Nope! That is absolutely not what I wrote this test for. This test was to ensure the loading of XSLT imports from within EXPath packages. This PR deletes that work and important use-case and goes in a completely different direction. This PR is a regression.

The correct approach would have been to fix this in the XML Resolver and/or EXPath package resolver.

@line-o
Copy link
Member Author

line-o commented Dec 17, 2024

This test was to ensure the loading of XSLT imports from within EXPath packages.

OK, so we are in agreement here, good. The test case to do that is back in now that this feature is fixed and more cases were added.

The correct approach would have been to fix this in the XML Resolver and/or EXPath package resolver.

This is what I did, by changing the order of the resolvers everything is in order.

@line-o
Copy link
Member Author

line-o commented Dec 17, 2024

The http-resolver should not be used for any of the test cases within ImportStylesheetTest. Maybe ImportLocalStylesheetTest would communicate that clearer?

@dizzzz dizzzz requested a review from a team December 20, 2024 19:54
When importing stylesheets the URIs are resolved in order

- registered import-uris in package repo
- XMLDB-locations (relative, absolute and with or without scheme)
- any other location is treated as an exteranal source

The test class and its cases were renamed to reflect their purpose.
Some inline comments were added to help describing the intent.
@line-o line-o force-pushed the hotfix/transform-import branch from 401ac6e to adbb94b Compare December 30, 2024 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issue confirmed as bug needs 6.x.x backport
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants