From ac983b25ef0768a62337f288a08130b80bb2f35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alo=C3=AFs=20Micard?= Date: Tue, 22 Dec 2020 12:50:46 +0100 Subject: [PATCH] scheduler: fix errors perms --- internal/scheduler/scheduler.go | 16 ++++++++-------- internal/scheduler/scheduler_test.go | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/scheduler/scheduler.go b/internal/scheduler/scheduler.go index 7c1c9df..48877f9 100644 --- a/internal/scheduler/scheduler.go +++ b/internal/scheduler/scheduler.go @@ -20,10 +20,10 @@ import ( ) var ( - ErrNotOnionHostname = errors.New("hostname is not .onion") - ErrProtocolNotAllowed = errors.New("protocol is not allowed") - ErrExtensionNotAllowed = errors.New("extension is not allowed") - ErrShouldNotSchedule = errors.New("should not be scheduled") + errNotOnionHostname = errors.New("hostname is not .onion") + errProtocolNotAllowed = errors.New("protocol is not allowed") + errExtensionNotAllowed = errors.New("extension is not allowed") + errShouldNotSchedule = errors.New("should not be scheduled") ) // GetApp return the scheduler app @@ -120,18 +120,18 @@ func (state *state) handleURLFoundEvent(subscriber event.Subscriber, body io.Rea // Make sure URL is valid .onion if !strings.Contains(u.Host, ".onion") { - return fmt.Errorf("%s %w", u.Host, ErrNotOnionHostname) + return fmt.Errorf("%s %w", u.Host, errNotOnionHostname) } // Make sure protocol is allowed if !strings.HasPrefix(u.Scheme, "http") { - return fmt.Errorf("%s %w", u, ErrProtocolNotAllowed) + return fmt.Errorf("%s %w", u, errProtocolNotAllowed) } // Make sure extension is not forbidden for _, ext := range state.forbiddenExtensions { if strings.HasSuffix(u.Path, "."+ext) { - return fmt.Errorf("%s (.%s) %w", u, ext, ErrExtensionNotAllowed) + return fmt.Errorf("%s (.%s) %w", u, ext, errExtensionNotAllowed) } } @@ -148,7 +148,7 @@ func (state *state) handleURLFoundEvent(subscriber event.Subscriber, body io.Rea } if count > 0 { - return fmt.Errorf("%s %w", u, ErrShouldNotSchedule) + return fmt.Errorf("%s %w", u, errShouldNotSchedule) } // No matches: schedule! diff --git a/internal/scheduler/scheduler_test.go b/internal/scheduler/scheduler_test.go index d179fc2..1d50428 100644 --- a/internal/scheduler/scheduler_test.go +++ b/internal/scheduler/scheduler_test.go @@ -32,7 +32,7 @@ func TestHandleMessageNotOnion(t *testing.T) { forbiddenExtensions: []string{}, } - if err := s.handleURLFoundEvent(subscriberMock, msg); !errors.Is(err, ErrNotOnionHostname) { + if err := s.handleURLFoundEvent(subscriberMock, msg); !errors.Is(err, errNotOnionHostname) { t.FailNow() } } @@ -58,7 +58,7 @@ func TestHandleMessageWrongProtocol(t *testing.T) { SetArg(1, event.FoundURLEvent{URL: fmt.Sprintf("%s://example.onion", protocol)}). Return(nil) - if err := s.handleURLFoundEvent(subscriberMock, msg); !errors.Is(err, ErrProtocolNotAllowed) { + if err := s.handleURLFoundEvent(subscriberMock, msg); !errors.Is(err, errProtocolNotAllowed) { t.FailNow() } } @@ -87,7 +87,7 @@ func TestHandleMessageAlreadyCrawled(t *testing.T) { forbiddenExtensions: []string{"png"}, } - if err := s.handleURLFoundEvent(subscriberMock, msg); !errors.Is(err, ErrShouldNotSchedule) { + if err := s.handleURLFoundEvent(subscriberMock, msg); !errors.Is(err, errShouldNotSchedule) { t.FailNow() } } @@ -111,7 +111,7 @@ func TestHandleMessageForbiddenExtensions(t *testing.T) { forbiddenExtensions: []string{"png"}, } - if err := s.handleURLFoundEvent(subscriberMock, msg); !errors.Is(err, ErrExtensionNotAllowed) { + if err := s.handleURLFoundEvent(subscriberMock, msg); !errors.Is(err, errExtensionNotAllowed) { t.FailNow() } }