summaryrefslogtreecommitdiffhomepage
path: root/tun/wintun/registry/registry_windows_test.go
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-05-09 10:11:15 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-10 16:43:58 +0200
commit7e962a9932667f4a161b20aba5ff1c75ab8e578a (patch)
tree212eb2c6bc55db43c0b982b71195fc3ec61ce659 /tun/wintun/registry/registry_windows_test.go
parent586112b5d78abc99c9858c9a9a40756d5854d311 (diff)
wintun: wait for interface registry key on device creation
By using RegNotifyChangeKeyValue(). Also disable dead gateway detection. Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun/wintun/registry/registry_windows_test.go')
-rw-r--r--tun/wintun/registry/registry_windows_test.go103
1 files changed, 103 insertions, 0 deletions
diff --git a/tun/wintun/registry/registry_windows_test.go b/tun/wintun/registry/registry_windows_test.go
new file mode 100644
index 0000000..c5a6e28
--- /dev/null
+++ b/tun/wintun/registry/registry_windows_test.go
@@ -0,0 +1,103 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
+ */
+
+package registry
+
+import (
+ "testing"
+ "time"
+
+ "golang.org/x/sys/windows/registry"
+)
+
+const keyRoot = registry.CURRENT_USER
+const pathRoot = "Software\\WireGuardRegistryTest"
+const path = pathRoot + "\\foobar"
+const pathFake = pathRoot + "\\raboof"
+
+func Test_WaitForKey(t *testing.T) {
+ registry.DeleteKey(keyRoot, path)
+ registry.DeleteKey(keyRoot, pathRoot)
+ go func() {
+ time.Sleep(time.Second * 1)
+ key, _, err := registry.CreateKey(keyRoot, pathFake, registry.QUERY_VALUE)
+ if err != nil {
+ t.Errorf("Error creating registry key: %v", err)
+ }
+ key.Close()
+ registry.DeleteKey(keyRoot, pathFake)
+
+ key, _, err = registry.CreateKey(keyRoot, path, registry.QUERY_VALUE)
+ if err != nil {
+ t.Errorf("Error creating registry key: %v", err)
+ }
+ key.Close()
+ }()
+ err := WaitForKey(keyRoot, path, time.Second*2)
+ if err != nil {
+ t.Errorf("Error waiting for registry key: %v", err)
+ }
+ registry.DeleteKey(keyRoot, path)
+ registry.DeleteKey(keyRoot, pathRoot)
+
+ err = WaitForKey(keyRoot, path, time.Second*1)
+ if err == nil {
+ t.Error("Registry key notification expected to timeout but it succeeded.")
+ }
+}
+
+func Test_GetValueWait(t *testing.T) {
+ registry.DeleteKey(keyRoot, path)
+ registry.DeleteKey(keyRoot, pathRoot)
+ go func() {
+ time.Sleep(time.Second * 1)
+ key, _, err := registry.CreateKey(keyRoot, path, registry.SET_VALUE)
+ if err != nil {
+ t.Errorf("Error creating registry key: %v", err)
+ }
+ time.Sleep(time.Second * 1)
+ key.SetStringValue("name1", "eulav")
+ key.SetExpandStringValue("name2", "value")
+ time.Sleep(time.Second * 1)
+ key.SetDWordValue("name3", ^uint32(123))
+ key.SetDWordValue("name4", 123)
+ key.Close()
+ }()
+
+ key, err := OpenKeyWait(keyRoot, path, registry.QUERY_VALUE|KEY_NOTIFY, time.Second*2)
+ if err != nil {
+ t.Errorf("Error waiting for registry key: %v", err)
+ }
+
+ valueStr, err := GetStringValueWait(key, "name2", time.Second*2)
+ if err != nil {
+ t.Errorf("Error waiting for registry value: %v", err)
+ }
+ if valueStr != "value" {
+ t.Errorf("Wrong value read: %v", valueStr)
+ }
+
+ _, err = GetStringValueWait(key, "nonexisting", time.Second*1)
+ if err == nil {
+ t.Error("Registry value notification expected to timeout but it succeeded.")
+ }
+
+ valueInt, err := GetIntegerValueWait(key, "name4", time.Second*2)
+ if err != nil {
+ t.Errorf("Error waiting for registry value: %v", err)
+ }
+ if valueInt != 123 {
+ t.Errorf("Wrong value read: %v", valueInt)
+ }
+
+ _, err = GetIntegerValueWait(key, "nonexisting", time.Second*1)
+ if err == nil {
+ t.Error("Registry value notification expected to timeout but it succeeded.")
+ }
+
+ key.Close()
+ registry.DeleteKey(keyRoot, path)
+ registry.DeleteKey(keyRoot, pathRoot)
+}