summaryrefslogtreecommitdiffstats
path: root/model/config_test.go
diff options
context:
space:
mode:
authorMartin Kraft <mkraft@users.noreply.github.com>2018-07-30 14:59:08 -0400
committerGitHub <noreply@github.com>2018-07-30 14:59:08 -0400
commit65cd447a61efa852da2c0e7db25f385c2436e236 (patch)
tree15954e1f0a1405cb916e19462174c7186684e7b2 /model/config_test.go
parentd23ca07133e9bc5eed14d87af563471b4ef963cd (diff)
downloadchat-65cd447a61efa852da2c0e7db25f385c2436e236.tar.gz
chat-65cd447a61efa852da2c0e7db25f385c2436e236.tar.bz2
chat-65cd447a61efa852da2c0e7db25f385c2436e236.zip
MM-11301: Validates listen address config value. (#9138)
* MM-11301: Validates listen address config value. * MM-11301: Adds some invalid port test cases. * MM-11301: Accept domain names. * MM-11301: Fix for max port.
Diffstat (limited to 'model/config_test.go')
-rw-r--r--model/config_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/model/config_test.go b/model/config_test.go
index 848f4327e..179bab8e2 100644
--- a/model/config_test.go
+++ b/model/config_test.go
@@ -519,3 +519,45 @@ func TestDisplaySettingsIsValidCustomUrlSchemes(t *testing.T) {
})
}
}
+
+func TestListenAddressIsValidated(t *testing.T) {
+
+ testValues := map[string]bool{
+ ":8065": true,
+ ":9917": true,
+ "0.0.0.0:9917": true,
+ "[2001:db8::68]:9918": true,
+ "[::1]:8065": true,
+ "localhost:8065": true,
+ "test.com:8065": true,
+ ":0": true,
+ ":33147": true,
+ "123:8065": false,
+ "[::1]:99999": false,
+ "[::1]:-1": false,
+ "[::1]:8065a": false,
+ "0.0.0:9917": false,
+ "0.0.0.0:9917/": false,
+ "0..0.0:9917/": false,
+ "0.0.0222.0:9917/": false,
+ "http://0.0.0.0:9917/": false,
+ "http://0.0.0.0:9917": false,
+ "8065": false,
+ "[2001:db8::68]": false,
+ }
+
+ for key, expected := range testValues {
+ ss := &ServiceSettings{
+ ListenAddress: NewString(key),
+ }
+ ss.SetDefaults()
+ if expected {
+ require.Nil(t, ss.isValid(), fmt.Sprintf("Got an error from '%v'.", key))
+ } else {
+ err := ss.isValid()
+ require.NotNil(t, err, fmt.Sprintf("Expected '%v' to throw an error.", key))
+ require.Equal(t, "model.config.is_valid.listen_address.app_error", err.Message)
+ }
+ }
+
+}