Skip to content

Commit

Permalink
Add maximum payload length tests to vpncscript
Browse files Browse the repository at this point in the history
Signed-off-by: hwipl <[email protected]>
  • Loading branch information
hwipl committed Mar 13, 2024
1 parent 808b5fd commit 084b177
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions internal/vpncscript/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package vpncscript

import (
"path/filepath"
"strings"
"testing"

"github.com/telekom-mms/oc-daemon/internal/api"
"github.com/telekom-mms/oc-daemon/internal/daemon"
"github.com/telekom-mms/oc-daemon/pkg/vpnconfig"
)

// TestRunClient tests runClient.
Expand Down Expand Up @@ -44,4 +46,56 @@ func TestRunClient(t *testing.T) {
t.Fatal(err)
}
server.Stop()

// helper for config update creation
getConfUpdate := func(length int) *daemon.VPNConfigUpdate {
exclude := "a.too.long.example.com"
conf := vpnconfig.New()
conf.Split.ExcludeDNS = []string{exclude}
confUpdate := daemon.NewVPNConfigUpdate()
confUpdate.Config = conf

// check length
b, err := confUpdate.JSON()
if err != nil {
t.Fatal(err)
}
n := length - len(b)

// increase length to maximum
exclude = strings.Repeat("a", n) + exclude
conf.Split.ExcludeDNS = []string{exclude}

return confUpdate
}

// test with maximum payload length
server = api.NewServer(config)
go func() {
for r := range server.Requests() {
r.Close()
}
}()
if err := server.Start(); err != nil {
t.Fatal(err)
}
if err := runClient(sockfile, getConfUpdate(api.MaxPayloadLength)); err != nil {
t.Fatal(err)
}
server.Stop()

// test with more than maximum payload length
server = api.NewServer(config)
go func() {
for r := range server.Requests() {
r.Close()
}
}()
if err := server.Start(); err != nil {
t.Fatal(err)
}
if err := runClient(sockfile, getConfUpdate(api.MaxPayloadLength+1)); err == nil {
t.Fatal("too long message should return error")
}
server.Stop()
}

0 comments on commit 084b177

Please sign in to comment.