70 lines
2.6 KiB
Go
70 lines
2.6 KiB
Go
package rpc
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
agentpb "git.ipao.vip/rogee/go-sip/gen/agent"
|
|
"google.golang.org/protobuf/reflect/protoreflect"
|
|
)
|
|
|
|
func TestAgentControlServiceOnlyExposesApprovedMethods(t *testing.T) {
|
|
var got []string
|
|
for _, method := range agentpb.AgentControlService_ServiceDesc.Methods {
|
|
got = append(got, method.MethodName)
|
|
}
|
|
want := []string{
|
|
"GetAgentStatus", "ActivateAgent",
|
|
"ExecuteApproved", "ApplyApprovedTaskControl", "GetLoadedSIP", "ApplySIP",
|
|
"RequestRecordingUpload", "ReportCallEnded", "ReportCallResult",
|
|
}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("Agent gRPC method surface = %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestAgentProtoOmitsRetiredBusinessPayloads(t *testing.T) {
|
|
file := agentpb.File_agent_agent_proto
|
|
for _, name := range []string{
|
|
"ConfigReference", "UploadPolicy", "ExecutionBinding",
|
|
"GetBootstrapRequest", "GetBootstrapResponse", "SetAdmissionStateRequest", "SetAdmissionStateResponse",
|
|
"ExecuteRequest", "ExecuteResponse", "ExecuteAuthorizedRequest", "ExecuteAuthorizedResponse",
|
|
"GetExecutionPermitRequest", "ExecutionPermit", "GetExecutionPermitResponse",
|
|
"ApplyTaskControlRequest", "ApplyTaskControlResponse",
|
|
"QueryExecutionRequest", "ExecutionSnapshot", "QueryExecutionResponse",
|
|
"ExecutionFact", "ReportExecutionEventRequest", "ReportExecutionEventResponse",
|
|
"RequestUploadRequest", "RequestUploadResponse", "CompleteUploadRequest", "CompleteUploadResponse",
|
|
} {
|
|
if file.Messages().ByName(protoreflect.Name(name)) != nil {
|
|
t.Fatalf("retired Agent Proto message %s is still declared", name)
|
|
}
|
|
}
|
|
for _, name := range []string{"ExecutionState", "UploadState", "FactKind"} {
|
|
if file.Enums().ByName(protoreflect.Name(name)) != nil {
|
|
t.Fatalf("retired Agent Proto enum %s is still declared", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAgentServerUsesLoadedSIPInsteadOfRetiredStaticArtifact(t *testing.T) {
|
|
options := reflect.TypeOf(ServerOptions{})
|
|
for _, name := range []string{"StaticArtifactRaw", "StaticArtifactExpected"} {
|
|
if _, exists := options.FieldByName(name); exists {
|
|
t.Fatalf("retired static artifact input %s remains on the Agent server", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAgentServerHasNoRetiredBusinessMethods(t *testing.T) {
|
|
server := reflect.TypeOf(&Server{})
|
|
for _, name := range []string{
|
|
"GetBootstrap", "SetAdmissionState", "Execute", "ExecuteAuthorized",
|
|
"GetExecutionPermit", "ApplyTaskControl", "QueryExecution",
|
|
"ReportExecutionEvent", "RequestUpload", "CompleteUpload",
|
|
} {
|
|
if _, exists := server.MethodByName(name); exists {
|
|
t.Fatalf("retired Agent RPC method %s is still implemented", name)
|
|
}
|
|
}
|
|
}
|