MCPcopy
hub / github.com/tailscale/tailscale / TestMaxAuthTriesNoneMethod

Function TestMaxAuthTriesNoneMethod

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

Source from the content-addressed store, hash-verified

68}
69
70func TestMaxAuthTriesNoneMethod(t *testing.T) {
71 username := "testuser"
72 serverConfig := &ServerConfig{
73 MaxAuthTries: 2,
74 PasswordCallback: func(conn ConnMetadata, password []byte) (*Permissions, error) {
75 if conn.User() == username && string(password) == clientPassword {
76 return nil, nil
77 }
78 return nil, errors.New("invalid credentials")
79 },
80 }
81 c1, c2, err := netPipe()
82 if err != nil {
83 t.Fatalf("netPipe: %v", err)
84 }
85 defer c1.Close()
86 defer c2.Close()
87
88 var serverAuthErrors []error
89
90 serverConfig.AddHostKey(testSigners["rsa"])
91 serverConfig.AuthLogCallback = func(conn ConnMetadata, method string, err error) {
92 serverAuthErrors = append(serverAuthErrors, err)
93 }
94 go newServer(c1, serverConfig)
95
96 clientConfig := ClientConfig{
97 User: username,
98 HostKeyCallback: InsecureIgnoreHostKey(),
99 }
100 clientConfig.SetDefaults()
101 // Our client will send 'none' auth only once, so we need to send the
102 // requests manually.
103 c := &connection{
104 sshConn: sshConn{
105 conn: c2,
106 user: username,
107 clientVersion: []byte(packageVersion),
108 },
109 }
110 c.serverVersion, err = exchangeVersions(c.sshConn.conn, c.clientVersion)
111 if err != nil {
112 t.Fatalf("unable to exchange version: %v", err)
113 }
114 c.transport = newClientTransport(
115 newTransport(c.sshConn.conn, clientConfig.Rand, true /* is client */),
116 c.clientVersion, c.serverVersion, &clientConfig, "", c.sshConn.RemoteAddr())
117 if err := c.transport.waitSession(); err != nil {
118 t.Fatalf("unable to wait session: %v", err)
119 }
120 c.sessionID = c.transport.getSessionID()
121 if err := c.transport.writePacket(Marshal(&serviceRequestMsg{serviceUserAuth})); err != nil {
122 t.Fatalf("unable to send ssh-userauth message: %v", err)
123 }
124 packet, err := c.transport.readPacket()
125 if err != nil {
126 t.Fatal(err)
127 }

Callers

nothing calls this directly

Calls 15

AddHostKeyMethod · 0.95
netPipeFunction · 0.85
newServerFunction · 0.85
InsecureIgnoreHostKeyFunction · 0.85
exchangeVersionsFunction · 0.85
newClientTransportFunction · 0.85
newTransportFunction · 0.85
MarshalFunction · 0.85
UnmarshalFunction · 0.85
SetDefaultsMethod · 0.80
waitSessionMethod · 0.80
UserMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…