scheduler: fix errors perms

This commit is contained in:
Aloïs Micard 2020-12-22 12:50:46 +01:00
parent dea2cfe7b0
commit ac983b25ef
No known key found for this signature in database
GPG Key ID: 1A0EB82F071F5EFE
2 changed files with 12 additions and 12 deletions

View File

@ -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!

View File

@ -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()
}
}