validator

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CheckErrorMessages = map[CheckErrorMSG]string{
	ErrInvalidSchema:         "Invalid URL schema. Only 'http' or 'https' are allowed.",
	ErrFileNotAllowed:        "Files are not allowed.",
	ErrMaxRedirectsExceeded:  "Maximum number of redirects exceeded.",
	ErrSizeExceeded:          "URL size exceeds the maximum allowed size.",
	ErrURLLengthExceeded:     "URL length exceeds the maximum allowed length.",
	ErrUnreachable:           "URL is unreachable.",
	ErrMustHaveTLD:           "URL must have a valid top-level domain (TLD).",
	ErrURLCannotContainCreds: "URL should not contain credentials.",
	ErrURLCannotEndWithSlash: "URL should not end with a slash.",
	ErrHTTPClientTimeout:     "Website is taking too long to respond",
	ErrHTTPSRequired:         "HTTPS is required.",
	ErrDNSRecordNotFound:     "DNS record not found.",
	ErrSeekerNotInitialized:  "Seeker is not initialized.",
	ErrIsNotAbsoluteURL:      "URL is not absolute.",
	ErrContentTypeNotAllowed: "Content type is not allowed.",
	ErrContentTypeIsEmpty:    "Content type is empty.",
	ErrDNSNameValueNull:      "DNS name value is null.",
}
View Source
var DefaultCheckConfig = CheckConfig{
	MaxRedirects:          2,
	MaxSize:               4194304,
	MaxURLLength:          2048,
	CheckForFile:          true,
	CheckIsReachable:      true,
	CannotEndWithSlash:    true,
	HTTPSRequired:         false,
	HTTPClientTimeout:     10 * time.Second,
	ContentTypeMustBeHTML: true,
}

Functions

func HasValidTLD

func HasValidTLD(host string) bool

Types

type CheckConfig

type CheckConfig struct {
	MaxRedirects          int           `koanf:"max_redirects"`
	MaxSize               int64         `koanf:"max_size"`
	MaxURLLength          int           `koanf:"max_url_length"`
	CheckForFile          bool          `koanf:"check_for_file"`
	CheckIsReachable      bool          `koanf:"check_is_reachable"`
	CannotEndWithSlash    bool          `koanf:"cannot_end_with_slash"`
	HTTPClientTimeout     time.Duration `koanf:"http_client_timeout"`
	HTTPSRequired         bool          `koanf:"https_required"`
	ContentTypeMustBeHTML bool          `koanf:"content_type_must_be_html"`
}

CheckConfig holds the configuration for URL checking.

type CheckError

type CheckError struct {
	Msg string
}

func (CheckError) Error

func (e CheckError) Error() string

type CheckErrorMSG

type CheckErrorMSG int
const (
	ErrInvalidSchema CheckErrorMSG = iota
	ErrFileNotAllowed
	ErrMaxRedirectsExceeded
	ErrSizeExceeded
	ErrURLLengthExceeded
	ErrLoginKeywordsFound
	ErrXSSDetected
	ErrUnreachable
	ErrMustHaveTLD
	ErrURLCannotContainCreds
	ErrURLCannotEndWithSlash
	ErrHTTPClientTimeout
	ErrHTTPSRequired
	ErrDNSRecordNotFound
	ErrSeekerNotInitialized
	ErrIsNotAbsoluteURL
	ErrContentTypeNotAllowed
	ErrContentTypeIsEmpty
	ErrDNSNameValueNull
)

type DNSRecord

type DNSRecord struct {
	RecordType string
	Records    []string
}

type Seeker

type Seeker struct {
	Config   CheckConfig
	InputURL string
	Client   *colly.Collector
	Logs     *SeekerLogs
}

func NewSeeker

func NewSeeker(config CheckConfig, collector *colly.Collector) (seeker *Seeker)

func (Seeker) GetCollector

func (s Seeker) GetCollector() *colly.Collector

func (Seeker) Seek

func (s Seeker) Seek(inputURL string) (err error)

type SeekerLogs

type SeekerLogs struct {
	StartAt           time.Time
	FirstByteDuration time.Duration
	Duration          time.Duration
	ContentLength     int64
	Content           *[]byte
	Redirects         *[]http.Request
	ContentType       string
	StatusCode        int
}

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

func DefaultValidator

func DefaultValidator() *Validator

func NewValidator

func NewValidator(config CheckConfig) *Validator

func (Validator) ValidateOwnershipOverDNSTxtRecord

func (v Validator) ValidateOwnershipOverDNSTxtRecord(inputURL string, DNSName string, DNSValue string, DNSServer string) (isValid bool, err error)

func (Validator) ValidateSite added in v0.0.4

func (v Validator) ValidateSite(inputURL string) (isValid bool, err error)

Validate a Website via visiting the URL and checking the response according to the configuration.

func (Validator) ValidateURL

func (v Validator) ValidateURL(inputURL string) (isValid bool, err error)

CheckURL validates a URL based on the given configuration and returns custom errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL