mirror of
https://github.com/slackhq/nebula.git
synced 2026-11-15 07:46:52 +01:00
smoke-extra / freebsd-amd64 (push) Failing after 14s
smoke-extra / linux-amd64-ipv6disable (push) Failing after 13s
smoke-extra / netbsd-amd64 (push) Failing after 14s
smoke-extra / openbsd-amd64 (push) Failing after 15s
smoke-extra / linux-386 (push) Failing after 14s
smoke / Run multi node smoke test (push) Failing after 1m46s
Build and test / Static checks (push) Successful in 2m38s
Build and test / Test linux (push) Failing after 1m12s
Build and test / Test linux-pkcs11 (push) Failing after 2m6s
Build and test / Test linux-boringcrypto (push) Failing after 3m0s
Build and test / Test linux-fips140 (push) Failing after 2m56s
Build and test / Cross-build linux-arm (push) Successful in 3m10s
Build and test / Cross-build linux-mips (push) Successful in 3m55s
Build and test / Cross-build linux-other (push) Successful in 3m15s
Build and test / Cross-build windows (push) Successful in 1m5s
Build and test / Cross-build freebsd (push) Successful in 1m37s
Build and test / Cross-build netbsd (push) Successful in 1m36s
Build and test / Cross-build openbsd (push) Successful in 1m35s
Build and test / Cross-build mobile (push) Successful in 3m32s
smoke-extra / Run windows smoke test (push) Canceled after 0s
smoke / Run self traffic smoke test on macOS (push) Canceled after 0s
Build and test / Test macos (push) Canceled after 0s
Build and test / Test windows (push) Canceled after 0s
Build and test / CI status (push) Canceled after 0s
Report ssh command failures to the surface (#1959) The ssh debug commands told the user when something went wrong but never told the surface that ran them, so `ssh host cmd` always exited 0 and a few failures were not reported at all. A failed command now returns its error, a failure the user has already heard about is a commands.Failure, and the ssh exec path exits 1 for either. The command bodies also lose their ssh prefixes and the duplication they carried over from ssh.go; both goldens pin that nothing else changed. - Dispatch returns the callback's error, or shlex's; the ssh session logs it at debug, and not at all for a Failure the user already saw - commands.Fail writes a message and returns it as a Failure in one step; an unknown command, `help` for a command that is not there, a failed reload and an unbalanced quote are failures - ssh exec exit-status is 1 for a command, flag or failure error, 0 otherwise; the e2e golden records the exit status for every case - Clone rebinds help to the copy, so an ssh session's help lists logout and `help logout` and `logout -h` answer; sshd.LogoutCommand is the session's logout, exported for tests - "did not understand" names the first word only, the one looked up; DispatchArgs takes just the tokens - log-format writes its refusal to the user, as log-level does - print-relays emits the relay error as a string and omits the key when there is none, where it printed {} or "Error":null - list-hostmap and list-lighthouse-addrmap -json return the encode error; print-cert reports a certificate that will not marshal - a flags type that is not the one registered is an internal error, not a silent success - command functions and flag types are <name>Command and <name>Flags; parseVpnAddr and listHostMapFlagSet replace the repeated parse block and flag set; close-tunnel sends through sendCloseTunnel Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
68 lines
2.7 KiB
Go
68 lines
2.7 KiB
Go
package nebula
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/netip"
|
|
"testing"
|
|
|
|
"github.com/slackhq/nebula/commands"
|
|
"github.com/slackhq/nebula/logging"
|
|
"github.com/slackhq/nebula/test"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestLogFormatRefusalIsShown: a format the logger does not know is reported to the user
|
|
// as a failure, rather than returned bare, which over ssh was silence.
|
|
func TestLogFormatRefusalIsShown(t *testing.T) {
|
|
l := logging.NewLogger(io.Discard)
|
|
out := &bytes.Buffer{}
|
|
w := commands.NewStringWriter(out)
|
|
|
|
var f *commands.Failure
|
|
require.ErrorAs(t, logFormatCommand(l, nil, []string{"bogus"}, w), &f)
|
|
assert.Equal(t, "Unable to set log format: unknown log format `bogus`. possible formats: [text json]\n", out.String())
|
|
|
|
out.Reset()
|
|
require.NoError(t, logFormatCommand(l, nil, []string{"JSON"}, w))
|
|
assert.Equal(t, "Log format is: json\n", out.String())
|
|
}
|
|
|
|
// TestPrintRelaysReportsErrorsAsText: the Error field was an error value, which encodes
|
|
// as {} and lost the message. It is the message now, and absent when there is none.
|
|
func TestPrintRelaysReportsErrorsAsText(t *testing.T) {
|
|
l := test.NewLogger()
|
|
hm := newHostMap(l)
|
|
relay := netip.MustParseAddr("10.0.0.1")
|
|
peer := netip.MustParseAddr("10.0.0.2")
|
|
|
|
// A relay host that is in Relays but not in Hosts, so its hostinfo cannot be found.
|
|
hm.Relays[1] = &HostInfo{vpnAddrs: []netip.Addr{relay}}
|
|
ifce := &Interface{hostMap: hm}
|
|
|
|
out := &bytes.Buffer{}
|
|
require.NoError(t, printRelaysCommand(ifce, &printTunnelFlags{}, nil, commands.NewStringWriter(out)))
|
|
assert.JSONEq(t, `{"Relays":[{"NebulaAddr":"10.0.0.1","RelayForAddrs":[{"Error":"could not find hostinfo","Type":"","State":"","PeerAddr":"","LocalIndex":0,"RemoteIndex":0,"RelayedThrough":null}]}]}`, out.String())
|
|
|
|
// The same relay host, found, relaying for a peer whose index matches: no Error key.
|
|
hi := hm.Relays[1]
|
|
r := &Relay{Type: ForwardingType, State: Established, PeerAddr: peer, LocalIndex: 1, RemoteIndex: 2}
|
|
hi.relayState = RelayState{
|
|
relayForByAddr: map[netip.Addr]*Relay{peer: r},
|
|
relayForByIdx: map[uint32]*Relay{r.LocalIndex: r},
|
|
}
|
|
hm.Hosts[relay] = hi
|
|
|
|
out.Reset()
|
|
require.NoError(t, printRelaysCommand(ifce, &printTunnelFlags{}, nil, commands.NewStringWriter(out)))
|
|
assert.JSONEq(t, `{"Relays":[{"NebulaAddr":"10.0.0.1","RelayForAddrs":[{"Type":"forwarding","State":"established","PeerAddr":"10.0.0.2","LocalIndex":1,"RemoteIndex":2,"RelayedThrough":null}]}]}`, out.String())
|
|
|
|
// And an index mismatch names it.
|
|
hm.Relays[7] = hi
|
|
delete(hm.Relays, 1)
|
|
out.Reset()
|
|
require.NoError(t, printRelaysCommand(ifce, &printTunnelFlags{}, nil, commands.NewStringWriter(out)))
|
|
assert.Contains(t, out.String(), `"Error":"hostmap LocalIndex '7' does not match RelayState LocalIndex"`)
|
|
}
|