-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
29 lines (22 loc) · 784 Bytes
/
Copy patherrors_test.go
File metadata and controls
29 lines (22 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package safehttp_test
import (
"errors"
"testing"
safehttp "github.com/ayuhito/safehttp"
"github.com/stretchr/testify/require"
)
func TestErrorBehavior(t *testing.T) {
guard, err := safehttp.NewGuard()
require.NoError(t, err)
err = guard.CheckURL(mustURL(t, "https://user:pass@example.com/path?token=secret"))
require.ErrorIs(t, err, safehttp.ErrBlocked)
require.ErrorIs(t, err, safehttp.ErrBlockedCredentials)
block, ok := errors.AsType[*safehttp.BlockError](err)
require.True(t, ok)
require.NotNil(t, block)
require.NotContains(t, block.URL, "user")
require.NotContains(t, block.URL, "pass")
require.NotContains(t, block.URL, "token")
msg := (&safehttp.BlockError{Reason: "blocked", Host: "example.com"}).Error()
require.Equal(t, "safehttp: blocked", msg)
}