uc := UserCreator{
				In:      userInChan,
				Out:     userOutChan,
				OrgName: orgName,
			}
			go uc.Run()
		}

		for i := 0; i < userCount; i++ {
			var user User
			Eventually(userOutChan, 60*time.Second).Should(Receive(&user))

			users = append(users, user)
		}

		clientService := warrant.NewClientsService(warrant.Config{Host: context.UAADomain, SkipVerifySSL: true})
		var err error
		token, err = clientService.GetToken(context.TestClientSenderID, context.TestClientSenderSecret)
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		Run("cf", "target", "-o", context.NotificationsOrg, "-s", context.NotificationsSpace)

		if originalSMTP.Host != "" {
			Run("cf", "set-env", "notifications", "SMTP_HOST", originalSMTP.Host)
			Run("cf", "set-env", "notifications", "SMTP_PORT", originalSMTP.Port)
			Run("cf", "set-env", "notifications", "SMTP_TLS", originalSMTP.TLS)
			Run("cf", "restart", "notifications")
		}
	"github.com/cloudfoundry-incubator/notifications/acceptance/support"
	"github.com/pivotal-cf-experimental/warrant"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("SendEmailToSpace", func() {
	var clientToken string

	BeforeEach(func() {
		var err error

		config := warrant.Config{Host: context.UAADomain, SkipVerifySSL: true}
		clientService := warrant.NewClientsService(config)
		clientToken, err = clientService.GetToken(context.TestClientSenderID, context.TestClientSenderSecret)
		Expect(err).NotTo(HaveOccurred())
	})

	It("sends a notification a user within a particular space", func() {
		var (
			messageID           string
			notificationsClient *support.Client
		)

		By("sending the notification to the space", func() {
			// PUT A USER IN A SPACE
			Run("cf", "auth", context.CFAdminUsername, context.CFAdminPassword)
			Run("cf", "set-space-role", context.TestUserName, context.TestOrg, context.TestSpace, "SpaceDeveloper")
			Run("cf", "auth", context.TestUserName, context.TestUserPassword)
)

var _ = Describe("ClientsService", func() {
	var (
		service warrant.ClientsService
		token   string
		config  warrant.Config
	)

	BeforeEach(func() {
		config = warrant.Config{
			Host:          fakeUAA.URL(),
			SkipVerifySSL: true,
			TraceWriter:   TraceWriter,
		}
		service = warrant.NewClientsService(config)
		token = fakeUAA.ClientTokenFor("admin", []string{"clients.write", "clients.read"}, []string{"clients"})
	})

	Describe("Create/Get", func() {
		var client warrant.Client

		BeforeEach(func() {
			client = warrant.Client{
				ID:                   "client-id",
				Scope:                []string{"openid"},
				ResourceIDs:          []string{"none"},
				Authorities:          []string{"scim.read", "scim.write"},
				AuthorizedGrantTypes: []string{"client_credentials"},
				AccessTokenValidity:  5000 * time.Second,
			}
Beispiel #4
0
func NewRouter(mx muxer, config Config) http.Handler {
	requestCounter := middleware.NewRequestCounter(mx.GetRouter(), metrics.DefaultLogger)
	logging := middleware.NewRequestLogging(config.Logger)
	notificationsWriteAuthenticator := middleware.NewAuthenticator(config.UAAPublicKey, "notifications.write")
	databaseAllocator := middleware.NewDatabaseAllocator(config.SQLDB, config.DBLoggingEnabled)

	warrantConfig := warrant.Config{
		Host:          config.UAAHost,
		SkipVerifySSL: config.SkipVerifySSL,
	}
	warrantUsersService := warrant.NewUsersService(warrantConfig)
	warrantClientsService := warrant.NewClientsService(warrantConfig)

	rainmakerConfig := rainmaker.Config{
		Host:          config.CCHost,
		SkipVerifySSL: config.SkipVerifySSL,
	}
	rainmakerSpacesService := rainmaker.NewSpacesService(rainmakerConfig)
	rainmakerOrganizationsService := rainmaker.NewOrganizationsService(rainmakerConfig)

	userFinder := uaa.NewUserFinder(config.UAAClientID, config.UAAClientSecret, warrantUsersService, warrantClientsService)
	spaceFinder := cf.NewSpaceFinder(config.UAAClientID, config.UAAClientSecret, warrantClientsService, rainmakerSpacesService)
	orgFinder := cf.NewOrgFinder(config.UAAClientID, config.UAAClientSecret, warrantClientsService, rainmakerOrganizationsService)

	campaignEnqueuer := queue.NewCampaignEnqueuer(config.Queue)

	sendersRepository := models.NewSendersRepository(uuid.NewV4)
	campaignTypesRepository := models.NewCampaignTypesRepository(uuid.NewV4)
	templatesRepository := models.NewTemplatesRepository(uuid.NewV4)
	campaignsRepository := models.NewCampaignsRepository(uuid.NewV4)
	messagesRepository := models.NewMessagesRepository(util.NewClock())

	sendersCollection := collections.NewSendersCollection(sendersRepository, campaignTypesRepository)
	templatesCollection := collections.NewTemplatesCollection(templatesRepository)
	campaignTypesCollection := collections.NewCampaignTypesCollection(campaignTypesRepository, sendersRepository, templatesRepository)
	campaignsCollection := collections.NewCampaignsCollection(campaignEnqueuer, campaignsRepository, campaignTypesRepository, templatesRepository, sendersRepository, userFinder, spaceFinder, orgFinder)
	campaignStatusesCollection := collections.NewCampaignStatusesCollection(campaignsRepository, messagesRepository)

	info.Routes{
		RequestCounter: requestCounter,
		RequestLogging: logging,
	}.Register(mx)

	senders.Routes{
		RequestLogging:    logging,
		Authenticator:     notificationsWriteAuthenticator,
		DatabaseAllocator: databaseAllocator,
		SendersCollection: sendersCollection,
	}.Register(mx)

	campaigntypes.Routes{
		RequestLogging:          logging,
		Authenticator:           notificationsWriteAuthenticator,
		DatabaseAllocator:       databaseAllocator,
		CampaignTypesCollection: campaignTypesCollection,
	}.Register(mx)

	templates.Routes{
		RequestLogging:      logging,
		Authenticator:       notificationsWriteAuthenticator,
		DatabaseAllocator:   databaseAllocator,
		TemplatesCollection: templatesCollection,
	}.Register(mx)

	campaigns.Routes{
		Clock:                      util.NewClock(),
		RequestLogging:             logging,
		Authenticator:              notificationsWriteAuthenticator,
		DatabaseAllocator:          databaseAllocator,
		CampaignsCollection:        campaignsCollection,
		CampaignStatusesCollection: campaignStatusesCollection,
	}.Register(mx)

	return mx
}