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

Fix notary keys requests for all keys #3296

Merged
merged 5 commits into from
Jan 8, 2024
Merged

Conversation

S7evinK
Copy link
Contributor

@S7evinK S7evinK commented Jan 6, 2024

This should be more spec compliant:

If no key IDs are given to be queried, the notary server should query for all keys.

@S7evinK S7evinK added spec-compliance Fix something that doesn't comply with the specs T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. labels Jan 6, 2024
@S7evinK S7evinK requested a review from a team as a code owner January 6, 2024 20:13
Copy link

codecov bot commented Jan 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (edd02ec) 65.74% compared to head (efe8094) 65.71%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3296      +/-   ##
==========================================
- Coverage   65.74%   65.71%   -0.04%     
==========================================
  Files         509      509              
  Lines       57464    57471       +7     
==========================================
- Hits        37780    37767      -13     
- Misses      15855    15871      +16     
- Partials     3829     3833       +4     
Flag Coverage Δ
unittests 50.06% <100.00%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@kegsay kegsay left a comment

Choose a reason for hiding this comment

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

Please add additional testing for the null vs [] edge case.

validateFunc: func(t *testing.T, resp util.JSONResponse) {
want := util.JSONResponse{
Code: http.StatusBadRequest,
JSON: spec.BadJSON("The request body could not be decoded into valid JSON. unexpected end of JSON input"),
Copy link
Member

Choose a reason for hiding this comment

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

It would be nicer to assert the error code and not the entire error message, as that is pretty brittle.

@@ -43,6 +43,15 @@ func (a *FederationInternalAPI) fetchServerKeysFromCache(
ctx context.Context, req *api.QueryServerKeysRequest,
) ([]gomatrixserverlib.ServerKeys, error) {
var results []gomatrixserverlib.ServerKeys

// We got a request for _all_ server keys, return them.
if len(req.KeyIDToCriteria) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Technically {"server_keys":{"servera":null}} will then be treated as getting all keys.

var response struct {
ServerKeys []json.RawMessage `json:"server_keys"`
}
response.ServerKeys = []json.RawMessage{}
Copy link
Member

Choose a reason for hiding this comment

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

Bad refactor. You forgot to do this, so no keys will be server_keys: null not server_keys: [].

@S7evinK S7evinK merged commit 13c5173 into main Jan 8, 2024
20 checks passed
@S7evinK S7evinK deleted the s7evink/notary-keys-fix branch January 8, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec-compliance Fix something that doesn't comply with the specs T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants