-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
DNS Update Misc #154
Merged
Merged
DNS Update Misc #154
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
414013f
Add test covering unpacking 0-length rdatas
andrewtj 71436da
Make TestDynamicUpdateZeroRdataUnpack pass
andrewtj ffe24e6
Test that Msg.RemoveRRset() works as intended
andrewtj 104b206
Make RemoveRRset work as intended
andrewtj 022d2d4
Lose a loop in Msg.RemoveRRset() and use copyHeader()
andrewtj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package dns | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
|
@@ -34,3 +35,71 @@ func TestDynamicUpdateUnpack(t *testing.T) { | |
t.Fail() | ||
} | ||
} | ||
|
||
func TestDynamicUpdateZeroRdataUnpack(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests look good. |
||
m := new(Msg) | ||
rr := &RR_Header{Name: ".", Rrtype: 0, Class: 1, Ttl: ^uint32(0), Rdlength: 0} | ||
m.Answer = []RR{rr, rr, rr, rr, rr} | ||
m.Ns = m.Answer | ||
for n, s := range TypeToString { | ||
rr.Rrtype = n | ||
bytes, err := m.Pack() | ||
if err != nil { | ||
t.Logf("failed to pack %s: %v", s, err) | ||
t.Fail() | ||
continue | ||
} | ||
if err := new(Msg).Unpack(bytes); err != nil { | ||
t.Logf("failed to unpack %s: %v", s, err) | ||
t.Fail() | ||
} | ||
} | ||
} | ||
|
||
func TestRemoveRRset(t *testing.T) { | ||
// Should add a zero data RR in Class ANY with a TTL of 0 | ||
// for each set mentioned in the RRs provided to it. | ||
rr, err := NewRR(". 100 IN A 127.0.0.1") | ||
if err != nil { | ||
t.Fatalf("Error constructing RR: %v", err) | ||
} | ||
m := new(Msg) | ||
m.Ns = []RR{&RR_Header{Name: ".", Rrtype: TypeA, Class: ClassANY, Ttl: 0, Rdlength: 0}} | ||
expectstr := m.String() | ||
expect, err := m.Pack() | ||
if err != nil { | ||
t.Fatalf("Error packing expected msg: %v", err) | ||
} | ||
|
||
m.Ns = nil | ||
m.RemoveRRset([]RR{rr}) | ||
actual, err := m.Pack() | ||
if err != nil { | ||
t.Fatalf("Error packing actual msg: %v", err) | ||
} | ||
if !bytes.Equal(actual, expect) { | ||
tmp := new(Msg) | ||
if err := tmp.Unpack(actual); err != nil { | ||
t.Fatalf("Error unpacking actual msg: %v", err) | ||
} | ||
t.Logf("Expected msg:\n%s", expectstr) | ||
t.Logf("Actual msg:\n%v", tmp) | ||
t.Fail() | ||
} | ||
|
||
m.Ns = nil | ||
m.RemoveRRset([]RR{rr, rr}) | ||
actual, err = m.Pack() | ||
if err != nil { | ||
t.Fatalf("Error packing actual msg: %v", err) | ||
} | ||
if !bytes.Equal(actual, expect) { | ||
tmp := new(Msg) | ||
if err := tmp.Unpack(actual); err != nil { | ||
t.Fatalf("Error unpacking actual msg: %v", err) | ||
} | ||
t.Logf("Expected msg:\n%v", expectstr) | ||
t.Logf("Actual msg:\n%v", tmp) | ||
t.Fail() | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 this is indeed valid and the other lenrd == off uses could be removed, but I'll need to check.