<commit_before>package acceptance_test

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

	"encoding/json"
	"io/ioutil"
	"net/http"
	"net/url"

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

var _ = Describe("AccountManagement", func() {
	const email = "<EMAIL>"

	var (
		params   url.Values
		password string
		authURL  *url.URL
	)

	BeforeEach(func() {
		params = url.Values{}
		params.Set("client_id", "")
		params.Set("redirect_uri", "")

		password = generator.PrefixedRandomName(testConfig.NamePrefix, "PASSWORD")

		infoCommand := cf.Cf("curl", "/v2/info")
		Expect(infoCommand.Wait(testConfig.DefaultTimeoutDuration())).To(Exit(0))

		var infoResp struct {
			AuthorizationEndpoint string `json:"authorization_endpoint"`
		}

		err := json.Unmarshal(infoCommand.Buffer().Contents(), &infoResp)
		Expect(err).NotTo(HaveOccurred())

		authURL, err = url.Parse(infoResp.AuthorizationEndpoint)
		Expect(err).NotTo(HaveOccurred())
	})

	Describe("login server /create_account endpoint", func() {
		It("should not allow access to the create account page", func() {
			createAccountURL := authURL
			createAccountURL.Path = "/create_account"

			resp, err := httpClient.Get(createAccountURL.String())
			Expect(err).NotTo(HaveOccurred())

			defer resp.Body.Close()
			body, err := ioutil.ReadAll(resp.Body)
			Expect(err).NotTo(HaveOccurred())
			Expect(resp.StatusCode).To(Equal(http.StatusNotFound), "wrong status code, body:\n\n %s", body)
			Expect(body).To(ContainSubstring("Something went amiss"))
		})

		It("should not allow anonymous users to create accounts", func() {
			createAccountURL := authURL
			createAccountURL.Path = "/create_account.do"

			params.Set("email", email)
			params.Set("password", password)
			params.Set("password_confirmation", password)

			resp, err := httpClient.PostForm(createAccountURL.String(), params)
			Expect(err).NotTo(HaveOccurred())

			defer resp.Body.Close()
			body, err := ioutil.ReadAll(resp.Body)
			Expect(err).NotTo(HaveOccurred())
			Expect(resp.StatusCode).To(Equal(http.StatusNotFound), "wrong status code, body:\n\n %s", body)
			Expect(body).To(ContainSubstring("Something went amiss"))
		})
	})

	Describe("login server /forgot_password endpoint", func() {
		It("should not allow access to the forgot password page", func() {
			resetPasswordURL := authURL
			resetPasswordURL.Path = "/forgot_password"

			params.Set("email", email)

			resp, err := httpClient.Get(resetPasswordURL.String())
			Expect(err).NotTo(HaveOccurred())

			defer resp.Body.Close()
			body, err := ioutil.ReadAll(resp.Body)
			Expect(err).NotTo(HaveOccurred())
			Expect(resp.StatusCode).To(Equal(http.StatusNotFound), "wrong status code, body:\n\n %s", body)
			Expect(body).To(ContainSubstring("Something went amiss"))
		})

		It("should not allow users to reset forgotten passwords", func() {
			resetPasswordURL := authURL
			resetPasswordURL.Path = "/forgot_password.do"

			params.Set("email", email)

			resp, err := httpClient.PostForm(resetPasswordURL.String(), params)
			Expect(err).NotTo(HaveOccurred())

			defer resp.Body.Close()
			body, err := ioutil.ReadAll(resp.Body)
			Expect(err).NotTo(HaveOccurred())<commit_msg>Change form field for forgot password test<commit_after>package acceptance_test

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

	"encoding/json"
	"io/ioutil"
	"net/http"
	"net/url"

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

var _ = Describe("AccountManagement", func() {
	const email = "<EMAIL>"

	var (
		params   url.Values
		password string
		authURL  *url.URL
	)

	BeforeEach(func() {
		params = url.Values{}
		params.Set("client_id", "")
		params.Set("redirect_uri", "")

		password = generator.PrefixedRandomName(testConfig.NamePrefix, "PASSWORD")

		infoCommand := cf.Cf("curl", "/v2/info")
		Expect(infoCommand.Wait(testConfig.DefaultTimeoutDuration())).To(Exit(0))

		var infoResp struct {
			AuthorizationEndpoint string `json:"authorization_endpoint"`
		}

		err := json.Unmarshal(infoCommand.Buffer().Contents(), &infoResp)
		Expect(err).NotTo(HaveOccurred())

		authURL, err = url.Parse(infoResp.AuthorizationEndpoint)
		Expect(err).NotTo(HaveOccurred())
	})

	Describe("login server /create_account endpoint", func() {
		It("should not allow access to the create account page", func() {
			createAccountURL := authURL
			createAccountURL.Path = "/create_account"

			resp, err := httpClient.Get(createAccountURL.String())
			Expect(err).NotTo(HaveOccurred())

			defer resp.Body.Close()
			body, err := ioutil.ReadAll(resp.Body)
			Expect(err).NotTo(HaveOccurred())
			Expect(resp.StatusCode).To(Equal(http.StatusNotFound), "wrong status code, body:\n\n %s", body)
			Expect(body).To(ContainSubstring("Something went amiss"))
		})

		It("should not allow anonymous users to create accounts", func() {
			createAccountURL := authURL
			createAccountURL.Path = "/create_account.do"

			params.Set("email", email)
			params.Set("password", password)
			params.Set("password_confirmation", password)

			resp, err := httpClient.PostForm(createAccountURL.String(), params)
			Expect(err).NotTo(HaveOccurred())

			defer resp.Body.Close()
			body, err := ioutil.ReadAll(resp.Body)
			Expect(err).NotTo(HaveOccurred())
			Expect(resp.StatusCode).To(Equal(http.StatusNotFound), "wrong status code, body:\n\n %s", body)
			Expect(body).To(ContainSubstring("Something went amiss"))
		})
	})

	Describe("login server /forgot_password endpoint", func() {
		It("should not allow access to the forgot password page", func() {
			resetPasswordURL := authURL
			resetPasswordURL.Path = "/forgot_password"

			params.Set("username", email)

			resp, err := httpClient.Get(resetPasswordURL.String())
			Expect(err).NotTo(HaveOccurred())

			defer resp.Body.Close()
			body, err := ioutil.ReadAll(resp.Body)
			Expect(err).NotTo(HaveOccurred())
			Expect(resp.StatusCode).To(Equal(http.StatusNotFound), "wrong status code, body:\n\n %s", body)
			Expect(body).To(ContainSubstring("Something went amiss"))
		})

		It("should not allow users to reset forgotten passwords", func() {
			resetPasswordURL := authURL
			resetPasswordURL.Path = "/forgot_password.do"

			params.Set("username", email)

			resp, err := httpClient.PostForm(resetPasswordURL.String(), params)
			Expect(err).NotTo(HaveOccurred())

			defer resp.Body.Close()
			body, err := ioutil.ReadAll(resp.Body)
			Expect(err).NotTo(HaveOccurred())
{'fraction_non_alphanumeric': 0.15122759451724657, 'fraction_numerical': 0.0006025003765627354, 'mean_word_length': 4.768896611642051, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '6125732', 'n_tokens_mistral': 2419, 'n_tokens_neox': 2148, 'n_words': 399}