Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(549)

Delta Between Two Patch Sets: ssh/messages_test.go

Issue 14767043: code review 14767043: go.crypto/ssh: additional coverage of message unmarshaling (Closed)
Left Patch Set: Created 10 years, 5 months ago
Right Patch Set: diff -r 32844aa1ae54 https://code.google.com/p/go.crypto Created 10 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package ssh 5 package ssh
6 6
7 import ( 7 import (
8 "math/big" 8 "math/big"
9 "math/rand" 9 "math/rand"
10 "reflect" 10 "reflect"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 if err := unmarshal(m2, marshaled, msgIgnore); err != ni l { 68 if err := unmarshal(m2, marshaled, msgIgnore); err != ni l {
69 t.Errorf("#%d failed to unmarshal %#v: %s", i, m 1, err) 69 t.Errorf("#%d failed to unmarshal %#v: %s", i, m 1, err)
70 break 70 break
71 } 71 }
72 72
73 if !reflect.DeepEqual(v.Interface(), m2) { 73 if !reflect.DeepEqual(v.Interface(), m2) {
74 t.Errorf("#%d\ngot: %#v\nwant:%#v\n%x", i, m2, m 1, marshaled) 74 t.Errorf("#%d\ngot: %#v\nwant:%#v\n%x", i, m2, m 1, marshaled)
75 break 75 break
76 } 76 }
77 } 77 }
78 }
79 }
80
81 func TestUnmarshalEmptyPacket(t *testing.T) {
82 var b []byte
83 var m channelRequestSuccessMsg
84 err := unmarshal(&m, b, msgChannelRequest)
85 want := ParseError{msgChannelRequest}
86 if _, ok := err.(ParseError); !ok {
87 t.Fatalf("got %T, want %T", err, want)
88 }
89 if got := err.(ParseError); want != got {
90 t.Fatal("got %#v, want %#v", got, want)
91 }
92 }
93
94 func TestUnmarshalUnexpectedPacket(t *testing.T) {
95 type S struct {
96 I uint32
97 S string
98 B bool
99 }
100
101 s := S{42, "hello", true}
102 packet := marshal(42, s)
103 roundtrip := S{}
104 err := unmarshal(&roundtrip, packet, 43)
105 if err == nil {
106 t.Fatal("expected error, not nil")
107 }
108 want := UnexpectedMessageError{43, 42}
109 if got, ok := err.(UnexpectedMessageError); !ok || want != got {
110 t.Fatal("expected %q, got %q", want, got)
78 } 111 }
79 } 112 }
80 113
81 func TestBareMarshalUnmarshal(t *testing.T) { 114 func TestBareMarshalUnmarshal(t *testing.T) {
82 type S struct { 115 type S struct {
83 I uint32 116 I uint32
84 S string 117 S string
85 B bool 118 B bool
86 } 119 }
87 120
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 marshal(msgKexDHInit, _kexDHInitMsg) 223 marshal(msgKexDHInit, _kexDHInitMsg)
191 } 224 }
192 } 225 }
193 226
194 func BenchmarkUnmarshalKexDHInitMsg(b *testing.B) { 227 func BenchmarkUnmarshalKexDHInitMsg(b *testing.B) {
195 m := new(kexDHInitMsg) 228 m := new(kexDHInitMsg)
196 for i := 0; i < b.N; i++ { 229 for i := 0; i < b.N; i++ {
197 unmarshal(m, _kexDHInit, msgKexDHInit) 230 unmarshal(m, _kexDHInit, msgKexDHInit)
198 } 231 }
199 } 232 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b