@@ -16,6 +16,7 @@ import (
1616 "github.com/gin-gonic/gin"
1717 "github.com/gorilla/websocket"
1818 "github.com/gotify/server/v3/auth"
19+ "github.com/gotify/server/v3/config"
1920 "github.com/gotify/server/v3/mode"
2021 "github.com/gotify/server/v3/model"
2122 "github.com/stretchr/testify/assert"
@@ -481,16 +482,22 @@ func Test_isAllowedOrigin_withoutAllowedOrigins_failsWhenNotSameOrigin(t *testin
481482
482483func Test_isAllowedOriginMatching (t * testing.T ) {
483484 mode .Set (mode .Prod )
484- compiledAllowedOrigins := compileAllowedWebSocketOrigins ([]string {"go.{4} \\ .example \\ .com " , "go \\ .example \\ .com " })
485+ compiledAllowedOrigins := config . CompileAllowedOrigins ([]string {"gotify \\ .net|push \\ .gotify \\ .net " , "other \\ .gotify \\ .net " })
485486
486487 req := httptest .NewRequest ("GET" , "http://example.me/stream" , nil )
487- req .Header .Set ("Origin" , "http://gorify.example.com" )
488+ req .Header .Set ("Origin" , "http://gotify.net" )
489+ assert .True (t , isAllowedOrigin (req , compiledAllowedOrigins ))
490+
491+ req .Header .Set ("Origin" , "http://push.gotify.net" )
488492 assert .True (t , isAllowedOrigin (req , compiledAllowedOrigins ))
489493
490- req .Header .Set ("Origin" , "http://go.example.com " )
494+ req .Header .Set ("Origin" , "http://other.gotify.net " )
491495 assert .True (t , isAllowedOrigin (req , compiledAllowedOrigins ))
492496
493- req .Header .Set ("Origin" , "http://hello.example.com" )
497+ req .Header .Set ("Origin" , "http://gotify.net.evil.net" )
498+ assert .False (t , isAllowedOrigin (req , compiledAllowedOrigins ))
499+
500+ req .Header .Set ("Origin" , "http://evil-gotify.net" )
494501 assert .False (t , isAllowedOrigin (req , compiledAllowedOrigins ))
495502}
496503
@@ -517,11 +524,6 @@ func Test_invalidOrigin_returnsFalse(t *testing.T) {
517524 assert .False (t , actual )
518525}
519526
520- func Test_compileAllowedWebSocketOrigins (t * testing.T ) {
521- assert .Equal (t , 0 , len (compileAllowedWebSocketOrigins ([]string {})))
522- assert .Equal (t , 3 , len (compileAllowedWebSocketOrigins ([]string {"^.*$" , "" , "abc" })))
523- }
524-
525527func clients (api * API , user uint ) []* client {
526528 api .lock .RLock ()
527529 defer api .lock .RUnlock ()
0 commit comments