Browse Source

Always use correct format Node IDs in GUI

Jakob Borg 11 years ago
parent
commit
f762bd5e25
3 changed files with 51 additions and 2 deletions
  1. 0 0
      auto/gui.files.go
  2. 50 1
      config/config_test.go
  3. 1 1
      gui/app.js

File diff suppressed because it is too large
+ 0 - 0
auto/gui.files.go


+ 50 - 1
config/config_test.go

@@ -189,7 +189,7 @@ func TestOverriddenValues(t *testing.T) {
 	}
 }
 
-func TestNodeAddresses(t *testing.T) {
+func TestNodeAddressesDynamic(t *testing.T) {
 	data := []byte(`
 <configuration version="2">
     <node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ">
@@ -233,3 +233,52 @@ func TestNodeAddresses(t *testing.T) {
 		t.Errorf("Nodes differ;\n  E: %#v\n  A: %#v", expected, cfg.Nodes)
 	}
 }
+
+func TestNodeAddressesStatic(t *testing.T) {
+	data := []byte(`
+<configuration version="2">
+    <node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ">
+        <address>192.0.2.1</address>
+        <address>192.0.2.2</address>
+    </node>
+    <node id="GYRZZQBIRNPV4T7TC52WEQYJ3TFDQW6MWDFLMU4SSSU6EMFBK2VA">
+        <address>192.0.2.3:6070</address>
+        <address>[2001:db8::42]:4242</address>
+    </node>
+    <node id="LGFPDIT7SKNNJVJZA4FC7QNCRKCE753K72BW5QD2FOZ7FRFEP57Q">
+        <address>[2001:db8::44]:4444</address>
+        <address>192.0.2.4:6090</address>
+    </node>
+</configuration>
+`)
+
+	name, _ := os.Hostname()
+	expected := []NodeConfiguration{
+		{
+			NodeID:    node1,
+			Addresses: []string{"192.0.2.1", "192.0.2.2"},
+		},
+		{
+			NodeID:    node2,
+			Addresses: []string{"192.0.2.3:6070", "[2001:db8::42]:4242"},
+		},
+		{
+			NodeID:    node3,
+			Addresses: []string{"[2001:db8::44]:4444", "192.0.2.4:6090"},
+		},
+		{
+			NodeID:    node4,
+			Name:      name, // Set when auto created
+			Addresses: []string{"dynamic"},
+		},
+	}
+
+	cfg, err := Load(bytes.NewReader(data), node4)
+	if err != nil {
+		t.Error(err)
+	}
+
+	if !reflect.DeepEqual(cfg.Nodes, expected) {
+		t.Errorf("Nodes differ;\n  E: %#v\n  A: %#v", expected, cfg.Nodes)
+	}
+}

+ 1 - 1
gui/app.js

@@ -413,7 +413,6 @@ syncthing.controller('SyncthingCtrl', function ($scope, $http, $translate, $loca
 
         $('#editNode').modal('hide');
         nodeCfg = $scope.currentNode;
-        nodeCfg.NodeID = nodeCfg.NodeID.replace(/ /g, '').replace(/-/g, '').toLowerCase().trim();
         nodeCfg.Addresses = nodeCfg.AddressesStr.split(',').map(function (x) { return x.trim(); });
 
         done = false;
@@ -866,6 +865,7 @@ syncthing.directive('validNodeid', function($http) {
                         if (resp.error) {
                             ctrl.$setValidity('validNodeid', false);
                         } else {
+                            scope.currentNode.NodeID = resp.id;
                             ctrl.$setValidity('validNodeid', true);
                         }
                     });

Some files were not shown because too many files changed in this diff