-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathtls_server_test.go
47 lines (40 loc) · 1.49 KB
/
tls_server_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package tls_server
import (
"github.com/wendy512/iec61850"
"os"
"os/signal"
"syscall"
"testing"
"unsafe"
)
func TestTlsServer(t *testing.T) {
model, err := iec61850.CreateModelFromConfigFileEx("model.cfg")
if err != nil {
t.Fatalf("create model error %v\n", err)
}
tlsConfig := iec61850.NewTLSConfig()
tlsConfig.KeyFile = "server_CA1_1.key"
tlsConfig.CertFile = "server_CA1_1.pem"
tlsConfig.AddCACertificateFromFile("root_CA1.pem")
tlsConfig.AddAllowedCertificateFromFile("client_CA1_1.pem")
tlsConfig.AddAllowedCertificateFromFile("client_CA1_2.pem")
tlsConfig.AllowOnlyKnownCertificates = true
tlsConfig.ChainValidation = false
server, err := iec61850.NewServerWithTlsSupport(iec61850.NewServerConfig(), tlsConfig, model)
modelNode := model.GetModelNodeByObjectReference("simpleIOGenericIO/GGIO1.SPCSO1")
server.SetControlHandler(modelNode, func(node *iec61850.ModelNode, action *iec61850.ControlAction, mmsValue *iec61850.MmsValue, test bool) iec61850.ControlHandlerResult {
t.Logf("control handler, action %#v, mmsValue %#v\n", action, mmsValue)
return iec61850.CONTROL_RESULT_OK
})
server.SetAuthenticator(func(securityToken *unsafe.Pointer, authParameter *iec61850.AcseAuthenticationParameter, appReference *iec61850.IsoApplicationReference) bool {
return true
})
server.Start(-1)
defer server.Destroy()
t.Logf("Server start up\n")
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
<-sig
t.Logf("Server stop\n")
server.Stop()
}