|
| 1 | +// Copyright 2012 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 | + |
| 5 | +// +build !windows,!solaris,!js |
| 6 | + |
| 7 | +package test |
| 8 | + |
| 9 | +import ( |
| 10 | + "sync" |
| 11 | + "testing" |
| 12 | + |
| 13 | + "golang.org/x/crypto/ssh" |
| 14 | +) |
| 15 | + |
| 16 | +// Concurrent functional tests. |
| 17 | + |
| 18 | +// This test needs to be executed using the race detector in order to be effective. |
| 19 | +// #37607 |
| 20 | +func TestRunConcurrent(t *testing.T) { |
| 21 | + affectedKex := []string{"diffie-hellman-group-exchange-sha1", "diffie-hellman-group-exchange-sha256"} |
| 22 | + |
| 23 | + var config ssh.Config |
| 24 | + config.SetDefaults() |
| 25 | + kexOrder := config.KeyExchanges |
| 26 | + // Based on the discussion in #17230, the key exchange algorithms |
| 27 | + // diffie-hellman-group-exchange-sha1 and diffie-hellman-group-exchange-sha256 |
| 28 | + // are not included in the default list of supported kex so we have to add them |
| 29 | + // here manually. |
| 30 | + kexOrder = append(kexOrder, affectedKex...) |
| 31 | + for _, kex := range affectedKex { |
| 32 | + t.Run(kex, func(t *testing.T) { |
| 33 | + wg := sync.WaitGroup{} |
| 34 | + for i := 0; i < 3; i++ { |
| 35 | + wg.Add(1) |
| 36 | + go func() { |
| 37 | + defer wg.Done() |
| 38 | + server := newServer(t) |
| 39 | + defer server.Shutdown() |
| 40 | + |
| 41 | + conf := clientConfig() |
| 42 | + // Don't fail if sshd doesn't have the kex. |
| 43 | + conf.KeyExchanges = append([]string{kex}, kexOrder...) |
| 44 | + conn, err := server.TryDial(conf) |
| 45 | + if err == nil { |
| 46 | + conn.Close() |
| 47 | + } else { |
| 48 | + t.Errorf("failed for kex %q", kex) |
| 49 | + } |
| 50 | + }() |
| 51 | + } |
| 52 | + wg.Wait() |
| 53 | + }) |
| 54 | + } |
| 55 | +} |
0 commit comments