mirror of
https://github.com/creekorful/bathyscaphe
synced 2024-11-16 00:12:56 +00:00
scheduler: fix errors perms
This commit is contained in:
parent
dea2cfe7b0
commit
ac983b25ef
@ -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!
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user