context_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //go:build glidertests
  2. package ssh
  3. import "testing"
  4. func TestSetPermissions(t *testing.T) {
  5. t.Parallel()
  6. permsExt := map[string]string{
  7. "foo": "bar",
  8. }
  9. session, _, cleanup := newTestSessionWithOptions(t, &Server{
  10. Handler: func(s Session) {
  11. if _, ok := s.Permissions().Extensions["foo"]; !ok {
  12. t.Fatalf("got %#v; want %#v", s.Permissions().Extensions, permsExt)
  13. }
  14. },
  15. }, nil, PasswordAuth(func(ctx Context, password string) bool {
  16. ctx.Permissions().Extensions = permsExt
  17. return true
  18. }))
  19. defer cleanup()
  20. if err := session.Run(""); err != nil {
  21. t.Fatal(err)
  22. }
  23. }
  24. func TestSetValue(t *testing.T) {
  25. t.Parallel()
  26. value := map[string]string{
  27. "foo": "bar",
  28. }
  29. key := "testValue"
  30. session, _, cleanup := newTestSessionWithOptions(t, &Server{
  31. Handler: func(s Session) {
  32. v := s.Context().Value(key).(map[string]string)
  33. if v["foo"] != value["foo"] {
  34. t.Fatalf("got %#v; want %#v", v, value)
  35. }
  36. },
  37. }, nil, PasswordAuth(func(ctx Context, password string) bool {
  38. ctx.SetValue(key, value)
  39. return true
  40. }))
  41. defer cleanup()
  42. if err := session.Run(""); err != nil {
  43. t.Fatal(err)
  44. }
  45. }