github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/uaa/uaa_suite_test.go (about)

     1  package uaa_test
     2  
     3  import (
     4  	"bytes"
     5  	"log"
     6  	"net/http"
     7  	"net/url"
     8  	"testing"
     9  
    10  	. "code.cloudfoundry.org/cli/api/uaa"
    11  	"code.cloudfoundry.org/cli/api/uaa/uaafakes"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  	. "github.com/onsi/gomega/ghttp"
    15  )
    16  
    17  func TestUaa(t *testing.T) {
    18  	RegisterFailHandler(Fail)
    19  	RunSpecs(t, "UAA Suite")
    20  }
    21  
    22  var (
    23  	// we create two servers in order to test that requests using different
    24  	// resources are going to the correct server
    25  	server    *Server
    26  	uaaServer *Server
    27  
    28  	TestAuthorizationResource string
    29  	TestUAAResource           string
    30  )
    31  
    32  var _ = SynchronizedBeforeSuite(func() []byte {
    33  	return []byte{}
    34  }, func(data []byte) {
    35  	server = NewTLSServer()
    36  	uaaServer = NewTLSServer()
    37  
    38  	testAuthURL, err := url.Parse(server.URL())
    39  	Expect(err).ToNot(HaveOccurred())
    40  	TestAuthorizationResource = testAuthURL.Host
    41  
    42  	testUAAURL, err := url.Parse(uaaServer.URL())
    43  	Expect(err).ToNot(HaveOccurred())
    44  	TestUAAResource = testUAAURL.Host
    45  
    46  	// Suppresses ginkgo server logs
    47  	server.HTTPTestServer.Config.ErrorLog = log.New(&bytes.Buffer{}, "", 0)
    48  })
    49  
    50  var _ = SynchronizedAfterSuite(func() {
    51  	server.Close()
    52  }, func() {})
    53  
    54  var _ = BeforeEach(func() {
    55  	server.Reset()
    56  })
    57  
    58  func NewTestConfig() *uaafakes.FakeConfig {
    59  	config := new(uaafakes.FakeConfig)
    60  	config.BinaryNameReturns("CF CLI UAA API Test")
    61  	config.BinaryVersionReturns("Unknown")
    62  	config.UAAOAuthClientReturns("client-id")
    63  	config.UAAOAuthClientSecretReturns("client-secret")
    64  	config.SkipSSLValidationReturns(true)
    65  	return config
    66  }
    67  
    68  func NewTestUAAClientAndStore(config Config) *Client {
    69  	client := NewClient(config)
    70  
    71  	// the 'uaaServer' is discovered via the bootstrapping when we hit the /login
    72  	// endpoint on 'server'
    73  	err := client.SetupResources(uaaServer.URL(), server.URL())
    74  	Expect(err).ToNot(HaveOccurred())
    75  
    76  	return client
    77  }
    78  
    79  func verifyRequestHost(host string) http.HandlerFunc {
    80  	return func(_ http.ResponseWriter, req *http.Request) {
    81  		Expect(req.Host).To(Equal(host))
    82  	}
    83  }