protocol: add generated bindings and conformance fixtures

This commit is contained in:
sechmachine
2026-07-21 23:43:04 +07:00
parent 2d69357052
commit 6abbc26dc4
22 changed files with 5031 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
package protocol_test
import (
"strings"
"testing"
protocol "github.com/sechmachine/VerseVDI-Protocol/gen/go/protocol"
)
func TestManifestRejectsForbiddenAndUnknownFields(t *testing.T) {
valid := `{"version":"1","purpose":"launch","session_id":"session-1","reconnect_sequence":0,"gateway":{"id":"gateway-1","addresses":["gateway.control.test:443"],"public_identity":"gateway-1"},"tunnel":{"versions":["verse-gateway-v1/1"],"features":["control.v1"]},"profile":{"id":"standard","bounds":{"minimum_kbps":1,"target_kbps":2,"maximum_kbps":3}},"grant":{"opaque_value":"opaque-one-time-grant-value-with-at-least-43-bytes","expires_at":"2099-01-01T00:00:00Z","audience":"versevdi-gateway"},"correlation_id":"correlation-1"}`
manifest, err := protocol.DecodeConnectionManifest([]byte(valid))
if err != nil || manifest.Gateway.ID != "gateway-1" {
t.Fatalf("valid manifest = %+v, err = %v", manifest, err)
}
for _, field := range []string{"provider_url", "vm_address", "password"} {
payload := strings.Replace(valid, `"correlation_id":"correlation-1"`, `"correlation_id":"correlation-1","`+field+`":"forbidden"`, 1)
if _, err := protocol.DecodeConnectionManifest([]byte(payload)); err == nil {
t.Fatalf("DecodeConnectionManifest accepted forbidden field %q", field)
}
}
}
func TestPageInfoRejectsOutOfBoundsLimit(t *testing.T) {
if _, err := protocol.DecodePageInfo([]byte(`{"limit":101,"next_cursor":""}`)); err == nil {
t.Fatal("DecodePageInfo accepted limit above the contract maximum")
}
}
func TestGeneratedDecodersRejectMissingRequiredFieldsAndTrailingValues(t *testing.T) {
if _, err := protocol.DecodeErrorEnvelope([]byte(`{"status":false,"error":"safe","code":"invalid_request","message":"safe","resolution":"retry","violations":[]} {}`)); err == nil {
t.Fatal("DecodeErrorEnvelope accepted a trailing JSON value")
}
if _, err := protocol.DecodeErrorEnvelope([]byte(`{"error":"safe","code":"invalid_request","message":"safe","resolution":"retry","request_id":"req-1","violations":[]}`)); err == nil {
t.Fatal("DecodeErrorEnvelope accepted a missing required boolean")
}
}