Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Verify each target has the right number of tests #11998

Merged
merged 7 commits into from
Oct 18, 2017
Merged

Verify each target has the right number of tests #11998

merged 7 commits into from
Oct 18, 2017

Conversation

cschanaj
Copy link
Collaborator

@cschanaj cschanaj commented Aug 20, 2017

blocked by #11187 which has been pending review for a long time... Also, merge #11942 before whitelisting rules-test.

See https://gist.github.com/cschanaj/b3c80c935226c55e78013d81d618cd99

Related: #7272

if not "*" in target and not self.excludes(("http://%s/" % target)):
continue

# '*.example.com' match 'www.example.com' but not 'secure.account.exmple.com'
Copy link
Collaborator Author

@cschanaj cschanaj Aug 21, 2017

Choose a reason for hiding this comment

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

@Hainish does *.example.com matches www.example.com, secure.account.example.com and example.com? I am a bit confused seeing https://support.google.com/customsearch/answer/71826?hl=en and I not not sure how https-everywhere treat them. thanks in advance!

Copy link
Member

@Hainish Hainish Aug 22, 2017

Choose a reason for hiding this comment

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

@cschanaj the logic is here:

// now eat away from the left, with *, so that for x.y.z.google.com we
// check *.z.google.com and *.google.com (we did *.y.z.google.com above)
for (var i = 2; i <= segmented.length - 2; ++i) {
var t = "*." + segmented.slice(i,segmented.length).join(".");
results = results.concat(this.targets[t]);
}

So to answer, for a.b.examble.com, *.example.com is a matching target.

@cschanaj
Copy link
Collaborator Author

@Hainish I have fixed the wildcard matching logic in c255212 and this is ready for an review. thanks!!

P.S. please have a look at #11942 which fix a trivial bug in the ruleset whitelist cleanup script.

@Hainish
Copy link
Member

Hainish commented Aug 23, 2017

Got it, I should have some time in the next few days to review this.

@cschanaj
Copy link
Collaborator Author

cschanaj commented Aug 24, 2017

@Hainish It seems that we treat * in different position differently, according to my understanding, it seem that

implementation in rules.js

target regex interpretation
*.example.com ^.+\.example\.com$
secure.*.example.com ^secure\.[^\.]+\.example\.com$
www.example.* ^www\.example\.[^\.]+$

I will have to make changes to this PR if this is true, please confirm. thanks!

@cschanaj
Copy link
Collaborator Author

@Hainish merge #12091 will fix Travis from this PR. thanks!

@cowlicks
Copy link
Contributor

@cschanaj I'm looking into this today! Sorry for the delay.

continue

# According to the logic in rules.js available at
# EFForg/https-everywhere/blob/master/chromium/rules.js#L350-L355
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you include the commit hash in this URL? This way we can find the referenced code if it moves. You can get a permalink to lines in a specific version of the file by selecting the lines normally, then pressing "y".

pattern = pattern.replace('*', '.+')

# however, `example.*` match `example.com` but not `example.co.uk`
if pattern[len(pattern) - 1] == '*':
Copy link
Contributor

Choose a reason for hiding this comment

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

You can get the last element like this: pattern[-1]

@cowlicks
Copy link
Contributor

@cschanaj I'm not very familiar with running these tests. Would you mind providing a testcase this PR fixes? I would just run it by pointing the rulesdir in checker.config to it, right?

@cschanaj
Copy link
Collaborator Author

cschanaj commented Sep 13, 2017

@cowlicks Sadly, Travis does not trigger rules test if there is only core code changes. I run the rules test by the following command

$ export TEST=rules
$ ./test.sh

Copy link
Contributor

@cowlicks cowlicks left a comment

Choose a reason for hiding this comment

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

One bug, should be simple to fix. Everything else seems fine.

"""Verify that each rule and each exclusion has the right number of tests
that applies to it. TODO: Also check that each target has the right
"""Verify that each target, rule and exclusion has the right number of tests
that applies to it. Also check that each target has the right
number of tests. In particular left-wildcard targets should have at least
three tests. Right-wildcard targets should have at least ten tests.

Returns an array of strings reporting any coverage problems if they exist,
or empty list if coverage is sufficient.
"""
problems = self._determineTestApplication()
Copy link
Contributor

Choose a reason for hiding this comment

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

Every "problem" gets printed twice, they are created here in getCoverageProblems. This happens because problems is a reference to self.test_application_problems through self._determineTestApplication. Then again in getTargetValidityProblems we do problems = self._determineTestApplication, so the problems from getCoverageProblems also get reported through getTargetValidityProblems.

I'm not sure why problems is assigned like this. I'm guessing it is a mistake in either this function or getTargetValidityProblems. Maybe @Hainish can chime in.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cschanaj You can probably just change this to:

self._determineTestApplication()
problems = []

that is what other tests do

@cowlicks
Copy link
Contributor

@cschanaj git can be tricky sometimes. I can fix this for you if you'd like.

@cowlicks
Copy link
Contributor

I revisited this today. It looks good to me. It should be merged in conjunction with #1209, but #12091 needs to be updated again. Can you update it @cschanaj ? then we can merge this.

Also, docker on travis is failing for some reason.

@cschanaj
Copy link
Collaborator Author

@cowlicks I have rebased this and merged #12091 here. I will update #11560 once this is merged. thanks!

@cowlicks
Copy link
Contributor

@cschanaj great work. Thank you.

@cowlicks cowlicks merged commit 32e9cac into EFForg:master Oct 18, 2017
@cschanaj cschanaj deleted the check-test branch October 18, 2017 22:26
J0WI pushed a commit that referenced this pull request Dec 1, 2017
* Remove outdated TODO (fixed by #11998)

* Remove html encoded characters

* Surround XML tags and code with backticks

* Wrap source to 80 characters

* Add missing slash
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants