File: context_test.go

package info (click to toggle)
golang-github-gliderlabs-ssh 0.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 240 kB
  • sloc: makefile: 3
file content (47 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package ssh

import "testing"

func TestSetPermissions(t *testing.T) {
	t.Parallel()
	permsExt := map[string]string{
		"foo": "bar",
	}
	session, _, cleanup := newTestSessionWithOptions(t, &Server{
		Handler: func(s Session) {
			if _, ok := s.Permissions().Extensions["foo"]; !ok {
				t.Fatalf("got %#v; want %#v", s.Permissions().Extensions, permsExt)
			}
		},
	}, nil, PasswordAuth(func(ctx Context, password string) bool {
		ctx.Permissions().Extensions = permsExt
		return true
	}))
	defer cleanup()
	if err := session.Run(""); err != nil {
		t.Fatal(err)
	}
}

func TestSetValue(t *testing.T) {
	t.Parallel()
	value := map[string]string{
		"foo": "bar",
	}
	key := "testValue"
	session, _, cleanup := newTestSessionWithOptions(t, &Server{
		Handler: func(s Session) {
			v := s.Context().Value(key).(map[string]string)
			if v["foo"] != value["foo"] {
				t.Fatalf("got %#v; want %#v", v, value)
			}
		},
	}, nil, PasswordAuth(func(ctx Context, password string) bool {
		ctx.SetValue(key, value)
		return true
	}))
	defer cleanup()
	if err := session.Run(""); err != nil {
		t.Fatal(err)
	}
}