summaryrefslogtreecommitdiff
path: root/plugins/websockets/origin_test.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-06-21 11:41:42 +0300
committerValery Piashchynski <[email protected]>2021-06-21 11:41:42 +0300
commitbdcfdd28d705e401973da2beb8a11543e362bda4 (patch)
tree6a80b5b78ce18c7ddf298861d5b0cd05d8c64ccf /plugins/websockets/origin_test.go
parentcee4bc46097506d6e892b6af194751434700621a (diff)
parent87d023d32feef5fe28c9bb65a796deb77d536b15 (diff)
Merge remote-tracking branch 'origin/master' into feature/jobs_plugin
# Conflicts: # plugins/websockets/plugin.go
Diffstat (limited to 'plugins/websockets/origin_test.go')
-rw-r--r--plugins/websockets/origin_test.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/plugins/websockets/origin_test.go b/plugins/websockets/origin_test.go
new file mode 100644
index 00000000..bbc49bbb
--- /dev/null
+++ b/plugins/websockets/origin_test.go
@@ -0,0 +1,73 @@
+package websockets
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestConfig_Origin(t *testing.T) {
+ cfg := &Config{
+ AllowedOrigin: "*",
+ Broker: "any",
+ }
+
+ err := cfg.InitDefault()
+ assert.NoError(t, err)
+
+ assert.True(t, isOriginAllowed("http://some.some.some.sssome", cfg))
+ assert.True(t, isOriginAllowed("http://", cfg))
+ assert.True(t, isOriginAllowed("http://google.com", cfg))
+ assert.True(t, isOriginAllowed("ws://*", cfg))
+ assert.True(t, isOriginAllowed("*", cfg))
+ assert.True(t, isOriginAllowed("you are bad programmer", cfg)) // True :(
+ assert.True(t, isOriginAllowed("****", cfg))
+ assert.True(t, isOriginAllowed("asde!@#!!@#!%", cfg))
+ assert.True(t, isOriginAllowed("http://*.domain.com", cfg))
+}
+
+func TestConfig_OriginWildCard(t *testing.T) {
+ cfg := &Config{
+ AllowedOrigin: "https://*my.site.com",
+ Broker: "any",
+ }
+
+ err := cfg.InitDefault()
+ assert.NoError(t, err)
+
+ assert.True(t, isOriginAllowed("https://my.site.com", cfg))
+ assert.False(t, isOriginAllowed("http://", cfg))
+ assert.False(t, isOriginAllowed("http://google.com", cfg))
+ assert.False(t, isOriginAllowed("ws://*", cfg))
+ assert.False(t, isOriginAllowed("*", cfg))
+ assert.False(t, isOriginAllowed("you are bad programmer", cfg)) // True :(
+ assert.False(t, isOriginAllowed("****", cfg))
+ assert.False(t, isOriginAllowed("asde!@#!!@#!%", cfg))
+ assert.False(t, isOriginAllowed("http://*.domain.com", cfg))
+
+ assert.False(t, isOriginAllowed("https://*site.com", cfg))
+ assert.True(t, isOriginAllowed("https://some.my.site.com", cfg))
+}
+
+func TestConfig_OriginWildCard2(t *testing.T) {
+ cfg := &Config{
+ AllowedOrigin: "https://my.*.com",
+ Broker: "any",
+ }
+
+ err := cfg.InitDefault()
+ assert.NoError(t, err)
+
+ assert.True(t, isOriginAllowed("https://my.site.com", cfg))
+ assert.False(t, isOriginAllowed("http://", cfg))
+ assert.False(t, isOriginAllowed("http://google.com", cfg))
+ assert.False(t, isOriginAllowed("ws://*", cfg))
+ assert.False(t, isOriginAllowed("*", cfg))
+ assert.False(t, isOriginAllowed("you are bad programmer", cfg)) // True :(
+ assert.False(t, isOriginAllowed("****", cfg))
+ assert.False(t, isOriginAllowed("asde!@#!!@#!%", cfg))
+ assert.False(t, isOriginAllowed("http://*.domain.com", cfg))
+
+ assert.False(t, isOriginAllowed("https://*site.com", cfg))
+ assert.True(t, isOriginAllowed("https://my.bad.com", cfg))
+}