Ejemplo n.º 1
0
func WrapNetworkErrors(host string, err error) error {
	var innerErr error
	switch typedErr := err.(type) {
	case *url.Error:
		innerErr = typedErr.Err
	case *websocket.DialError:
		innerErr = typedErr.Err
	}

	if innerErr != nil {
		switch typedErr := innerErr.(type) {
		case x509.UnknownAuthorityError:
			return errors.NewInvalidSSLCert(host, "unknown authority")
		case x509.HostnameError:
			return errors.NewInvalidSSLCert(host, "not valid for the requested host")
		case x509.CertificateInvalidError:
			return errors.NewInvalidSSLCert(host, "")
		case *net.OpError:
			return typedErr.Err
		}
	}

	return errors.NewWithError("Error performing request", err)

}
Ejemplo n.º 2
0
func wrapSSLErrorInternal(host string, err error) error {
	switch err.(type) {
	case x509.UnknownAuthorityError:
		return errors.NewInvalidSSLCert(host, "unknown authority")
	case x509.HostnameError:
		return errors.NewInvalidSSLCert(host, "not valid for the requested host")
	case x509.CertificateInvalidError:
		return errors.NewInvalidSSLCert(host, "")
	default:
		return errors.NewWithError("Error performing request", err)
	}
}
Ejemplo n.º 3
0
func wrapSSLErrors(host string, err error) errors.Error {
	urlError, ok := err.(*url.Error)
	if ok {
		switch urlError.Err.(type) {
		case x509.UnknownAuthorityError:
			return errors.NewInvalidSSLCert(host, "unknown authority")
		case x509.HostnameError:
			return errors.NewInvalidSSLCert(host, "not valid for the requested host")
		case x509.CertificateInvalidError:
			return errors.NewInvalidSSLCert(host, "")
		}
	}
	return errors.NewErrorWithError("Error performing request", err)
}
Ejemplo n.º 4
0
}

var _ = Describe("api command", func() {
	var (
		config       configuration.ReadWriter
		endpointRepo *testapi.FakeEndpointRepo
	)

	BeforeEach(func() {
		config = testconfig.NewRepository()
		endpointRepo = &testapi.FakeEndpointRepo{}
	})

	Context("when the api endpoint's ssl certificate is invalid", func() {
		It("warns the user and prints out a tip", func() {
			endpointRepo.UpdateEndpointError = errors.NewInvalidSSLCert("https://buttontomatoes.org", "why? no. go away")
			ui := callApi([]string{"https://buttontomatoes.org"}, config, endpointRepo)

			testassert.SliceContains(ui.Outputs, testassert.Lines{
				{"FAILED"},
				{"SSL cert", "https://buttontomatoes.org"},
				{"TIP", "--skip-ssl-validation"},
			})
		})
	})

	Context("when the user does not provide an endpoint", func() {
		Context("when the endpoint is set in the config", func() {
			var (
				ui                  *testterm.FakeUI
				ctx                 *cli.Context
Ejemplo n.º 5
0
					ItDoesntShowTheTarget()

					It("clears the entire config", func() {
						Expect(Config.ApiEndpoint()).To(BeEmpty())
						Expect(Config.IsSSLDisabled()).To(BeFalse())
						Expect(Config.AccessToken()).To(BeEmpty())
						Expect(Config.RefreshToken()).To(BeEmpty())
						Expect(Config.OrganizationFields().Guid).To(BeEmpty())
						Expect(Config.SpaceFields().Guid).To(BeEmpty())
					})
				})
			})

			Describe("when there is an invalid SSL cert", func() {
				BeforeEach(func() {
					endpointRepo.UpdateEndpointError = errors.NewInvalidSSLCert("https://bobs-burgers.com", "SELF SIGNED SADNESS")
					ui.Inputs = []string{"bobs-burgers.com"}
				})

				It("fails and suggests the user skip SSL validation", func() {
					testassert.SliceContains(ui.Outputs, testassert.Lines{
						{"FAILED"},
						{"SSL cert", "https://bobs-burgers.com"},
						{"TIP", "--skip-ssl-validation"},
					})
				})

				ItDoesntShowTheTarget()
			})
		})
Ejemplo n.º 6
0
		})
	})

	Context("when the loggregator server has an invalid cert", func() {
		var (
			reqFactory *testreq.FakeReqFactory
			logsRepo   *testapi.FakeLogsRepository
		)

		BeforeEach(func() {
			reqFactory, logsRepo = getLogsDependencies()
		})

		Context("when the skip-ssl-validation flag is not set", func() {
			It("fails and informs the user about the skip-ssl-validation flag", func() {
				logsRepo.TailLogErr = errors.NewInvalidSSLCert("https://example.com", "it don't work good")
				ui := callLogs([]string{"my-app"}, reqFactory, logsRepo)

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"Received invalid SSL certificate", "https://example.com"},
					{"TIP"},
				})
			})

			It("informs the user of the error when they include the --recent flag", func() {
				logsRepo.RecentLogErr = errors.NewInvalidSSLCert("https://example.com", "how does SSL work???")
				ui := callLogs([]string{"--recent", "my-app"}, reqFactory, logsRepo)

				testassert.SliceContains(ui.Outputs, testassert.Lines{
					{"Received invalid SSL certificate", "https://example.com"},
					{"TIP"},