Added link sanitization tests
This commit is contained in:
committed by
Vivek Patel
parent
f1f4f4bd1d
commit
0996f80dbe
@@ -43,6 +43,6 @@ func Test_logoutProc(t *testing.T) {
|
||||
rq.Empty(authReq.Session.Values)
|
||||
rq.Empty(authReq.AuthUser)
|
||||
rq.Empty(authReq.Client)
|
||||
rq.Equal("scriptalert(origin)/script", authReq.Data["link"])
|
||||
rq.Equal("//scriptalert(origin)/script", authReq.Data["link"])
|
||||
rq.Equal(TmplLogout, authReq.Template)
|
||||
}
|
||||
|
||||
41
auth/handlers/links_test.go
Normal file
41
auth/handlers/links_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_sanitizeLink(t *testing.T) {
|
||||
type (
|
||||
tt struct {
|
||||
name string
|
||||
link string
|
||||
expect string
|
||||
}
|
||||
)
|
||||
|
||||
tcc := []tt{
|
||||
{
|
||||
name: `empty link`,
|
||||
link: ``,
|
||||
expect: `//`,
|
||||
},
|
||||
{
|
||||
name: `Example URL with query`,
|
||||
link: `https://example.url/query`,
|
||||
expect: `//example.url/query`,
|
||||
},
|
||||
{
|
||||
name: `URL with additional js`,
|
||||
link: `javascript:window.alert('foobar')`,
|
||||
expect: `//javascript:window.alert(foobar)`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
require.New(t).Equal(tc.expect, sanitizeLink(tc.link))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user