Browse Source

daemon/config: Validate() also validate default MTU

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 năm trước cách đây
mục cha
commit
f8231c62f4
2 tập tin đã thay đổi với 20 bổ sung0 xóa
  1. 3 0
      daemon/config/config.go
  2. 17 0
      daemon/config/config_test.go

+ 3 - 0
daemon/config/config.go

@@ -597,6 +597,9 @@ func Validate(config *Config) error {
 	}
 
 	// TODO(thaJeztah) Validations below should not accept "0" to be valid; see Validate() for a more in-depth description of this problem
+	if config.Mtu < 0 {
+		return fmt.Errorf("invalid default MTU: %d", config.Mtu)
+	}
 	if config.MaxConcurrentDownloads < 0 {
 		return fmt.Errorf("invalid max concurrent downloads: %d", config.MaxConcurrentDownloads)
 	}

+ 17 - 0
daemon/config/config_test.go

@@ -280,6 +280,15 @@ func TestValidateConfigurationErrors(t *testing.T) {
 			},
 			expectedErr: "123456 is not a valid domain",
 		},
+		{
+			name: "negative MTU",
+			config: &Config{
+				CommonConfig: CommonConfig{
+					Mtu: -10,
+				},
+			},
+			expectedErr: "invalid default MTU: -10",
+		},
 		{
 			name: "negative max-concurrent-downloads",
 			config: &Config{
@@ -397,6 +406,14 @@ func TestValidateConfiguration(t *testing.T) {
 				},
 			},
 		},
+		{
+			name: "with mtu",
+			config: &Config{
+				CommonConfig: CommonConfig{
+					Mtu: 1234,
+				},
+			},
+		},
 		{
 			name: "with max-concurrent-downloads",
 			config: &Config{