예제 #1
0
func TestUnsuccessfullyLoggingIn(t *testing.T) {
	ts := httptest.NewTLSServer(http.HandlerFunc(unsuccessfulLoginEndpoint))
	defer ts.Close()

	configRepo := testhelpers.FakeConfigRepository{}
	configRepo.Delete()
	config, err := configRepo.Get()
	assert.NoError(t, err)
	config.AuthorizationEndpoint = ts.URL
	config.AccessToken = ""
	gateway := net.NewUAAAuthGateway()

	auth := NewUAAAuthenticator(gateway, configRepo)
	err = auth.Authenticate("*****@*****.**", "oops wrong pass")
	assert.Error(t, err)
	assert.Equal(t, err.Error(), "Password is incorrect, please try again.")
	savedConfig := testhelpers.SavedConfiguration
	assert.Empty(t, savedConfig.AccessToken)
}
예제 #2
0
func TestServerErrorLoggingIn(t *testing.T) {
	ts := httptest.NewTLSServer(http.HandlerFunc(errorLoginEndpoint))
	defer ts.Close()

	configRepo := testhelpers.FakeConfigRepository{}
	configRepo.Delete()
	config, err := configRepo.Get()
	assert.NoError(t, err)
	config.AuthorizationEndpoint = ts.URL
	config.AccessToken = ""
	gateway := net.NewUAAAuthGateway()

	auth := NewUAAAuthenticator(gateway, configRepo)
	err = auth.Authenticate("*****@*****.**", "bar")
	assert.Error(t, err)
	assert.Equal(t, err.Error(), "Server error, status code: 500, error code: , message: ")
	savedConfig := testhelpers.SavedConfiguration
	assert.Empty(t, savedConfig.AccessToken)
}
예제 #3
0
func TestSuccessfullyLoggingIn(t *testing.T) {
	ts := httptest.NewTLSServer(http.HandlerFunc(successfulLoginEndpoint))
	defer ts.Close()

	configRepo := testhelpers.FakeConfigRepository{}
	configRepo.Delete()
	config, err := configRepo.Get()
	assert.NoError(t, err)
	config.AuthorizationEndpoint = ts.URL
	config.AccessToken = ""
	gateway := net.NewUAAAuthGateway()

	auth := NewUAAAuthenticator(gateway, configRepo)
	err = auth.Authenticate("*****@*****.**", "bar")

	savedConfig := testhelpers.SavedConfiguration
	assert.Equal(t, savedConfig.AccessToken, "BEARER my_access_token")
	assert.Equal(t, savedConfig.RefreshToken, "my_refresh_token")
}
예제 #4
0
func NewRepositoryLocator(config *configuration.Configuration) (loc RepositoryLocator) {
	loc.config = config
	loc.configurationRepo = configuration.NewConfigurationDiskRepository()

	authGateway := net.NewUAAAuthGateway()
	loc.authenticator = NewUAAAuthenticator(authGateway, loc.configurationRepo)

	loc.cloudControllerGateway = net.NewCloudControllerGateway(loc.authenticator)
	loc.uaaGateway = net.NewUAAGateway(loc.authenticator)

	loc.organizationRepo = NewCloudControllerOrganizationRepository(config, loc.cloudControllerGateway)
	loc.spaceRepo = NewCloudControllerSpaceRepository(config, loc.cloudControllerGateway)
	loc.appRepo = NewCloudControllerApplicationRepository(config, loc.cloudControllerGateway)
	loc.appSummaryRepo = NewCloudControllerAppSummaryRepository(config, loc.cloudControllerGateway, loc.appRepo)
	loc.appFilesRepo = NewCloudControllerAppFilesRepository(config, loc.cloudControllerGateway)
	loc.domainRepo = NewCloudControllerDomainRepository(config, loc.cloudControllerGateway)
	loc.routeRepo = NewCloudControllerRouteRepository(config, loc.cloudControllerGateway)
	loc.stackRepo = NewCloudControllerStackRepository(config, loc.cloudControllerGateway)
	loc.serviceRepo = NewCloudControllerServiceRepository(config, loc.cloudControllerGateway)
	loc.passwordRepo = NewCloudControllerPasswordRepository(config, loc.uaaGateway)
	loc.logsRepo = NewLoggregatorLogsRepository(config, loc.cloudControllerGateway, LoggregatorHost)

	return
}