MCPcopy
hub / github.com/tailscale/tailscale / TestBannerError

Function TestBannerError

tempfork/sshtest/ssh/server_test.go:231–301  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

229}
230
231func TestBannerError(t *testing.T) {
232 serverConfig := &ServerConfig{
233 BannerCallback: func(ConnMetadata) string {
234 return "banner from BannerCallback"
235 },
236 NoClientAuth: true,
237 NoClientAuthCallback: func(ConnMetadata) (*Permissions, error) {
238 err := &BannerError{
239 Err: errors.New("error from NoClientAuthCallback"),
240 Message: "banner from NoClientAuthCallback",
241 }
242 return nil, fmt.Errorf("wrapped: %w", err)
243 },
244 PasswordCallback: func(conn ConnMetadata, password []byte) (*Permissions, error) {
245 return &Permissions{}, nil
246 },
247 PublicKeyCallback: func(conn ConnMetadata, key PublicKey) (*Permissions, error) {
248 return nil, &BannerError{
249 Err: errors.New("error from PublicKeyCallback"),
250 Message: "banner from PublicKeyCallback",
251 }
252 },
253 KeyboardInteractiveCallback: func(conn ConnMetadata, client KeyboardInteractiveChallenge) (*Permissions, error) {
254 return nil, &BannerError{
255 Err: nil, // make sure that a nil inner error is allowed
256 Message: "banner from KeyboardInteractiveCallback",
257 }
258 },
259 }
260 serverConfig.AddHostKey(testSigners["rsa"])
261
262 var banners []string
263 clientConfig := &ClientConfig{
264 User: "test",
265 Auth: []AuthMethod{
266 PublicKeys(testSigners["rsa"]),
267 KeyboardInteractive(func(name, instruction string, questions []string, echos []bool) ([]string, error) {
268 return []string{"letmein"}, nil
269 }),
270 Password(clientPassword),
271 },
272 HostKeyCallback: InsecureIgnoreHostKey(),
273 BannerCallback: func(msg string) error {
274 banners = append(banners, msg)
275 return nil
276 },
277 }
278
279 c1, c2, err := netPipe()
280 if err != nil {
281 t.Fatalf("netPipe: %v", err)
282 }
283 defer c1.Close()
284 defer c2.Close()
285 go newServer(c1, serverConfig)
286 c, _, _, err := NewClientConn(c2, "", clientConfig)
287 if err != nil {
288 t.Fatalf("client connection failed: %v", err)

Callers

nothing calls this directly

Calls 12

AddHostKeyMethod · 0.95
PublicKeysFunction · 0.85
KeyboardInteractiveFunction · 0.85
PasswordFunction · 0.85
InsecureIgnoreHostKeyFunction · 0.85
netPipeFunction · 0.85
newServerFunction · 0.85
NewClientConnFunction · 0.85
ErrorfMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…