Exemplo n.º 1
0
func (blacklistManager *URLBlacklistManager) CheckUrl(rawUrl string) (outputURL *url.URL, err error) {
	outputURL, err = url.Parse(rawUrl)
	if err != nil {
		return nil, err
	}

	ipNotBlacklisted, err := iprange.IpOutsideOfRanges(*outputURL, blacklistManager.blacklistIPs)
	if err != nil {
		return nil, err
	}
	if !ipNotBlacklisted {
		return nil, errors.New("Syslog Drain URL is blacklisted")
	}
	return outputURL, nil
}
Exemplo n.º 2
0
func (blacklistManager *URLBlacklistManager) CheckUrl(rawUrl string) (outputURL *url.URL, err error) {
	outputURL, err = url.Parse(rawUrl)
	if err != nil {
		return nil, err
	}

	ipNotBlacklisted, err := iprange.IpOutsideOfRanges(*outputURL, blacklistManager.blacklistIPs)
	if err != nil {
		_, ok := err.(iprange.ResolutionFailure)
		if !ok {
			return nil, err
		}
		blacklistManager.logger.Errorf("Could not resolve URL %s: %s", outputURL, err)

		// Allow the syslog drain backoff to deal with this URL if it
		// continues to not resolve.
		ipNotBlacklisted = true
	}
	if !ipNotBlacklisted {
		return nil, errors.New("Syslog Drain URL is blacklisted")
	}
	return outputURL, nil
}
Exemplo n.º 3
0
		It("accepts start and end as the same", func() {
			ranges := []iprange.IPRange{iprange.IPRange{Start: "127.0.2.2", End: "127.0.2.2"}}
			err := iprange.ValidateIpAddresses(ranges)
			Expect(err).NotTo(HaveOccurred())
		})

	})

	Describe("IpOutsideOfRanges", func() {
		It("parses the IP address properly", func() {
			ranges := []iprange.IPRange{iprange.IPRange{Start: "127.0.1.2", End: "127.0.3.4"}}

			for _, ipTest := range ipTests {
				parsedURL, _ := url.Parse(ipTest.url)
				outOfRange, err := iprange.IpOutsideOfRanges(*parsedURL, ranges)
				Expect(err).NotTo(HaveOccurred())
				Expect(outOfRange).To(Equal(ipTest.output), fmt.Sprintf("Wrong output for url: %s", ipTest.url))
			}
		})

		It("returns error on malformatted URL", func() {
			ranges := []iprange.IPRange{iprange.IPRange{Start: "127.0.2.2", End: "127.0.2.4"}}

			for _, testUrl := range malformattedURLs {
				parsedURL, _ := url.Parse(testUrl.url)
				_, err := iprange.IpOutsideOfRanges(*parsedURL, ranges)
				if err == nil {
					GinkgoT().Fatal(fmt.Sprintf("There should be an error about malformatted URL for %s", testUrl))
				}
			}