github.com/deis/deis@v1.13.5-0.20170519182049-1d9e59fbdbfc/Godeps/_workspace/src/golang.org/x/crypto/ssh/cipher_test.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package ssh 6 7 import ( 8 "bytes" 9 "crypto" 10 "crypto/rand" 11 "testing" 12 ) 13 14 func TestDefaultCiphersExist(t *testing.T) { 15 for _, cipherAlgo := range supportedCiphers { 16 if _, ok := cipherModes[cipherAlgo]; !ok { 17 t.Errorf("default cipher %q is unknown", cipherAlgo) 18 } 19 } 20 } 21 22 func TestPacketCiphers(t *testing.T) { 23 for cipher := range cipherModes { 24 kr := &kexResult{Hash: crypto.SHA1} 25 algs := directionAlgorithms{ 26 Cipher: cipher, 27 MAC: "hmac-sha1", 28 Compression: "none", 29 } 30 client, err := newPacketCipher(clientKeys, algs, kr) 31 if err != nil { 32 t.Errorf("newPacketCipher(client, %q): %v", cipher, err) 33 continue 34 } 35 server, err := newPacketCipher(clientKeys, algs, kr) 36 if err != nil { 37 t.Errorf("newPacketCipher(client, %q): %v", cipher, err) 38 continue 39 } 40 41 want := "bla bla" 42 input := []byte(want) 43 buf := &bytes.Buffer{} 44 if err := client.writePacket(0, buf, rand.Reader, input); err != nil { 45 t.Errorf("writePacket(%q): %v", cipher, err) 46 continue 47 } 48 49 packet, err := server.readPacket(0, buf) 50 if err != nil { 51 t.Errorf("readPacket(%q): %v", cipher, err) 52 continue 53 } 54 55 if string(packet) != want { 56 t.Errorf("roundtrip(%q): got %q, want %q", cipher, packet, want) 57 } 58 } 59 }