mirror of
https://github.com/golang/go
synced 2024-09-30 11:18:33 -06:00
crypto/tls: test that Clone copies session ticket key fields
Updates #25256 Change-Id: If16c42581f1cf3500fd7fd01c915e487f8025e55 Reviewed-on: https://go-review.googlesource.com/c/go/+/235922 Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org>
This commit is contained in:
parent
73dd74a9fe
commit
23dcee6464
@ -785,11 +785,6 @@ func TestCloneNonFuncFields(t *testing.T) {
|
|||||||
typ := v.Type()
|
typ := v.Type()
|
||||||
for i := 0; i < typ.NumField(); i++ {
|
for i := 0; i < typ.NumField(); i++ {
|
||||||
f := v.Field(i)
|
f := v.Field(i)
|
||||||
if !f.CanSet() {
|
|
||||||
// unexported field; not cloned.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// testing/quick can't handle functions or interfaces and so
|
// testing/quick can't handle functions or interfaces and so
|
||||||
// isn't used here.
|
// isn't used here.
|
||||||
switch fn := typ.Field(i).Name; fn {
|
switch fn := typ.Field(i).Name; fn {
|
||||||
@ -830,17 +825,17 @@ func TestCloneNonFuncFields(t *testing.T) {
|
|||||||
f.Set(reflect.ValueOf([]CurveID{CurveP256}))
|
f.Set(reflect.ValueOf([]CurveID{CurveP256}))
|
||||||
case "Renegotiation":
|
case "Renegotiation":
|
||||||
f.Set(reflect.ValueOf(RenegotiateOnceAsClient))
|
f.Set(reflect.ValueOf(RenegotiateOnceAsClient))
|
||||||
|
case "mutex", "autoSessionTicketKeys", "sessionTicketKeys":
|
||||||
|
continue // these are unexported fields that are handled separately
|
||||||
default:
|
default:
|
||||||
t.Errorf("all fields must be accounted for, but saw unknown field %q", fn)
|
t.Errorf("all fields must be accounted for, but saw unknown field %q", fn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Set the unexported fields related to session ticket keys, which are copied with Clone().
|
||||||
|
c1.autoSessionTicketKeys = []ticketKey{c1.ticketKeyFromBytes(c1.SessionTicketKey)}
|
||||||
|
c1.sessionTicketKeys = []ticketKey{c1.ticketKeyFromBytes(c1.SessionTicketKey)}
|
||||||
|
|
||||||
c2 := c1.Clone()
|
c2 := c1.Clone()
|
||||||
// DeepEqual also compares unexported fields, thus c2 needs to have run
|
|
||||||
// serverInit in order to be DeepEqual to c1. Cloning it and discarding
|
|
||||||
// the result is sufficient.
|
|
||||||
c2.Clone()
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(&c1, c2) {
|
if !reflect.DeepEqual(&c1, c2) {
|
||||||
t.Errorf("clone failed to copy a field")
|
t.Errorf("clone failed to copy a field")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user