示例#1
0
			setupCCServer(ccReqs...)

			_, apiErr := repo.ListUsersInOrgForRole("my-org-guid", models.ORG_MANAGER)

			Expect(ccHandler).To(testnet.HaveAllRequestsCalled())
			httpErr, ok := apiErr.(errors.HttpError)
			Expect(ok).To(BeTrue())
			Expect(httpErr.StatusCode()).To(Equal(http.StatusGatewayTimeout))
		})

		It("returns an error when the UAA endpoint cannot be determined", func() {
			ccReqs, _ := createUsersByRoleEndpoints("/v2/organizations/my-org-guid/managers")

			setupCCServer(ccReqs...)

			config.SetAuthenticationEndpoint("")

			_, apiErr := repo.ListUsersInOrgForRole("my-org-guid", models.ORG_MANAGER)
			Expect(apiErr).To(HaveOccurred())
		})
	})

	Describe("FindByUsername", func() {
		Context("when the user exists", func() {
			It("finds the user", func() {
				setupUAAServer(
					testapi.NewCloudControllerTestRequest(testnet.TestRequest{
						Method: "GET",
						Path:   "/Users?attributes=id,userName&filter=userName+Eq+%22damien%2Buser1%40pivotallabs.com%22",
						Response: testnet.TestResponse{
							Status: http.StatusOK,
示例#2
0
		auth       AuthenticationRepository
	)

	BeforeEach(func() {
		config = testconfig.NewRepository()
		gateway = net.NewUAAGateway(config)
		auth = NewUAAAuthenticationRepository(gateway, config)
	})

	AfterEach(func() {
		testServer.Close()
	})

	var setupTestServer = func(request testnet.TestRequest) {
		testServer, handler = testnet.NewServer([]testnet.TestRequest{request})
		config.SetAuthenticationEndpoint(testServer.URL)
	}

	Describe("authenticating", func() {
		var err error

		JustBeforeEach(func() {
			err = auth.Authenticate(map[string]string{
				"username": "******",
				"password": "******",
			})
		})

		Describe("when login succeeds", func() {
			BeforeEach(func() {
				setupTestServer(successfulLoginRequest)