From c60393d390070c112a5e54c3ed7d9adbd14d5d10 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Sat, 29 Jul 2023 00:40:18 -0600 Subject: [PATCH] gql changes --- gql.go | 12 ++++++------ gql_test.go | 26 ++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/gql.go b/gql.go index 0983dac..9d55df0 100644 --- a/gql.go +++ b/gql.go @@ -687,19 +687,19 @@ func LoadGQLExt(ctx *Context, data []byte) (Extension, error) { return nil, err } - return NewGQLExt(ctx, j.Listen, j.TLSCert, j.TLSKey), nil + return NewGQLExt(ctx, j.Listen, j.TLSCert, j.TLSKey) } -func NewGQLExt(ctx *Context, listen string, tls_cert []byte, tls_key []byte) *GQLExt { +func NewGQLExt(ctx *Context, listen string, tls_cert []byte, tls_key []byte) (*GQLExt, error) { if tls_cert == nil || tls_key == nil { ssl_key, err := ecdsa.GenerateKey(ctx.ECDSA, rand.Reader) if err != nil { - panic(err) + return nil, err } ssl_key_bytes, err := x509.MarshalECPrivateKey(ssl_key) if err != nil { - panic(err) + return nil, err } ssl_key_pem := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: ssl_key_bytes}) @@ -722,7 +722,7 @@ func NewGQLExt(ctx *Context, listen string, tls_cert []byte, tls_key []byte) *GQ ssl_cert, err := x509.CreateCertificate(rand.Reader, &template, &template, &ssl_key.PublicKey, ssl_key) if err != nil { - panic(err) + return nil, err } ssl_cert_pem := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: ssl_cert}) @@ -735,7 +735,7 @@ func NewGQLExt(ctx *Context, listen string, tls_cert []byte, tls_key []byte) *GQ SubscribeListeners: []chan Signal{}, tls_cert: tls_cert, tls_key: tls_key, - } + }, nil } func StartGQLServer(ctx *Context, node *Node, gql_ext *GQLExt) error { diff --git a/gql_test.go b/gql_test.go index 4f32562..65256a7 100644 --- a/gql_test.go +++ b/gql_test.go @@ -5,7 +5,28 @@ import ( "time" ) -func TestGQLDB(t * testing.T) { +func TestGQL(t *testing.T) { + ctx := logTestContext(t, []string{}) + + TestNodeType := NodeType("TEST") + err := ctx.RegisterNodeType(TestNodeType, []ExtType{LockableExtType, ACLExtType}) + fatalErr(t, err) + + gql_ext, err := NewGQLExt(ctx, ":0", nil, nil) + fatalErr(t, err) + listener_ext := NewListenerExt(10) + policy := NewAllNodesPolicy(Actions{MakeAction("+")}) + gql := NewNode(ctx, nil, TestNodeType, 10, nil, NewLockableExt(), NewACLExt(policy), gql_ext, listener_ext) + n1 := NewNode(ctx, nil, TestNodeType, 10, nil, NewLockableExt(), NewACLExt(policy)) + + LinkRequirement(ctx, gql.ID, n1.ID) + _, err = WaitForSignal(ctx, listener_ext, time.Millisecond*10, LinkSignalType, func(sig StateSignal) bool { + return sig.State == "linked_as_req" + }) + fatalErr(t, err) +} + +func TestGQLDB(t *testing.T) { ctx := logTestContext(t, []string{}) TestUserNodeType := NodeType("TEST_USER") @@ -15,7 +36,8 @@ func TestGQLDB(t * testing.T) { ctx.Log.Logf("test", "U1_ID: %s", u1.ID) - gql_ext := NewGQLExt(ctx, ":0", nil, nil) + gql_ext, err := NewGQLExt(ctx, ":0", nil, nil) + fatalErr(t, err) listener_ext := NewListenerExt(10) gql := NewNode(ctx, nil, GQLNodeType, 10, nil, gql_ext,