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

HTTPS URL Property Validator #2079

Merged
merged 3 commits into from
Jan 21, 2025
Merged

Conversation

jakobvogel
Copy link
Member

@jakobvogel jakobvogel commented Jan 20, 2025

Description

Adds a property validator that enforces a valid HTTPS URL.

Note that the entire property validation framework may be subject to some maintenance soon in order to improve integration with Tycho (and file structure). See SIRI-1050.

Additional Notes

Checklist

  • Code change has been tested and works locally
  • Code was formatted via IntelliJ and follows SonarLint & best practices

@jakobvogel jakobvogel added the 🧬 Enhancement Contains new features label Jan 20, 2025
return null;
}

if (!"https".equalsIgnoreCase(url.getProtocol())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Yannick build recently some central checks about http checks, would be good to reuse those.

Copy link
Member Author

Choose a reason for hiding this comment

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

Only if there is a non-trivial benefit. URL parsing is securely done via a Standard Library method, leaving only the protocol comparison as "custom code". IMHO, that is too trivial to invoke yet another helper.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I don't see it this way. It was done exactly to avoid 1.000 places checking if a string starts with http. BTW, its in Strings.isHttpUrl. but it does not enforce https and allows http as well 🫣
My vote is to add a isHttpsUrl method among with it, but its just my opinion.

Copy link
Member Author

Choose a reason for hiding this comment

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

…and it does not even check whether it is a valid URL after the prefix at all, accepting https:// ;%@@ lol whatever i don't care as valid URL, at the same time (ab-)using fully-fledged pattern matching for a simple case-insensitive prefix match. And that is the kind of faulty code we should use everywhere instead of standard methods?

We are approaching the test week. We need to get stuff done. Basically, you attempt to force me into bugfixing another project, open another PR there, wait for it to be processed, update this here, so that I can finally continue the work I am supposed to have done in time for the patch, just to move perfectly fine and effectively trivial code from this PR somewhere else. Honestly, under these circumstances, we really can save the discussions in future retros about planning and extra-hours and do something more productive instead.

But fine, then I'll work on sirius-kernel instead of the OX ticket.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks 🙏

…as requested by @idlira during review and after fixing the respective implementation.

OX-11244
@jakobvogel jakobvogel added the 🖐 Keep open Should not be merged label Jan 20, 2025

@Override
public void beforeSave(Property property, Object value) {
if (value instanceof String url && Strings.isFilled(url) && !Strings.isHttpsUrl(url)) {
Copy link
Member

Choose a reason for hiding this comment

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

Very optional: Could reduce duplication by extracting the actual check/validation (the if-condition) into a private method

Copy link
Member Author

@jakobvogel jakobvogel Jan 20, 2025

Choose a reason for hiding this comment

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

The variable url created in the first condition is used within the block for creating the error message. Hence, in order to extract a method, it would be something like a attemptToParseInvalidString(value) returning an Optional. Not sure whether that would be easier to understand and maintain.

However, like the other validators, this validator currently only checks Strings, and entirely ignores other data types. Maybe we could also get rid of the instance-of and generally use .toString(). That would make extraction of the method trivial.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Ah right. I think its okay for now then

@jakobvogel jakobvogel removed the 🖐 Keep open Should not be merged label Jan 21, 2025
@jakobvogel jakobvogel merged commit b23b775 into develop Jan 21, 2025
3 of 4 checks passed
@jakobvogel jakobvogel deleted the feature/jvo/OX-11244-HTTPS-Validation branch January 21, 2025 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧬 Enhancement Contains new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants