feat(bsr): add protocol to sessionMeta
This commit is contained in:
1 parent
798a1f952a
commit
b43830e66e
10 files changed
+63
-5
No files matched your search
+6
-1
@@ -24,7 +24,8 @@ const (
|
||||
|
||||
// SessionMeta contains metadata about a session in a BSR.
|
||||
type SessionMeta struct {
|
||||
Id string
|
||||
Id string
|
||||
Protocol Protocol
|
||||
}
|
||||
|
||||
// Session is the top level container in a bsr that contains the files for
|
||||
@@ -66,6 +67,10 @@ func NewSession(ctx context.Context, meta *SessionMeta, f storage.FS, keys *kms.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = nc.WriteMeta(ctx, "protocol", meta.Protocol.ToText())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Session{
|
||||
container: nc,
|
||||
multiplexed: opts.withSupportsMultiplex,
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/bsr"
|
||||
"github.com/hashicorp/boundary/internal/bsr/internal/fstest"
|
||||
"github.com/hashicorp/boundary/internal/bsr/kms"
|
||||
"github.com/hashicorp/boundary/internal/bsr/ssh"
|
||||
"github.com/hashicorp/boundary/internal/storage"
|
||||
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -34,7 +36,9 @@ func assertContainer(ctx context.Context, t *testing.T, path, state string, typ
|
||||
require.NoError(t, err, "unable to find test data file")
|
||||
meta, ok := fs.Files[string(typ)+".meta"]
|
||||
require.True(t, ok, "container is missing meta file")
|
||||
assert.Equal(t, string(wantMeta), meta.Buf.String())
|
||||
wantChecksumsRegex, err := regexp.Compile(string(wantMeta))
|
||||
require.NoError(t, err)
|
||||
assert.True(t, wantChecksumsRegex.MatchString(meta.Buf.String()))
|
||||
|
||||
// summary
|
||||
wantSummary, err := os.ReadFile(filepath.Join(td, string(typ)+".summary"))
|
||||
@@ -188,7 +192,7 @@ func TestBsr(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s, err := bsr.NewSession(ctx, &bsr.SessionMeta{Id: tc.id}, tc.c, tc.keys, tc.opts...)
|
||||
s, err := bsr.NewSession(ctx, &bsr.SessionMeta{Id: tc.id, Protocol: ssh.Protocol}, tc.c, tc.keys, tc.opts...)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, s)
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
package bsr
|
||||
|
||||
import "regexp"
|
||||
|
||||
// Protocol identifies the protocol of the data captured in a chunk.
|
||||
type Protocol string
|
||||
|
||||
@@ -10,3 +12,10 @@ type Protocol string
|
||||
func ValidProtocol(p Protocol) bool {
|
||||
return len(p) <= protocolSize
|
||||
}
|
||||
|
||||
// ToText converts a protocol to a text-safe string
|
||||
func (p Protocol) ToText() string {
|
||||
re := regexp.MustCompile("[[:^ascii:]]")
|
||||
t := re.ReplaceAllLiteralString(string(p), "")
|
||||
return t
|
||||
}
|
||||
@@ -35,3 +35,39 @@ func TestValidProtocol(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestToText(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
in bsr.Protocol
|
||||
want string
|
||||
}{
|
||||
{
|
||||
"all ascii",
|
||||
bsr.Protocol("BOOM"),
|
||||
"BOOM",
|
||||
},
|
||||
{
|
||||
"not all ascii",
|
||||
bsr.Protocol("SSH\x87"),
|
||||
"SSH",
|
||||
},
|
||||
{
|
||||
"mostly not ascii",
|
||||
bsr.Protocol("S\x89\x99\x87"),
|
||||
"S",
|
||||
},
|
||||
{
|
||||
"no ascii",
|
||||
bsr.Protocol("\x95\x89\x99\x87"),
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := tc.in.ToText()
|
||||
assert.Equal(t, tc.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
ff2a532f46f3e2202e69b3aab760da95c290adf33a9a4b1c4a7e17e0a2671421 session.meta
|
||||
a7b7dc4a1c6032980f84d22afb71d59ccdf498db37f2e855a83d8854bdc297db session.meta
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 session.summary
|
||||
@@ -1,2 +1,3 @@
|
||||
id: session_123456789
|
||||
protocol: SSH
|
||||
connection: conn_1.connection
|
||||
@@ -1 +1,2 @@
|
||||
id: session_123456789
|
||||
protocol: SSH
|
||||
@@ -1,2 +1,2 @@
|
||||
ff2a532f46f3e2202e69b3aab760da95c290adf33a9a4b1c4a7e17e0a2671421 session.meta
|
||||
a7b7dc4a1c6032980f84d22afb71d59ccdf498db37f2e855a83d8854bdc297db session.meta
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 session.summary
|
||||
@@ -1,2 +1,3 @@
|
||||
id: session_123456789
|
||||
protocol: SSH
|
||||
connection: conn_1.connection
|
||||
@@ -1 +1,2 @@
|
||||
id: session_123456789
|
||||
protocol: SSH
|
||||
Reference in new issue
Block a user