<commit_before>package acceptance_test

import (
	"net"
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/gexec"

	"github.com/cloudfoundry-incubator/cf-test-helpers/cf"
	"github.com/cloudfoundry-incubator/cf-test-helpers/generator"
)

var _ = Describe("plain HTTP requests", func() {
	const (
		CONNECTION_TIMEOUT = 11 * time.Second
	)

	Describe("to the API", func() {
		It("has the connection refused", func() {
			uri := config.ApiEndpoint + ":80"
			_, err := net.DialTimeout("tcp", uri, CONNECTION_TIMEOUT)
			Expect(err).To(HaveOccurred(), "should not connect")
			Expect(err.(net.Error).Timeout()).To(BeTrue(), "should timeout")
		})
	})

	Describe("to an app", func() {
		It("has the connection refused", func() {
			appName := generator.PrefixedRandomName("CATS-APP-")
			Expect(cf.Cf(
				"push", appName,
				"-b", config.StaticFileBuildpackName,
				"-p", "../../example-apps/static-app",
				"-d", config.AppsDomain,
			).Wait(CF_PUSH_TIMEOUT)).To(Exit(0))

			uri := appName + "." + config.AppsDomain + ":80"
			_, err := net.DialTimeout("tcp", uri, CONNECTION_TIMEOUT)
			Expect(err).To(HaveOccurred(), "should not connect")
			Expect(err.(net.Error).Timeout()).To(BeTrue(), "should timeout")
		})
	})
})<commit_msg>Add acceptance tests for http redirect behaviour.<commit_after>package acceptance_test

import (
	"fmt"
	"net"
	"net/http"
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("plain HTTP requests", func() {
	const (
		CONNECTION_TIMEOUT = 11 * time.Second
	)

	Describe("to the API", func() {
		It("has the connection refused", func() {
			uri := config.ApiEndpoint + ":80"
			_, err := net.DialTimeout("tcp", uri, CONNECTION_TIMEOUT)
			Expect(err).To(HaveOccurred(), "should not connect")
			Expect(err.(net.Error).Timeout()).To(BeTrue(), "should timeout")
		})
	})

	Describe("to an app", func() {
		It("is redirected to the https endpoint", func() {
			req, err := http.NewRequest("GET", fmt.Sprintf("http://foo.%s/", config.AppsDomain), nil)
			Expect(err).NotTo(HaveOccurred())
			resp, err := http.DefaultTransport.RoundTrip(req)
			Expect(err).NotTo(HaveOccurred())

			Expect(resp.StatusCode).To(Equal(301))
			Expect(resp.Header.Get("Location")).To(Equal(fmt.Sprintf("https://foo.%s/", config.AppsDomain)))
		})

		It("has any path and query components removed when redirecting", func() {
			req, err := http.NewRequest("GET", fmt.Sprintf("http://foo.%s/bar?baz=qux", config.AppsDomain), nil)
			Expect(err).NotTo(HaveOccurred())
			resp, err := http.DefaultTransport.RoundTrip(req)
			Expect(err).NotTo(HaveOccurred())

			Expect(resp.StatusCode).To(Equal(301))
			Expect(resp.Header.Get("Location")).To(Equal(fmt.Sprintf("https://foo.%s/", config.AppsDomain)))
		})
	})
})
{'fraction_non_alphanumeric': 0.1909709781440344, 'fraction_numerical': 0.006091006807595844, 'mean_word_length': 4.3486590038314175, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2005714', 'n_tokens_mistral': 1085, 'n_tokens_neox': 981, 'n_words': 174}