<commit_before>package vizzini_test

import (
	"fmt"
	"net/http"

	"github.com/cloudfoundry-incubator/receptor"
	"github.com/cloudfoundry-incubator/runtime-schema/models"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/pivotal-cf-experimental/vizzini/matchers"
)

var _ = Describe("Security groups", func() {
	var listener receptor.DesiredLRPCreateRequest
	var listenerGuid string
	var protectedURL string

	BeforeEach(func() {
		listenerGuid = NewGuid()
		listener = DesiredLRPWithGuid(listenerGuid)

		Ω(client.CreateDesiredLRP(listener)).Should(Succeed())
		Eventually(ActualGetter(listenerGuid, 0)).Should(BeActualLRPWithState(listenerGuid, 0, receptor.ActualLRPStateRunning))
		Eventually(EndpointCurler("http://" + RouteForGuid(listenerGuid) + "/env")).Should(Equal(http.StatusOK))

		listenerActual, err := client.ActualLRPByProcessGuidAndIndex(listenerGuid, 0)
		Ω(err).ShouldNot(HaveOccurred())
		protectedURL = fmt.Sprintf("http://%s:%d/env", listenerActual.Address, listenerActual.Ports[0].HostPort)
	})

	Context("for LRPs", func() {
		var allowedCaller, disallowedCaller receptor.DesiredLRPCreateRequest
		var allowedCallerGuid, disallowedCallerGuid string

		BeforeEach(func() {
			allowedCallerGuid, disallowedCallerGuid = NewGuid(), NewGuid()
			allowedCaller, disallowedCaller = DesiredLRPWithGuid(allowedCallerGuid), DesiredLRPWithGuid(disallowedCallerGuid)

			Ω(client.CreateDesiredLRP(disallowedCaller)).Should(Succeed())
			Eventually(ActualGetter(disallowedCallerGuid, 0)).Should(BeActualLRPWithState(disallowedCallerGuid, 0, receptor.ActualLRPStateRunning))
			Eventually(EndpointCurler("http://" + RouteForGuid(disallowedCallerGuid) + "/env")).Should(Equal(http.StatusOK))

			allowedCaller.EgressRules = []models.SecurityGroupRule{
				{
					Protocol:     models.AllProtocol,
					Destinations: []string{"0.0.0.0/0"},
				},
			}

			Ω(client.CreateDesiredLRP(allowedCaller)).Should(Succeed())
			Eventually(ActualGetter(allowedCallerGuid, 0)).Should(BeActualLRPWithState(allowedCallerGuid, 0, receptor.ActualLRPStateRunning))
			Eventually(EndpointCurler("http://" + RouteForGuid(allowedCallerGuid) + "/env")).Should(Equal(http.StatusOK))
		})

		It("should allow access to the opened up location", func() {
			urlToProxyThroughDisallowedCaller := fmt.Sprintf("http://"+RouteForGuid(disallowedCallerGuid)+"/curl?url=%s", protectedURL)
			urlToProxyThroughAllowedCaller := fmt.Sprintf("http://"+RouteForGuid(allowedCallerGuid)+"/curl?url=%s", protectedURL)

			By("verifiying that calling into the VPC is disallowed")
			resp, err = http.Get(urlToProxyThroughDisallowedCaller)
			Ω(err).ShouldNot(HaveOccurred())
			Ω(resp.StatusCode).Should(Equal(http.StatusInternalServerError))

			By("asserting that opening up the security group rules allow us to call into the VPC")
			resp, err = http.Get(urlToProxyThroughAllowedCaller)
			Ω(err).ShouldNot(HaveOccurred())
			Ω(resp.StatusCode).Should(Equal(http.StatusOK))
		})
	})
<commit_msg>oh hai compiler<commit_after>package vizzini_test

import (
	"fmt"
	"net/http"

	"github.com/cloudfoundry-incubator/receptor"
	"github.com/cloudfoundry-incubator/runtime-schema/models"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/pivotal-cf-experimental/vizzini/matchers"
)

var _ = Describe("Security groups", func() {
	var listener receptor.DesiredLRPCreateRequest
	var listenerGuid string
	var protectedURL string

	BeforeEach(func() {
		listenerGuid = NewGuid()
		listener = DesiredLRPWithGuid(listenerGuid)

		Ω(client.CreateDesiredLRP(listener)).Should(Succeed())
		Eventually(ActualGetter(listenerGuid, 0)).Should(BeActualLRPWithState(listenerGuid, 0, receptor.ActualLRPStateRunning))
		Eventually(EndpointCurler("http://" + RouteForGuid(listenerGuid) + "/env")).Should(Equal(http.StatusOK))

		listenerActual, err := client.ActualLRPByProcessGuidAndIndex(listenerGuid, 0)
		Ω(err).ShouldNot(HaveOccurred())
		protectedURL = fmt.Sprintf("http://%s:%d/env", listenerActual.Address, listenerActual.Ports[0].HostPort)
	})

	Context("for LRPs", func() {
		var allowedCaller, disallowedCaller receptor.DesiredLRPCreateRequest
		var allowedCallerGuid, disallowedCallerGuid string

		BeforeEach(func() {
			allowedCallerGuid, disallowedCallerGuid = NewGuid(), NewGuid()
			allowedCaller, disallowedCaller = DesiredLRPWithGuid(allowedCallerGuid), DesiredLRPWithGuid(disallowedCallerGuid)

			Ω(client.CreateDesiredLRP(disallowedCaller)).Should(Succeed())
			Eventually(ActualGetter(disallowedCallerGuid, 0)).Should(BeActualLRPWithState(disallowedCallerGuid, 0, receptor.ActualLRPStateRunning))
			Eventually(EndpointCurler("http://" + RouteForGuid(disallowedCallerGuid) + "/env")).Should(Equal(http.StatusOK))

			allowedCaller.EgressRules = []models.SecurityGroupRule{
				{
					Protocol:     models.AllProtocol,
					Destinations: []string{"0.0.0.0/0"},
				},
			}

			Ω(client.CreateDesiredLRP(allowedCaller)).Should(Succeed())
			Eventually(ActualGetter(allowedCallerGuid, 0)).Should(BeActualLRPWithState(allowedCallerGuid, 0, receptor.ActualLRPStateRunning))
			Eventually(EndpointCurler("http://" + RouteForGuid(allowedCallerGuid) + "/env")).Should(Equal(http.StatusOK))
		})

		It("should allow access to the opened up location", func() {
			urlToProxyThroughDisallowedCaller := fmt.Sprintf("http://"+RouteForGuid(disallowedCallerGuid)+"/curl?url=%s", protectedURL)
			urlToProxyThroughAllowedCaller := fmt.Sprintf("http://"+RouteForGuid(allowedCallerGuid)+"/curl?url=%s", protectedURL)

			By("verifiying that calling into the VPC is disallowed")
			resp, err := http.Get(urlToProxyThroughDisallowedCaller)
			Ω(err).ShouldNot(HaveOccurred())
			Ω(resp.StatusCode).Should(Equal(http.StatusInternalServerError))

			By("asserting that opening up the security group rules allow us to call into the VPC")
			resp, err = http.Get(urlToProxyThroughAllowedCaller)
			Ω(err).ShouldNot(HaveOccurred())
			Ω(resp.StatusCode).Should(Equal(http.StatusOK))
		})
	})

{'fraction_non_alphanumeric': 0.1317154811715481, 'fraction_numerical': 0.004351464435146443, 'mean_word_length': 6.479349186483104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2451551', 'n_tokens_mistral': 2138, 'n_tokens_neox': 1945, 'n_words': 272}