<commit_before>package isolated

import (
	"io/ioutil"
	"os"
	"path/filepath"
	"regexp"

	"code.cloudfoundry.org/cli/integration/helpers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/gbytes"
	. "github.com/onsi/gomega/gexec"
)

func fileAsString(path string) string {
	configBytes, err := ioutil.ReadFile(path)
	Expect(err).ToNot(HaveOccurred())

	return string(configBytes)
}

func replaceConfig(path string, old string, new string) {
	r := regexp.MustCompile(old)
	newConfig := r.ReplaceAllString(fileAsString(path), new)
	err := ioutil.WriteFile(path, []byte(newConfig), 0600)
	Expect(err).ToNot(HaveOccurred())
}

var _ = Describe("custom oauth client id", func() {
	var configPath string

	BeforeEach(func() {
		helpers.SkipIfClientCredentialsTestMode()
		configPath = filepath.Join(homeDir, ".cf", "config.json")
	})

	When("the config file exists", func() {
		BeforeEach(func() {
			helpers.LoginCF()
			helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace)
		})

		When("the client id and secret keys are set in the config", func() {
			BeforeEach(func() {
				replaceConfig(
					configPath, `"UAAOAuthClient": ".*"`, `"UAAOAuthClient": "cf2"`)
				replaceConfig(
					configPath, `"UAAOAuthClientSecret": ".*"`, `"UAAOAuthClientSecret": "secret2"`)
			})

			Context("oauth-token", func() {
				It("uses the custom client id and secret", func() {<commit_msg>Force UAA call in oauth client test<commit_after>package isolated

import (
	"io/ioutil"
	"os"
	"path/filepath"
	"regexp"

	"code.cloudfoundry.org/cli/integration/helpers"
	"code.cloudfoundry.org/cli/util/configv3"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/gbytes"
	. "github.com/onsi/gomega/gexec"
)

func fileAsString(path string) string {
	configBytes, err := ioutil.ReadFile(path)
	Expect(err).ToNot(HaveOccurred())

	return string(configBytes)
}

func replaceConfig(path string, old string, new string) {
	r := regexp.MustCompile(old)
	newConfig := r.ReplaceAllString(fileAsString(path), new)
	err := ioutil.WriteFile(path, []byte(newConfig), 0600)
	Expect(err).ToNot(HaveOccurred())
}

var _ = Describe("custom oauth client id", func() {
	var configPath string

	BeforeEach(func() {
		helpers.SkipIfClientCredentialsTestMode()
		configPath = filepath.Join(homeDir, ".cf", "config.json")
	})

	When("the config file exists", func() {
		BeforeEach(func() {
			helpers.LoginCF()
			helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace)
		})

		When("the client id and secret keys are set in the config", func() {
			BeforeEach(func() {
				replaceConfig(
					configPath, `"UAAOAuthClient": ".*"`, `"UAAOAuthClient": "cf2"`)
				replaceConfig(
					configPath, `"UAAOAuthClientSecret": ".*"`, `"UAAOAuthClientSecret": "secret2"`)
			})

			Context("oauth-token", func() {
				BeforeEach(func() {
					helpers.SetConfig(func(conf *configv3.Config) {
						conf.ConfigFile.AccessToken = "invalid-access-token"
					})
				})

				It("uses the custom client id and secret", func() {
{'fraction_non_alphanumeric': 0.15549686365137008, 'fraction_numerical': 0.00462198745460548, 'mean_word_length': 4.62152133580705, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '4222496', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1089, 'n_words': 204}