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

Add test cases documenting CBOR's behaviour with omitted and extra fields #6880

Merged
merged 6 commits into from
Jan 21, 2025

Conversation

jordanschalm
Copy link
Member

@jordanschalm jordanschalm commented Jan 13, 2025

This PR adds two test cases to the CBOR codec package which document the behaviour of the CBOR decoding mode used for the networking layer.

@jordanschalm jordanschalm requested a review from a team as a code owner January 13, 2025 23:01
@codecov-commenter
Copy link

codecov-commenter commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 41.07%. Comparing base (8c170e3) to head (f03b83e).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6880      +/-   ##
==========================================
- Coverage   41.09%   41.07%   -0.02%     
==========================================
  Files        2121     2121              
  Lines      185912   185912              
==========================================
- Hits        76395    76360      -35     
- Misses     103104   103137      +33     
- Partials     6413     6415       +2     
Flag Coverage Δ
unittests 41.07% <ø> (-0.02%) ⬇️

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

@AlexHentschel AlexHentschel left a comment

Choose a reason for hiding this comment

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

Very nice demonstration of behaviour

network/codec/cbor/cbor_behaviour_test.go Outdated Show resolved Hide resolved
network/codec/cbor/cbor_behaviour_test.go Outdated Show resolved Hide resolved
network/codec/cbor/cbor_behaviour_test.go Outdated Show resolved Hide resolved
network/codec/cbor/cbor_behaviour_test.go Outdated Show resolved Hide resolved
assert.NoError(t, err)

var m1 model1
err = defaultDecMode.Unmarshal(bz, &m1)
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 great to use the decoding mode defined in the package

// NetworkDecMode is the DecMode used for decoding messages over the network.
// It returns an error if the message contains any extra field not present in the
// target (struct we are unmarshalling into), which prevents some classes of spamming.
var NetworkDecMode, _ = cbor.DecOptions{ExtraReturnErrors: cbor.ExtraDecErrorUnknownField}.DecMode()

Copy link
Member Author

Choose a reason for hiding this comment

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

That isn't defined on this branch, but we'll get this outcome when merging the feature branch.

network/codec/cbor/cbor_behaviour_test.go Show resolved Hide resolved
@jordanschalm jordanschalm added this pull request to the merge queue Jan 21, 2025
Merged via the queue into master with commit 795645f Jan 21, 2025
56 checks passed
@jordanschalm jordanschalm deleted the jord/cbor-codec-behaviour branch January 21, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants