Skip to content

Commit e6813fc

Browse files
claudehulto
authored andcommitted
Fix tests: update C2 server initialization to include JWT service
Updated all test files that create C2 servers to include the JWT service parameter that was added in the previous commits: - internal/c2/c2test/grpc.go: Test helper for C2 tests - internal/c2/reverse_shell_e2e_test.go: E2E reverse shell test - internal/portals/integration_test.go: Portal integration tests - internal/portals/benchmark_test.go: Portal benchmark tests Each test now generates ephemeral ed25519 keys and creates a JWT service before initializing the C2 server, matching the updated c2.New() signature.
1 parent e55a4bd commit e6813fc

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

tavern/internal/c2/c2test/grpc.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package c2test
22

33
import (
44
"context"
5+
"crypto/ed25519"
6+
"crypto/rand"
57
"errors"
68
"net"
79
"testing"
@@ -19,6 +21,7 @@ import (
1921
"realm.pub/tavern/internal/ent"
2022
"realm.pub/tavern/internal/ent/enttest"
2123
"realm.pub/tavern/internal/http/stream"
24+
"realm.pub/tavern/internal/jwt"
2225
"realm.pub/tavern/internal/portals/mux"
2326
)
2427

@@ -49,10 +52,16 @@ func New(t *testing.T) (c2pb.C2Client, *ent.Client, func()) {
4952
grpcShellMux := stream.NewMux(grpcOutTopic, grpcInSub)
5053
portalMux := mux.New(mux.WithInMemoryDriver())
5154

55+
// JWT Service for testing
56+
pubKey, privKey, err := ed25519.GenerateKey(rand.Reader)
57+
require.NoError(t, err)
58+
jwtService, err := jwt.NewService(privKey, pubKey)
59+
require.NoError(t, err)
60+
5261
// gRPC Server
5362
lis := bufconn.Listen(1024 * 1024 * 10)
5463
baseSrv := grpc.NewServer()
55-
c2pb.RegisterC2Server(baseSrv, c2.New(graph, grpcShellMux, portalMux))
64+
c2pb.RegisterC2Server(baseSrv, c2.New(graph, grpcShellMux, portalMux, jwtService))
5665

5766
grpcErrCh := make(chan error, 1)
5867
go func() {

tavern/internal/c2/reverse_shell_e2e_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package c2_test
22

33
import (
44
"context"
5+
"crypto/ed25519"
6+
"crypto/rand"
57
"net"
68
"net/http/httptest"
79
"strconv"
@@ -21,6 +23,7 @@ import (
2123
"realm.pub/tavern/internal/c2/c2pb"
2224
"realm.pub/tavern/internal/ent/enttest"
2325
"realm.pub/tavern/internal/http/stream"
26+
"realm.pub/tavern/internal/jwt"
2427
"realm.pub/tavern/internal/portals/mux"
2528

2629
_ "github.com/mattn/go-sqlite3"
@@ -62,10 +65,16 @@ func TestReverseShell_E2E(t *testing.T) {
6265
grpcMux := stream.NewMux(pubOutput, subInput)
6366
portalMux := mux.New(mux.WithInMemoryDriver())
6467

68+
// Setup JWT service for testing
69+
pubKey, privKey, err := ed25519.GenerateKey(rand.Reader)
70+
require.NoError(t, err)
71+
jwtService, err := jwt.NewService(privKey, pubKey)
72+
require.NoError(t, err)
73+
6574
go wsMux.Start(ctx)
6675
go grpcMux.Start(ctx)
6776

68-
c2pb.RegisterC2Server(s, c2.New(graph, grpcMux, portalMux))
77+
c2pb.RegisterC2Server(s, c2.New(graph, grpcMux, portalMux, jwtService))
6978
go func() {
7079
if err := s.Serve(lis); err != nil {
7180
t.Logf("Server exited with error: %v", err)

tavern/internal/portals/benchmark_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package portals_test
22

33
import (
44
"context"
5+
"crypto/ed25519"
56
"crypto/rand"
67
"fmt"
78
"log/slog"
@@ -25,6 +26,7 @@ import (
2526
"realm.pub/tavern/internal/ent/task"
2627
"realm.pub/tavern/internal/ent/tome"
2728
"realm.pub/tavern/internal/http/stream"
29+
"realm.pub/tavern/internal/jwt"
2830
"realm.pub/tavern/internal/portals"
2931
"realm.pub/tavern/internal/portals/mux"
3032
"realm.pub/tavern/portals/portalpb"
@@ -92,7 +94,17 @@ func BenchmarkPortalThroughput(b *testing.B) {
9294
// Create a placeholder shellMux since C2 requires it, but we won't use it.
9395
var shellMux *stream.Mux = nil
9496

95-
c2Srv := c2.New(client, shellMux, portalMux)
97+
// Setup JWT service for testing
98+
pubKey, privKey, err := ed25519.GenerateKey(rand.Reader)
99+
if err != nil {
100+
b.Fatalf("failed to generate ed25519 key: %v", err)
101+
}
102+
jwtService, err := jwt.NewService(privKey, pubKey)
103+
if err != nil {
104+
b.Fatalf("failed to create JWT service: %v", err)
105+
}
106+
107+
c2Srv := c2.New(client, shellMux, portalMux, jwtService)
96108
portalSrv := portals.New(client, portalMux)
97109

98110
// 4. Start gRPC Server

tavern/internal/portals/integration_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package portals_test
22

33
import (
44
"context"
5+
"crypto/ed25519"
6+
"crypto/rand"
57
"fmt"
68
"net"
79
"testing"
@@ -19,6 +21,7 @@ import (
1921
"realm.pub/tavern/internal/ent"
2022
"realm.pub/tavern/internal/ent/enttest"
2123
"realm.pub/tavern/internal/http/stream"
24+
"realm.pub/tavern/internal/jwt"
2225
"realm.pub/tavern/internal/portals"
2326
"realm.pub/tavern/internal/portals/mux"
2427
"realm.pub/tavern/portals/portalpb"
@@ -58,7 +61,13 @@ func SetupTestEnv(t *testing.T) *TestEnv {
5861
ctxMux, cancelMux := context.WithCancel(ctx)
5962
go c2StreamMux.Start(ctxMux)
6063

61-
c2Server := c2.New(entClient, c2StreamMux, portalMux)
64+
// Setup JWT service for testing
65+
pubKey, privKey, err := ed25519.GenerateKey(rand.Reader)
66+
require.NoError(t, err)
67+
jwtService, err := jwt.NewService(privKey, pubKey)
68+
require.NoError(t, err)
69+
70+
c2Server := c2.New(entClient, c2StreamMux, portalMux, jwtService)
6271
portalServer := portals.New(entClient, portalMux)
6372

6473
// 4. Setup gRPC Listener with bufconn

0 commit comments

Comments
 (0)