-
Notifications
You must be signed in to change notification settings - Fork 29
(GH-14) Adding additional IconUrl check #23
base: master
Are you sure you want to change the base?
Conversation
|
||
protected override PackageValidationOutput is_valid(IPackage package) | ||
{ | ||
var iconUrlHost = package.IconUrl.Host; |
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.
This could be null, so it may be helpful to return if the package.IconUrl is empty
Fix up the checks a bit so there are no null reference exceptions. |
@ferventcoder ah, good shout! I think I have corrected the logic flow. Let me know if you spot any other problems. |
Always resubmit the same commits unless the new changes add something additional. A code review is not one of them. (same comments for full effect ;) ) |
|
||
// Since there is an iconUrl, but no Project Url, the check has to return false | ||
// since the domains are definitely not the same | ||
if(package.ProjectUrl == null) return false; |
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.
We have a failure already accounted for projectUrl being empty, but I think it is okay to do this 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.
Agreed, this is a side effect of this specific test, and also a slight duplication of the other test, is it actually testing something else.
ce02888
to
e070513
Compare
@ferventcoder just away to head for the night, but will follow up with any comments in the morning. Let me know what you think. |
// Use Regular Expression to extract the Domain Name, from the Uri Host | ||
// Taken from example shown here http://stackoverflow.com/a/17091145/671491 | ||
var match = Regex.Match(host, "([^.]+\\.[^.]{1,3}(\\.[^.]{1,3})?)$"); | ||
return match.Groups[1].Success ? match.Groups[1].Value : string.Empty; |
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.
If there was ever a valid reason for adding tests, this is one.
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 was actually thinking that as I was creating it. :-D Have you got an example of how you would like the test harness, etc, set up, adn i can take a stab at 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.
There is a tests project. I'm taking it that there are no examples yet though?
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.
The testing harness would be similar to choco's
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.
I don't "think" there are, but ill admit, I only glanced. Will take a look, and see what I can come up with.
Would you see the get_domain_from_host method staying within the rule, or moved out into own class? Made static? Or create interface and constructor inject?
Just throwing ideas out just now. Not at computer now, so will be at least tomorrow.
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.
Make it a public method and then test it there.
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.
Okay, sounds like a plan 👍
@ferventcoder as a start (work still required) is the second commit the type of thing that you had in mind? |
NOTE: Never used TinySpec before, so very much feeling my way around here, but used some examples from choco in order to create this. |
result.ShouldEqual("test.com"); | ||
} | ||
} | ||
} |
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.
This is a great start! You could probably change the because to empty and then do this in all of the tests:
iconGuideline.get_domain_from_host("www.test.com").ShouldEqual("test.com")
And then add tests for the following scenarios:
- test.com
- www.test.com
- somewildsubdomain.test.com
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.
so, is each of those a separate test, or rather Fact? In other testing frameworks I have used/seen you can overload the test with multiple input and expected values, and it runs through the single test of each theory. Does that work here, or should I create three separate facts? If so, any suggestions as the the name of each fact?
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.
It's using nunit in the background, so you could add that logic, I just prefer separate specs for each so the names are specific to what failed - unless you have a way of changing the test name based on the input.
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.
It's really working with testing for so long - I should know from the name of the test alone exactly what failed before I go to dig into how to fix it. If I have to dig into the test itself to find out why it is failing then something is wrong. That's the theory anyway. It works out most of the time.
@ferventcoder ok, let me know what you think. |
|
||
var domain = iconGuideline.get_domain_from_host("somewildsubdomain.test.co.uk"); | ||
|
||
domain.ShouldEqual("test.co.uk"); |
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.
I would not have thought of this scenario, but that appears to be valid. :)
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.
Can you add one more scenario for me?
subdomain.tla.com
@ferventcoder ok, so that scenario results in a failed tests, which is what I think you thought would happen :-) I will look at the regex, and see if there is anything that can be done. |
@ferventcoder I have added that scenario though, and pushed to this PR. |
You caught me :D |
@ferventcoder what do you think of this change? |
{ | ||
domain = parts[1] + '.' + parts[0]; | ||
|
||
if (host.ToLower().IndexOf(".co.uk") != -1 && parts.Count > 2) |
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.
is this the only domain like this?
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.
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.
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.
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.
No, I didn't think it was, but I also didn't know of a clever way to encompass all the edge cases :-(
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.
It's possible we just call this good enough.
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.
I have one more approach that I want to try out, going to give it a whack at lunch time. If I don't get anywhere, I will fallback to what we have.
@ferventcoder what do you think about this alternative approach? |
[Fact] | ||
public void IsIconFromSameDomainAsProjectOrRawgit_should_return_true_from_rawgit_domain_with_single_level_top_level_domain() | ||
{ | ||
Context(); |
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.
Just noticed this. You don't need to call context. It is done automatically for you.
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.
Oh really? I am fairly sure I saw this in some of the Chocolatey Tests, so I just copied it from there. But I will take this out, and give it a try. Cheers!
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.
Ooooh. Yeah it was likely each of them was calling a reset to remove state.
"Under this context (arrange), because this happened (act), it should result in (assert)..."
Usually you set everything up in context, then because is the action (or the SUT), then all of the facts are just assertions. Sometimes you want to short circuit that because you have many, many scenarios that require little setup. I tend to prefer less ceremony because each arrange and act is usually an entire class with multiple assertions on that one action.
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.
Gotcha, that makes sense now then.
I had been looking at this:
But this fits with exactly what you are describing.
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.
Yes, that is one that is definitely a smaller setup. Would be a ton of spec classes for little benefit.
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.
|
||
result.ShouldBeTrue(); | ||
} | ||
} |
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.
All trues, no falses. Need both sides of that.
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.
Ah, good point! I guess by default I am a "happy path" kind of a guy 😄 I will add some failing steps as well.
56b9fd2
to
8217f67
Compare
@ferventcoder I have fixed up with your comments, and re-pushed. However... :-( I started adding in the unhappy paths, as you suggested, and this highlighted an error in the logic. See the failing test. Any ideas on best approach to go forward? It all comes down to not knowing the valid TLD's in order to move forward. I really don't want to have to start pulling in a complete list of TLD's and comparing against them, as these lists are always changing. What are your thoughts? |
I'll need to pull in the PR to see the failing test. |
@ferventcoder did you have any suggestions about this one, or did you get pulled onto something else? |
I didn't see the failing test yet. Might be best to comment on the PR files where the failing test is. |
[Fact] | ||
public void should_return_false_from_different_domain_and_double_level_top_level_domain() | ||
{ | ||
guideline.is_icon_from_same_domain_as_project_or_rawgit("test1.co.uk", "test.co.uk").ShouldBeFalse(); |
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.
Is this the failing test?
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.
Yes.
And it is due to this line:
I can change it to be > 3
but that then fails another test.
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.
Dumb idea Monday - most double TLDs are both two letters.
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.
I take it back. The last one is 2 letters. The other is either co
or one of the well known ones like org
, edu
. We'd catch enough of the items, it's probably okay if a few false positives drop.
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.
I had that idea on Dumb Idea Saturday, but wasn't sure if it was going to be a winner or not. Happy to proceed on that basis though.
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.
I guess we can add some exemptions, as we see them start to come in.
Is this ready to go? |
@ferventcoder no, this still has a failing test :-( I keep coming back to this one, and not liking the solutions that I come up with :-( |
- To ensure that the IconUrl either comes from the same domain as the ProjectUrl, or comes from the RawGit CDN - Fixes chocolateyGH-14
- To cover the functionality of the get_domain_from_host method
ProjectUrl, or comes from the RawGit CDN