Rename root, api and sdk module paths (imports, go.mod, go_package, ldflags, build scripts, buf configs) and regenerate protobuf/gateway code with the project's pinned toolchain. Wire identifiers unchanged. api gets a local replace for sdk; root/api/sdk require v0.1.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
106 lines
2.4 KiB
Go
106 lines
2.4 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package ssh
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/bsr"
|
|
pssh "repo.anhonesthost.net/CyberCoveLLC/threshold/internal/bsr/gen/ssh/v1"
|
|
"github.com/stretchr/testify/require"
|
|
gssh "golang.org/x/crypto/ssh"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func Test_NewShellRequest(t *testing.T) {
|
|
ctx := context.Background()
|
|
now := bsr.NewTimestamp(time.Now())
|
|
payload := []byte{}
|
|
|
|
tests := []struct {
|
|
name string
|
|
direction bsr.Direction
|
|
time *bsr.Timestamp
|
|
request *gssh.Request
|
|
expErr bool
|
|
expErrMsg string
|
|
}{
|
|
{
|
|
name: "nil request",
|
|
direction: bsr.Inbound,
|
|
time: now,
|
|
expErr: true,
|
|
expErrMsg: "ssh.NewShellRequest: request cannot be nil: invalid parameter",
|
|
},
|
|
{
|
|
name: "empty direction",
|
|
time: now,
|
|
request: &gssh.Request{
|
|
Type: ShellRequestType,
|
|
WantReply: false,
|
|
Payload: payload,
|
|
},
|
|
expErr: true,
|
|
expErrMsg: "ssh.NewShellRequest: invalid direction: invalid parameter",
|
|
},
|
|
{
|
|
name: "empty time",
|
|
direction: bsr.Inbound,
|
|
request: &gssh.Request{
|
|
Type: ShellRequestType,
|
|
WantReply: false,
|
|
Payload: payload,
|
|
},
|
|
expErr: true,
|
|
expErrMsg: "ssh.NewShellRequest: timestamp cannot be nil: invalid parameter",
|
|
},
|
|
{
|
|
name: "bad type",
|
|
direction: bsr.Inbound,
|
|
time: now,
|
|
request: &gssh.Request{
|
|
Type: "muahaha",
|
|
WantReply: false,
|
|
Payload: payload,
|
|
},
|
|
expErr: true,
|
|
expErrMsg: `ssh.NewShellRequest: request type must be "shell": invalid parameter`,
|
|
},
|
|
{
|
|
name: "happy path",
|
|
direction: bsr.Inbound,
|
|
time: now,
|
|
request: &gssh.Request{
|
|
Type: ShellRequestType,
|
|
WantReply: false,
|
|
Payload: payload,
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
rc, err := NewShellRequest(ctx, tt.direction, tt.time, tt.request)
|
|
if tt.expErr {
|
|
require.EqualError(t, err, tt.expErrMsg)
|
|
require.Nil(t, rc)
|
|
return
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
require.NotNil(t, rc)
|
|
|
|
data, err := rc.MarshalData(ctx)
|
|
require.NoError(t, err)
|
|
dataPayload := &pssh.ShellRequest{}
|
|
err = proto.Unmarshal(data, dataPayload)
|
|
require.NoError(t, err)
|
|
require.Equal(t, dataPayload.RequestType, ShellRequestType)
|
|
require.Equal(t, dataPayload.WantReply, false)
|
|
})
|
|
}
|
|
}
|