forked from bettercap/bettercap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_test.go
90 lines (88 loc) · 2.78 KB
/
session_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package session
import (
"fmt"
"testing"
)
func TestParseCommands(t *testing.T) {
//commands := ParseCommands("wifi.recon on; asdf; \"asdf;\" asdf")
t.Run("handles a semicolon as a delimiter", func(t *testing.T) {
first := "wifi.recon on"
second := "wifi.ap"
cmd := fmt.Sprintf("%s; %s", first, second)
commands := ParseCommands(cmd)
if l := len(commands); l != 2 {
t.Fatalf("Expected 2 commands, got %d", l)
}
if got := commands[0]; got != first {
t.Fatalf("expected %s got %s", first, got)
}
if got := commands[1]; got != second {
t.Fatalf("expected %s got %s", second, got)
}
})
t.Run("handles semicolon inside quotes", func(t *testing.T) {
cmd := "set ticker.commands \"clear; net.show\""
commands := ParseCommands(cmd)
if l := len(commands); l != 1 {
t.Fatalf("expected 1 command, got %d", l)
}
// Expect double-quotes stripped
expected := "set ticker.commands clear; net.show"
if got := commands[0]; got != expected {
fmt.Println(got)
t.Fatalf("expected %s got %s", cmd, got)
}
})
t.Run("handles semicolon inside single quotes", func(t *testing.T) {
cmd := "set ticker.commands 'clear; net.show'"
commands := ParseCommands(cmd)
if l := len(commands); l != 1 {
t.Fatalf("expected 1 command, got %d", l)
}
// Expect double-quotes stripped
expected := "set ticker.commands clear; net.show"
if got := commands[0]; got != expected {
fmt.Println(got)
t.Fatalf("expected %s got %s", cmd, got)
}
})
t.Run("handles semicolon inside single quotes inside quote", func(t *testing.T) {
cmd := "set ticker.commands \"'clear; net.show'\""
commands := ParseCommands(cmd)
if l := len(commands); l != 1 {
t.Fatalf("expected 1 command, got %d", l)
}
// Expect double-quotes stripped
expected := "set ticker.commands 'clear; net.show'"
if got := commands[0]; got != expected {
fmt.Println(got)
t.Fatalf("expected %s got %s", cmd, got)
}
})
t.Run("handles semicolon inside quotes inside single quote", func(t *testing.T) {
cmd := "set ticker.commands '\"clear; net.show\"'"
commands := ParseCommands(cmd)
if l := len(commands); l != 1 {
t.Fatalf("expected 1 command, got %d", l)
}
// Expect double-quotes stripped
expected := "set ticker.commands \"clear; net.show\""
if got := commands[0]; got != expected {
fmt.Println(got)
t.Fatalf("expected %s got %s", cmd, got)
}
})
t.Run("handle mismatching quote", func(t *testing.T) {
cmd := "set ticker.commands \"clear; echo it's working ?\""
commands := ParseCommands(cmd)
if l := len(commands); l != 1 {
t.Fatalf("expected 1 command, got %d", l)
}
// Expect double-quotes stripped
expected := "set ticker.commands clear; echo it's working ?"
if got := commands[0]; got != expected {
fmt.Println(got)
t.Fatalf("expected %s got %s", cmd, got)
}
})
}