예제 #1
0
	AfterEach(func() {
		testServer.Close()
	})

	It("logs in", func() {
		testServer, handler, config = setupAuthDependencies(successfulLoginRequest)

		auth := NewUAAAuthenticationRepository(gateway, config)
		apiErr := auth.Authenticate(map[string]string{
			"username": "******",
			"password": "******",
		})

		Expect(handler).To(testnet.HaveAllRequestsCalled())
		Expect(apiErr).NotTo(HaveOccurred())
		Expect(config.AuthenticationEndpoint()).To(Equal(testServer.URL))
		Expect(config.AccessToken()).To(Equal("BEARER my_access_token"))
		Expect(config.RefreshToken()).To(Equal("my_refresh_token"))
	})

	It("returns a failure response when login fails", func() {
		testServer, handler, config = setupAuthDependencies(unsuccessfulLoginRequest)

		auth := NewUAAAuthenticationRepository(gateway, config)
		apiErr := auth.Authenticate(map[string]string{
			"username": "******",
			"password": "******",
		})

		Expect(handler).To(testnet.HaveAllRequestsCalled())
		Expect(apiErr).NotTo(BeNil())
예제 #2
0
				org := models.OrganizationFields{}
				org.Name = "my-org"
				org.Guid = "my-org-guid"

				space := models.SpaceFields{}
				space.Name = "my-space"
				space.Guid = "my-space-guid"

				config.SetOrganizationFields(org)
				config.SetSpaceFields(space)

				repo.UpdateEndpoint(testServer.URL)

				Expect(config.AccessToken()).To(Equal(""))
				Expect(config.AuthenticationEndpoint()).To(Equal("https://login.example.com"))
				Expect(config.LoggregatorEndpoint()).To(Equal("wss://loggregator.foo.example.org:4443"))
				Expect(config.ApiEndpoint()).To(Equal(testServer.URL))
				Expect(config.ApiVersion()).To(Equal("42.0.0"))
				Expect(config.HasOrganization()).To(BeFalse())
				Expect(config.HasSpace()).To(BeFalse())
			})

			It("does not clear the session if the api endpoint does not change", func() {
				testServerFn = validApiInfoEndpoint

				org := models.OrganizationFields{}
				org.Name = "my-org"
				org.Guid = "my-org-guid"

				space := models.SpaceFields{}