|
@@ -4,6 +4,8 @@
|
|
|
package urllib // import "miniflux.app/v2/internal/urllib"
|
|
package urllib // import "miniflux.app/v2/internal/urllib"
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "errors"
|
|
|
|
|
+ "io"
|
|
|
"net"
|
|
"net"
|
|
|
"net/url"
|
|
"net/url"
|
|
|
"testing"
|
|
"testing"
|
|
@@ -288,6 +290,83 @@ func TestRedactedURL(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func TestRedactURLInError(t *testing.T) {
|
|
|
|
|
+ tests := []struct {
|
|
|
|
|
+ name string
|
|
|
|
|
+ err error
|
|
|
|
|
+ want string
|
|
|
|
|
+ }{
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "password and token",
|
|
|
|
|
+ err: &url.Error{Op: "Get", URL: "https://user:secret@bridge.example.org/?action=display&token=secret", Err: io.ErrUnexpectedEOF},
|
|
|
|
|
+ want: `Get "https://user:xxxxx@bridge.example.org/?action=display&token=xxxxx": unexpected EOF`,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "unparsable URL",
|
|
|
|
|
+ err: &url.Error{Op: "parse", URL: "https://user:secret@example.org/\n", Err: errors.New("net/url: invalid control character in URL")},
|
|
|
|
|
+ want: `parse "xxxxx": net/url: invalid control character in URL`,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "error without URL",
|
|
|
|
|
+ err: io.ErrUnexpectedEOF,
|
|
|
|
|
+ want: "unexpected EOF",
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, tt := range tests {
|
|
|
|
|
+ t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
+ if got := RedactURLInError(tt.err).Error(); got != tt.want {
|
|
|
|
|
+ t.Fatalf("expected %q, got %q", tt.want, got)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if err := RedactURLInError(nil); err != nil {
|
|
|
|
|
+ t.Fatalf("expected nil, got %v", err)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func TestRedactSecretURLInError(t *testing.T) {
|
|
|
|
|
+ tests := []struct {
|
|
|
|
|
+ name string
|
|
|
|
|
+ err error
|
|
|
|
|
+ want string
|
|
|
|
|
+ }{
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "network error",
|
|
|
|
|
+ err: &url.Error{Op: "Post", URL: "https://example.org/bot123:secret-token/sendMessage?key=secret-token", Err: io.ErrUnexpectedEOF},
|
|
|
|
|
+ want: `Post "https://example.org/xxxxx": unexpected EOF`,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "network error with userinfo and port",
|
|
|
|
|
+ err: &url.Error{Op: "Get", URL: "https://user:password@example.org:8443/secret-token", Err: io.ErrUnexpectedEOF},
|
|
|
|
|
+ want: `Get "https://example.org:8443/xxxxx": unexpected EOF`,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "unparsable URL",
|
|
|
|
|
+ err: &url.Error{Op: "parse", URL: "https://example.org/secret-token\n", Err: errors.New("net/url: invalid control character in URL")},
|
|
|
|
|
+ want: `parse "xxxxx": net/url: invalid control character in URL`,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "error without URL",
|
|
|
|
|
+ err: io.ErrUnexpectedEOF,
|
|
|
|
|
+ want: "unexpected EOF",
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, tt := range tests {
|
|
|
|
|
+ t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
+ if got := RedactSecretURLInError(tt.err).Error(); got != tt.want {
|
|
|
|
|
+ t.Fatalf("expected %q, got %q", tt.want, got)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if err := RedactSecretURLInError(nil); err != nil {
|
|
|
|
|
+ t.Fatalf("expected nil, got %v", err)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func TestIsNonPublicIP(t *testing.T) {
|
|
func TestIsNonPublicIP(t *testing.T) {
|
|
|
testCases := []struct {
|
|
testCases := []struct {
|
|
|
name string
|
|
name string
|