github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cli/interactive_tests/test_error_hints.tcl (about)

     1  #! /usr/bin/env expect -f
     2  
     3  source [file join [file dirname $argv0] common.tcl]
     4  
     5  set fakeserv [file join [file dirname $argv0] netcat.py]
     6  
     7  # We'll override security defaults below.
     8  set certs_dir "/certs"
     9  set ::env(COCKROACH_INSECURE) "false"
    10  
    11  spawn /bin/bash
    12  set shell_spawn_id $spawn_id
    13  
    14  send "PS1=':''/# '\r"
    15  eexpect ":/# "
    16  
    17  # Check what happens when attempting to connect and the server does not exist.
    18  
    19  start_test "Connecting a RPC client to a non-started server"
    20  send "$argv quit\r"
    21  eexpect "ERROR: cannot load certificates.\r\nCheck your certificate settings"
    22  eexpect "or use --insecure"
    23  eexpect ":/# "
    24  
    25  send "$argv quit --certs-dir=$certs_dir\r"
    26  eexpect "ERROR: cannot dial server.\r\nIs the server running?"
    27  eexpect "connection refused"
    28  eexpect ":/# "
    29  end_test
    30  
    31  start_test "Connecting a SQL client to a non-started server"
    32  send "$argv sql -e 'select 1'\r"
    33  eexpect "ERROR: cannot load certificates.\r\nCheck your certificate settings"
    34  eexpect "or use --insecure"
    35  eexpect ":/# "
    36  
    37  send "$argv sql -e 'select 1' --certs-dir=$certs_dir\r"
    38  eexpect "ERROR: cannot dial server.\r\nIs the server running?"
    39  eexpect "connection refused"
    40  eexpect ":/# "
    41  end_test
    42  
    43  # Check what happens when attempting to connect securely to an
    44  # insecure server.
    45  
    46  send "$argv start-single-node --insecure\r"
    47  eexpect "initialized new cluster"
    48  
    49  spawn /bin/bash
    50  set client_spawn_id $spawn_id
    51  
    52  send "PS1=':''/# '\r"
    53  eexpect ":/# "
    54  
    55  start_test "Connecting a secure RPC client to an insecure server"
    56  send "$argv quit --certs-dir=$certs_dir\r"
    57  eexpect "ERROR: cannot establish secure connection to insecure server."
    58  eexpect "Maybe use --insecure?"
    59  eexpect ":/# "
    60  end_test
    61  
    62  start_test "Connecting a secure SQL client to an insecure server"
    63  send "$argv sql -e 'select 1' --certs-dir=$certs_dir\r"
    64  eexpect "ERROR: cannot establish secure connection to insecure server."
    65  eexpect ":/# "
    66  end_test
    67  
    68  # Check what happens when attempting to connect insecurely to a secure
    69  # server.
    70  
    71  set spawn_id $shell_spawn_id
    72  interrupt
    73  interrupt
    74  eexpect ":/# "
    75  
    76  send "$argv start-single-node --listen-addr=localhost --certs-dir=$certs_dir\r"
    77  eexpect "restarted pre-existing node"
    78  
    79  set spawn_id $client_spawn_id
    80  
    81  start_test "Connecting an insecure RPC client to a secure server"
    82  send "$argv quit --insecure\r"
    83  eexpect "ERROR: server closed the connection."
    84  eexpect "remove --insecure"
    85  eexpect ":/# "
    86  end_test
    87  
    88  start_test "Connecting an insecure SQL client to a secure server"
    89  send "$argv sql -e 'select 1' --insecure\r"
    90  eexpect "ERROR: SSL authentication error while connecting."
    91  eexpect "remove --insecure"
    92  eexpect ":/# "
    93  end_test
    94  
    95  # Check what happens when attempting to connect to something
    96  # that is not a CockroachDB server.
    97  set spawn_id $shell_spawn_id
    98  interrupt
    99  interrupt
   100  eexpect ":/# "
   101  
   102  start_test "Connecting an insecure RPC client to a non-CockroachDB server"
   103  # In one shell, start a bogus server
   104  send "python2 $fakeserv\r"
   105  eexpect "ready"
   106  # In the other shell, try to run cockroach quit
   107  set spawn_id $client_spawn_id
   108  send "$argv quit --insecure\r"
   109  eexpect "insecure\r\n"
   110  # Wait to see an HTTP/2.0 header on the fake server, then stop the server.
   111  set spawn_id $shell_spawn_id
   112  eexpect "connected"
   113  eexpect "PRI * HTTP/2.0"
   114  interrupt
   115  eexpect ":/# "
   116  # Check that cockroach quit becomes suitably confused.
   117  set spawn_id $client_spawn_id
   118  eexpect "ERROR: server closed the connection."
   119  eexpect "Is this a CockroachDB node?"
   120  eexpect ":/# "
   121  set spawn_id $shell_spawn_id
   122  end_test
   123  
   124  start_test "Connecting an insecure SQL client to a non-CockroachDB server"
   125  # In one shell, start a bogus server
   126  send "python2 $fakeserv\r"
   127  eexpect "ready"
   128  # In the other shell, try to run cockroach sql
   129  set spawn_id $client_spawn_id
   130  send "$argv sql -e 'select 1' --insecure\r"
   131  eexpect "insecure\r\n"
   132  # In the first shell, wait for netcat to receive garbage,
   133  # then kill it
   134  set spawn_id $shell_spawn_id
   135  eexpect "connected"
   136  eexpect "cockroach sql"
   137  interrupt
   138  eexpect ":/# "
   139  # Check that cockroach sql becomes suitably confused.
   140  set spawn_id $client_spawn_id
   141  eexpect "ERROR: server closed the connection."
   142  eexpect "Is this a CockroachDB node?"
   143  eexpect "EOF"
   144  eexpect ":/# "
   145  set spawn_id $shell_spawn_id
   146  end_test
   147  
   148  
   149  # clean up the background processes
   150  set spawn_id $shell_spawn_id
   151  send "exit\r"
   152  eexpect eof
   153  
   154  set spawn_id $client_spawn_id
   155  send "exit\r"
   156  eexpect eof