Skip to content

Commit

Permalink
Merge pull request #103 from telekom-mms/bugfix/parse-login-info-from…
Browse files Browse the repository at this point in the history
…-lines-in-client

Parse Login Info from whole lines in Client
  • Loading branch information
hwipl committed Jul 4, 2024
2 parents 6c32ae9 + 32962d3 commit 9601f86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
package client

import (
"bufio"
"bytes"
"fmt"
"os"
"os/exec"
"strings"
"sync"

"github.com/godbus/dbus/v5"
Expand Down Expand Up @@ -478,10 +478,11 @@ var authenticate = func(d *DBusClient) error {
// FINGERPRINT=469bb424ec8835944d30bc77c77e8fc1d8e23a42
// RESOLVE='vpnserver.example.com:10.0.0.1'
//
s := b.String()
login := &logininfo.LoginInfo{}
login.Server = config.VPNServer
for _, line := range strings.Fields(s) {
scanner := bufio.NewScanner(&b)
for scanner.Scan() {
line := scanner.Text()
login.ParseLine(line)
}
d.SetLogin(login)
Expand Down
15 changes: 15 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,21 @@ func TestDBusClientAuthenticate(t *testing.T) {
if !reflect.DeepEqual(got, want) {
t.Errorf("got %v, want %v", got, want)
}

// test cookie with spaces
want = &logininfo.LoginInfo{
Cookie: "Test cookie with spaces!",
}
execCommand = func(string, ...string) *exec.Cmd {
return exec.Command("echo", "COOKIE='Test cookie with spaces!'")
}
if err := client.Authenticate(); err != nil {
t.Errorf("authenticate returned error: %v", err)
}
got = client.GetLogin()
if !reflect.DeepEqual(got, want) {
t.Errorf("got %v, want %v", got, want)
}
}

// TestDBusClientConnect tests Connect of DBusClient.
Expand Down

0 comments on commit 9601f86

Please sign in to comment.