-
Notifications
You must be signed in to change notification settings - Fork 35
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
feat(validators): add URL validator #52
Conversation
Codecov Report
@@ Coverage Diff @@
## master #52 +/- ##
==========================================
+ Coverage 96.87% 97.52% +0.64%
==========================================
Files 11 12 +1
Lines 192 242 +50
Branches 31 43 +12
==========================================
+ Hits 186 236 +50
Misses 5 5
Partials 1 1
Continue to review full report at Codecov.
|
@bolatovumar thanks for sending over. Let's discuss further in #11 |
@bolatovumar are you up for some changes in order to land this in? |
@bolatovumar putting my thoughts around enabling this capability without coupling it into the existing hosts validation logic, see below:
Acceptance tests:
|
@lirantal makes sense. I will probably have some time to look at this in a week or so. Was a bit busy in recent weeks. |
Ok, let's see how it goes in the upcoming week. |
a0a6355
to
3e894df
Compare
0ed044e
to
bbc1041
Compare
Ok, I added a separate URL validator which tries to do an exact match for a URL in the list of allowed URLs. However, in its current state it ONLY checks for a list of passed-in URLs and is not usable together with Not sure how I would go about getting the |
@bolatovumar see my last bullet. The new validator you add to the api package is ok to be standalone and doesn't need to "play nicely together with allowed-hosts" because that's an API and the consumer will implement whatever they want. The change of making them play nicely together is on the CLI package and specifically inside |
@lirantal still not entirely sure what you mean. As it works currently,
the |
@bolatovumar ok, so once more - you should add to the Does that help make it clear? :) |
@lirantal If you have something like Then Same as above would have to be done for |
Exactly. Change it to also receive that flag, and then when it has both it can call the underlying API for both of them and make the proper decision. I think you got it ;-) |
430a6ad
to
5d94a11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the hassle, almost there! :-)
5d94a11
to
e60b855
Compare
e60b855
to
428d7ff
Compare
50dc5aa
to
f7cb87a
Compare
|
||
expect(() => { | ||
validator.validate(['https://registry.npms.org/@babel/code-frame']) | ||
}).not.toThrow() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a future PR we need to remember to replace all these no.toThrow() with the expected returned objects since we changed throwing to returning an object with an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lirantal, yeah, will do but will have to be a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
if (validatorOptions && validatorOptions.allowedUrls) { | ||
const urlValidator = new ValidateUrl({packages: lockfile.object}) | ||
|
||
validationResult.errors = validationResult.errors.filter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if validationResult.errors
is already populated from the host validator in line 49? (https://github.com/lirantal/lockfile-lint/pull/52/files#diff-b5633cfe76c3d56193e776b9dc02140dR49) we'll overwrite it here. It might be ok to overwrite some of the results because the url validation will allow them, but not others.
I think would be good to iterate specifically on each package there in the errors
objects and then based on the results from urlValidator.validateSingle()
into that instead of assigning to it and overwriting whatever is there. Since validateSingle()
only returns true or false then you can't just pass the same to the validationResult.errors
because that expects to have a specific structure, right? so I think that validateSingle()
needs to return the same error object instead of a boolean. Either that, or you'll need to construct it properly here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lirantal line 55 will filter out all errors that the did not pass the HostValidator
check but passed the UrlValidator
check. So, let's say you have ['npm', 'yarn']
specified for allowed hosts and some package fails the check because this packages resolves to a URL on Github. Now, we will have this error in the validationResult.errors
array. However, if we explicitly specify this exact Github URL as allowed in our allowedUrls
option then it will pass the UrlValidator
check and will be filtered out. Is this not what we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think you're right. This check happens only for errors, and only for those that then have been sent through the allowed-urls so a failing check should keep the error object, and a passing one should remove it.
@@ -59,3 +81,35 @@ function ValidateHttpsManager ({path, type, validatorValues, validatorOptions}) | |||
|
|||
return validator.validate() | |||
} | |||
|
|||
function ValidateUrlManager ({path, type, validatorValues, validatorOptions}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so this is needed, but only in the case that specific urls were specific -u
and no hostnames, otherwise we don't need to trigger this one. In the case that we do need to trigger this only on specific URLs then the whole work with ValidateHost
below is then needless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bolatovumar ok so last comment before we merge - where do we stand on this one? does my comment make sense.
I understand that you've put it here because the validators are being run regardless to one another so maybe we can update the code for runValidators()
to not run the url validator manager, if the host validator manager is run, and if so, then skip it. I guess it changes things a bit so I'm happy to take a look at refactoring this after landing this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lirantal yeah, your comment makes sense. I will look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I'll get this merged later tonight or tomorrow and we can pick up the remaining work after this one gets in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lirantal ok, I added an additional check to skip running the ValidateUrlManager
if both the --allowed-urls
and --allowed-host
are used.
@bolatovumar thanks for keeping at it. We're getting there and this is really close, just need to polish out the way this validator now works for the CLI |
@bolatovumar sorry about the delay here. Great work and commitment from you. I wanted to say that I appreciate the time and attending to everything! 🙏 |
🎉🎉🎉 |
address #39
Description
Allows to specify more specific URLs in
--allowed-hosts
option by specifying something likegithub.com/SomeOrg/SomeRepo#<hash>
. You can be as specific as you want, e.g.github.com
,github.com/SomeOrg
,github.com/SomeOrg/SomeRepo
andgithub.com/SomeOrg/SomeRepo#<hash>
are all valid options.Types of changes
Related Issue
#11
Checklist: