common_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. package ssh
  5. import (
  6. "io"
  7. "net"
  8. "testing"
  9. )
  10. func TestSafeString(t *testing.T) {
  11. strings := map[string]string{
  12. "\x20\x0d\x0a": "\x20\x0d\x0a",
  13. "flibble": "flibble",
  14. "new\x20line": "new\x20line",
  15. "123456\x07789": "123456 789",
  16. "\t\t\x10\r\n": "\t\t \r\n",
  17. }
  18. for s, expected := range strings {
  19. actual := safeString(s)
  20. if expected != actual {
  21. t.Errorf("expected: %v, actual: %v", []byte(expected), []byte(actual))
  22. }
  23. }
  24. }
  25. // Make sure Read/Write are not exposed.
  26. func TestConnHideRWMethods(t *testing.T) {
  27. for _, c := range []interface{}{new(ServerConn), new(ClientConn)} {
  28. if _, ok := c.(io.Reader); ok {
  29. t.Errorf("%T implements io.Reader", c)
  30. }
  31. if _, ok := c.(io.Writer); ok {
  32. t.Errorf("%T implements io.Writer", c)
  33. }
  34. }
  35. }
  36. func TestConnSupportsLocalRemoteMethods(t *testing.T) {
  37. type LocalAddr interface {
  38. LocalAddr() net.Addr
  39. }
  40. type RemoteAddr interface {
  41. RemoteAddr() net.Addr
  42. }
  43. for _, c := range []interface{}{new(ServerConn), new(ClientConn)} {
  44. if _, ok := c.(LocalAddr); !ok {
  45. t.Errorf("%T does not implement LocalAddr", c)
  46. }
  47. if _, ok := c.(RemoteAddr); !ok {
  48. t.Errorf("%T does not implement RemoteAddr", c)
  49. }
  50. }
  51. }