gql changes

gql_cataclysm
noah metz 2023-07-29 00:40:18 -06:00
parent 641bd8febe
commit c60393d390
2 changed files with 30 additions and 8 deletions

@ -687,19 +687,19 @@ func LoadGQLExt(ctx *Context, data []byte) (Extension, error) {
return nil, err 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 { if tls_cert == nil || tls_key == nil {
ssl_key, err := ecdsa.GenerateKey(ctx.ECDSA, rand.Reader) ssl_key, err := ecdsa.GenerateKey(ctx.ECDSA, rand.Reader)
if err != nil { if err != nil {
panic(err) return nil, err
} }
ssl_key_bytes, err := x509.MarshalECPrivateKey(ssl_key) ssl_key_bytes, err := x509.MarshalECPrivateKey(ssl_key)
if err != nil { if err != nil {
panic(err) return nil, err
} }
ssl_key_pem := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: ssl_key_bytes}) 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) ssl_cert, err := x509.CreateCertificate(rand.Reader, &template, &template, &ssl_key.PublicKey, ssl_key)
if err != nil { if err != nil {
panic(err) return nil, err
} }
ssl_cert_pem := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: ssl_cert}) 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{}, SubscribeListeners: []chan Signal{},
tls_cert: tls_cert, tls_cert: tls_cert,
tls_key: tls_key, tls_key: tls_key,
} }, nil
} }
func StartGQLServer(ctx *Context, node *Node, gql_ext *GQLExt) error { func StartGQLServer(ctx *Context, node *Node, gql_ext *GQLExt) error {

@ -5,6 +5,27 @@ import (
"time" "time"
) )
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) { func TestGQLDB(t *testing.T) {
ctx := logTestContext(t, []string{}) ctx := logTestContext(t, []string{})
@ -15,7 +36,8 @@ func TestGQLDB(t * testing.T) {
ctx.Log.Logf("test", "U1_ID: %s", u1.ID) 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) listener_ext := NewListenerExt(10)
gql := NewNode(ctx, nil, GQLNodeType, 10, nil, gql := NewNode(ctx, nil, GQLNodeType, 10, nil,
gql_ext, gql_ext,