|
@@ -36,20 +36,8 @@ func TestGoto(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestReadDropfileFail(t *testing.T) {
|
|
|
- d := Door{}
|
|
|
-
|
|
|
- defer func() {
|
|
|
- if r := recover(); r == nil {
|
|
|
- t.Error("ReadDropfile did not panic on missing dropfile.")
|
|
|
- }
|
|
|
- }()
|
|
|
-
|
|
|
- d.ReadDropfile("This_File_Will_Not_Be_Found")
|
|
|
-}
|
|
|
-
|
|
|
func TestLogfileFailure(t *testing.T) {
|
|
|
- tmpFile, err := os.CreateTemp("", "test-*")
|
|
|
+ tmpFile, err := os.CreateTemp("", "test-door32.sys-*")
|
|
|
if err != nil {
|
|
|
panic("Cannot create temporary file")
|
|
|
}
|
|
@@ -68,11 +56,9 @@ func TestLogfileFailure(t *testing.T) {
|
|
|
var fd int = 0
|
|
|
|
|
|
// Create door32.sys file
|
|
|
- dfc := DropfileConfig{2, fd, 1800, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 0, 13}
|
|
|
+ dfc := DropfileConfig{2, fd, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 13}
|
|
|
|
|
|
- _, err = tmpFile.WriteString(fmt.Sprintf("%d\n%d\n%d\n%s\n%d\n%s\n%s\n%d\n%d\n%d\n%d\n",
|
|
|
- dfc.Comm_type, dfc.Comm_handle, dfc.Baudrate, dfc.BBSID, dfc.User_number, dfc.Real_name, dfc.Handle,
|
|
|
- dfc.Security_level, dfc.Time_left, dfc.Emulation, dfc.Node))
|
|
|
+ err = CreateDoor32File(&dfc, tmpFile)
|
|
|
if err != nil {
|
|
|
t.Error("tmpFile.WriteString:", err)
|
|
|
}
|
|
@@ -88,88 +74,20 @@ func TestLogfileFailure(t *testing.T) {
|
|
|
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
|
|
// preset commandline args so door can init
|
|
|
os.Args = []string{"door", "-d", tmpFile.Name()}
|
|
|
- d.Init("/badname-test")
|
|
|
|
|
|
-}
|
|
|
+ uid := os.Getuid()
|
|
|
|
|
|
-func TestReadDropFile(t *testing.T) {
|
|
|
- tmpFile, err := os.CreateTemp("", "test-*")
|
|
|
- if err != nil {
|
|
|
- panic("Cannot create temporary file")
|
|
|
- }
|
|
|
-
|
|
|
- // Clean up the dropfile afterwards
|
|
|
- defer os.Remove(tmpFile.Name())
|
|
|
-
|
|
|
- dfc := DropfileConfig{2, 20, 1800, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 0, 12}
|
|
|
-
|
|
|
- _, err = tmpFile.WriteString(fmt.Sprintf("%d\n%d\n%d\n%s\n%d\n%s\n%s\n%d\n%d\n%d\n%d\n",
|
|
|
- dfc.Comm_type, dfc.Comm_handle, dfc.Baudrate, dfc.BBSID, dfc.User_number, dfc.Real_name, dfc.Handle,
|
|
|
- dfc.Security_level, dfc.Time_left, dfc.Emulation, dfc.Node))
|
|
|
- if err != nil {
|
|
|
- t.Error("tmpFile.WriteString:", err)
|
|
|
- }
|
|
|
- err = tmpFile.Close()
|
|
|
- if err != nil {
|
|
|
- t.Error("tmpFile.Close:", err)
|
|
|
- }
|
|
|
-
|
|
|
- d := Door{}
|
|
|
- d.ReadDropfile(tmpFile.Name())
|
|
|
-
|
|
|
- if dfc.Comm_type != d.Config.Comm_type {
|
|
|
- t.Errorf("Comm Type expected %#v, got %#v", dfc.Comm_type, d.Config.Comm_type)
|
|
|
- }
|
|
|
- if dfc.Comm_handle != d.Config.Comm_handle {
|
|
|
- t.Errorf("Comm Handle expected %#v, got %#v", dfc.Comm_handle, d.Config.Comm_handle)
|
|
|
- }
|
|
|
- if dfc.BBSID != d.Config.BBSID {
|
|
|
- t.Errorf("BBSID expected %#v, got %#v", dfc.BBSID, d.Config.BBSID)
|
|
|
- }
|
|
|
- if dfc.User_number != d.Config.User_number {
|
|
|
- t.Errorf("User Number expected %#v, got %#v", dfc.User_number, d.Config.User_number)
|
|
|
- }
|
|
|
- if dfc.Real_name != d.Config.Real_name {
|
|
|
- t.Errorf("Real Name expected %#v, got %#v", dfc.Real_name, d.Config.Real_name)
|
|
|
- }
|
|
|
- if dfc.Handle != d.Config.Handle {
|
|
|
- t.Errorf("Handle expected %#v, got %#v", dfc.Handle, d.Config.Handle)
|
|
|
- }
|
|
|
- if dfc.Time_left != d.Config.Time_left {
|
|
|
- t.Errorf("Time Left expected %#v, got %#v", dfc.Time_left, d.Config.Time_left)
|
|
|
- }
|
|
|
- if dfc.Node != d.Config.Node {
|
|
|
- t.Errorf("Node expected %#v, got %#v", dfc.Node, d.Config.Node)
|
|
|
- }
|
|
|
- start := time.Now()
|
|
|
- timeout := time.Now().Add(time.Duration(dfc.Time_left) * time.Minute)
|
|
|
-
|
|
|
- // Verify the start time and timeout values have been set correctly.
|
|
|
- startDelta := start.Sub(d.StartTime)
|
|
|
- timeoutDelta := timeout.Sub(d.TimeOut)
|
|
|
-
|
|
|
- left := d.TimeLeft()
|
|
|
- used := d.TimeUsed()
|
|
|
-
|
|
|
- if used.Seconds() > 1 {
|
|
|
- t.Errorf("Time Used (from door) > 1 second: %#v", used)
|
|
|
- }
|
|
|
-
|
|
|
- time_left_seconds := dfc.Time_left * 60
|
|
|
-
|
|
|
- if time_left_seconds-int(left.Seconds()) > 1 {
|
|
|
- t.Errorf("Time Left differences > 1 second: test %#v door %#v", time_left_seconds, left)
|
|
|
- }
|
|
|
- if startDelta.Seconds() > 1 {
|
|
|
- t.Errorf("Start Time differences: test %#v door %#v delta %#v", start, d.StartTime, startDelta)
|
|
|
- }
|
|
|
- if timeoutDelta.Seconds() > 1 {
|
|
|
- t.Errorf("TimeOut differences: test %#v door %#v delta %#v", timeout, d.TimeOut, timeoutDelta)
|
|
|
+ if uid == 0 {
|
|
|
+ // Running as root. Use invalid path here.
|
|
|
+ d.Init("/invalid-path/badpath-test")
|
|
|
+ } else {
|
|
|
+ // uid == -1 (windows), this should also fail there.
|
|
|
+ d.Init("/badname-test")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func TestDetectFail(t *testing.T) {
|
|
|
- tmpFile, err := os.CreateTemp("", "test-*")
|
|
|
+ tmpFile, err := os.CreateTemp("", "test-door32.sys-*")
|
|
|
if err != nil {
|
|
|
panic("Cannot create temporary file")
|
|
|
}
|
|
@@ -190,11 +108,9 @@ func TestDetectFail(t *testing.T) {
|
|
|
defer close_fd(fd)
|
|
|
|
|
|
// Create door32.sys file
|
|
|
- dfc := DropfileConfig{2, fd, 1800, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 0, 13}
|
|
|
+ dfc := DropfileConfig{2, fd, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 13}
|
|
|
|
|
|
- _, err = tmpFile.WriteString(fmt.Sprintf("%d\n%d\n%d\n%s\n%d\n%s\n%s\n%d\n%d\n%d\n%d\n",
|
|
|
- dfc.Comm_type, dfc.Comm_handle, dfc.Baudrate, dfc.BBSID, dfc.User_number, dfc.Real_name, dfc.Handle,
|
|
|
- dfc.Security_level, dfc.Time_left, dfc.Emulation, dfc.Node))
|
|
|
+ err = CreateDoor32File(&dfc, tmpFile)
|
|
|
if err != nil {
|
|
|
t.Error("tmpFile.WriteString:", err)
|
|
|
}
|
|
@@ -281,16 +197,19 @@ func InputTests(t *testing.T, server net.Conn, d *Door, mode string) {
|
|
|
"\x00\x3b\x00\x3c\x00\x3d\x00\x3e": []Extended{F1, F2, F3, F4},
|
|
|
"\x00\x3f\x00\x40\x00\x41\x00\x42": []Extended{F5, F6, F7, F8},
|
|
|
"\x00\x43\x00\x44\x00\x52\x00\x53": []Extended{F9, F10, INSERT, DELETE},
|
|
|
+ "\x00\x45\x00\x46": []Extended{F11, F12},
|
|
|
"\x1b[A\x1b[B\x1b[C\x1b[D": []Extended{UP_ARROW, DOWN_ARROW, RIGHT_ARROW, LEFT_ARROW},
|
|
|
"\x1b[H\x1b[F\x1b[K\x1b[V\x1b[U": []Extended{HOME, END, END, PAGE_UP, PAGE_DOWN},
|
|
|
"\x1b[5~\x1b[6~": []Extended{PAGE_UP, PAGE_DOWN},
|
|
|
"\x1b[@\x1b[2~\x1b[3~": []Extended{INSERT, INSERT, DELETE},
|
|
|
+ "\x1b[1~\x1b[4~": []Extended{HOME, END},
|
|
|
"\x1bOP\x1bOQ\x1bOR\x1bOS": []Extended{F1, F2, F3, F4},
|
|
|
"\x1b[15~\x1b[17~\x1b[18~\x1b[19~": []Extended{F5, F6, F7, F8},
|
|
|
"\x1b[20~\x1b[21~\x1b[23~\x1b[24~": []Extended{F9, F10, F11, F12},
|
|
|
}
|
|
|
|
|
|
- keyWait := time.Duration(50 * time.Millisecond)
|
|
|
+ // 50ms causes 3 tries (internal is 200ms, use 210ms).
|
|
|
+ keyWait := time.Duration(210 * time.Millisecond)
|
|
|
|
|
|
// Verify input is empty
|
|
|
for {
|
|
@@ -564,7 +483,7 @@ func TestDoorCP437(t *testing.T) {
|
|
|
var tmpFile *os.File
|
|
|
var err error
|
|
|
// Dropfile
|
|
|
- tmpFile, err = os.CreateTemp("", "test-*")
|
|
|
+ tmpFile, err = os.CreateTemp("", "test-door32.sys-*")
|
|
|
if err != nil {
|
|
|
panic("Cannot create temporary file")
|
|
|
}
|
|
@@ -591,11 +510,9 @@ func TestDoorCP437(t *testing.T) {
|
|
|
|
|
|
// Create door32.sys file
|
|
|
var node int = 10
|
|
|
- dfc := DropfileConfig{2, fd, 1800, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 0, node}
|
|
|
+ dfc := DropfileConfig{2, fd, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, node}
|
|
|
|
|
|
- _, err = tmpFile.WriteString(fmt.Sprintf("%d\n%d\n%d\n%s\n%d\n%s\n%s\n%d\n%d\n%d\n%d\n",
|
|
|
- dfc.Comm_type, dfc.Comm_handle, dfc.Baudrate, dfc.BBSID, dfc.User_number, dfc.Real_name, dfc.Handle,
|
|
|
- dfc.Security_level, dfc.Time_left, dfc.Emulation, dfc.Node))
|
|
|
+ err = CreateDoor32File(&dfc, tmpFile)
|
|
|
if err != nil {
|
|
|
t.Error("tmpFile.WriteString:", err)
|
|
|
}
|
|
@@ -703,7 +620,7 @@ func TestDoorUnicode(t *testing.T) {
|
|
|
var err error
|
|
|
|
|
|
// Dropfile
|
|
|
- tmpFile, err = os.CreateTemp("", "test-*")
|
|
|
+ tmpFile, err = os.CreateTemp("", "test-door32.sys-*")
|
|
|
if err != nil {
|
|
|
panic("Cannot create temporary file")
|
|
|
}
|
|
@@ -730,11 +647,9 @@ func TestDoorUnicode(t *testing.T) {
|
|
|
|
|
|
// Create door32.sys file
|
|
|
var node int = 11
|
|
|
- dfc := DropfileConfig{2, fd, 1800, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 0, node}
|
|
|
+ dfc := DropfileConfig{2, fd, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, node}
|
|
|
|
|
|
- _, err = tmpFile.WriteString(fmt.Sprintf("%d\n%d\n%d\n%s\n%d\n%s\n%s\n%d\n%d\n%d\n%d\n",
|
|
|
- dfc.Comm_type, dfc.Comm_handle, dfc.Baudrate, dfc.BBSID, dfc.User_number, dfc.Real_name, dfc.Handle,
|
|
|
- dfc.Security_level, dfc.Time_left, dfc.Emulation, dfc.Node))
|
|
|
+ err = CreateDoor32File(&dfc, tmpFile)
|
|
|
if err != nil {
|
|
|
t.Error("tmpFile.WriteString:", err)
|
|
|
}
|