-
Notifications
You must be signed in to change notification settings - Fork 276
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
Extend delegations tests #1711
Extend delegations tests #1711
Conversation
f0a5f63
to
580e206
Compare
Pull Request Test Coverage Report for Build 1606265815Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
cd02ba2
to
10e6361
Compare
10e6361
to
15234b6
Compare
15234b6
to
a0e74c1
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.
Looks pretty good to me. I'm not sure if my comments are really change requests -- maybe have a look and give your opinion?
TestDelegation("A", "C"), | ||
], | ||
# The traversal stops after visiting an invalid role | ||
visited_order=["A"], |
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.
could even rename "A" as "invalid" or something to make it clearer what the invalid role is?
targets | ||
*.doc / \ r/*/* | ||
A B | ||
r/x/* / \ r/y/*.zip | ||
C D |
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.
a diagram is not a bad idea but
- missing "*.md"
- shortening releases to r is not trivial to figure out
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.
True, I'll fix it but now after your comment I'm not sure how long a diagram can remain up to date with the code.
targets: utils.DataSet = { | ||
"targetfile": ("targetfile", []), | ||
"README.md": ("README.md", ["A"]), | ||
"releases/x/*": ("releases/x/x_v1", ["B", "C"]), | ||
"releases/y/*.zip": ("releases/y/y_v1.zip", ["B", "D"]), | ||
} |
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.
Would it make sense to include boolean for whether the target is found or not? then you could include some negative tests here as well, using the same delegations_tree. Or do you want to keep them separate?
As an example
- Add
TestTarget("C", b"x release in C", "releases/x/x_v2")
- add test case
"target exists, not delegated": ("releases/x/x_v2", [ ... ], False)
As another example
- Add
TestTarget("C", b"duplicate x release in C", "releases/x/x_v1")
- existing test case "releases/x/*" now tests that it finds the correct target (and not the one added above). The case name could be improved to explain 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.
I think extending it for negative cases makes sense but I didn't understand the second example. We add the target files in a dictionary in the simulator so the duplicate will replace the first target?
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 right, if the target path is the same then the url is the same... you are correct my example does not make sense.
TestTarget("targets", b"content", "targetfile"), | ||
TestTarget("A", b"content", "README.md"), | ||
TestTarget("C", b"content", "releases/x/x_v1"), | ||
TestTarget("D", b"content", "releases/y/y_v1.zip"), |
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.
having the same content is not great if you ever want to check you got the correct file from the correct delegation
# Confirm that the expected TargetFile is found | ||
assert target is not None | ||
exp_target = self.sim.target_files[targetpath].target_file | ||
self.assertDictEqual(target.to_dict(), exp_target.to_dict()) |
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.
since content is the same for every test target (see above), this would return true even if we had two different roles serving the same targetpath (and we got the wrong target because of a bug)
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 this is pretty much a bug in the test, I added a different content for each test file.
tuf/ngclient/updater.py
Outdated
if ( | ||
len(visited_role_names) > self.config.max_delegations | ||
and len(delegations_to_visit) > 0 | ||
): |
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 ( | |
len(visited_role_names) > self.config.max_delegations | |
and len(delegations_to_visit) > 0 | |
): | |
if len(delegations_to_visit) > 0: |
I like the simplification you did, and I think this now seems clear... if we have delegations to visit at this point, we must have aborted because max delegations or do I misunderstand?
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 correct, I've missed it.
Reduce the number of variables in the while loop by using len(visited_role_names) instead of number_of_delegations. Include equality in the comparison with config.max_delegations to account for visiting "targets". Shorten the commit message. Add max number of delegations test case. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Extend test_updater_delegation_graphs.py with tests for targets metadata search. - create a new test class TestTargetFileSearch which creates a single repository and pefrorms multiple file searches in subtests. - group the common functionality in a base class TestDelegations. - extend the data classes to accomodate for target_files. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Extend TestDelegationsGraphs with a test case for unsigned metadata. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Using a raw string allows the use of backslashes in the docstring comment whithout them being interpreted as an escape character. It also silences pylint W1401: anomalous-backslash-in-string. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Use a dataclass for a better visual representation of the test case data set. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
a0e74c1
to
36eaffa
Compare
Thanks for the suggestions, I find them very reasonable, I did several changes to include them. |
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 like it. TestTargetFileSearch is quite complex and requires reader to spend some time to figure it out but I think that's just because this is the most complex thing the client does.
Left a comment about the delegation loop change, please have look. I think your version is fine though.
|
||
# Preorder depth-first traversal of the graph of target delegations. | ||
while number_of_delegations > 0 and len(delegations_to_visit) > 0: | ||
while ( | ||
len(visited_role_names) <= self.config.max_delegations |
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.
now that I look at this again... doesn't this handle one more delegation than it used to?
The new interpretation could be the correct one (with the assumption that only delegated targets are counted so "targets" itself is not a delegation), just wanted to make sure we're not making a mistake. The test you added for max delegations feels correct to me so I guess I'm ok with this interpretation.
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, in the previous implementation "targets" was counted in the delegations number which I noticed only after adding the test. So I changed a bit the implementation using "<=" here to compensate for targets. I think I mentioned it in the commit message but I can try adding a comment?
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 you did, I just did not understand the connection...
WIP since it is built on top of #1689Fixes #1641
Description of the changes being introduced by the pull request:
Extend test_delegation_graphs with tests for:
Please verify and check that the pull request fulfills the following
requirements: