func (suite *AccountsTestSuite) TestConfirmInvitationReferenceNotFound() {
	// Prepare a request
	bogusUUID := uuid.New()
	payload, err := json.Marshal(&accounts.ConfirmInvitationRequest{
		PasswordRequest: accounts.PasswordRequest{Password: "******"},
	})
	r, err := http.NewRequest(
		"POST",
		fmt.Sprintf("http://1.2.3.4/v1/invitations/%s", bogusUUID),
		bytes.NewBuffer(payload),
	)
	assert.NoError(suite.T(), err, "Request setup should not get an error")
	r.Header.Set(
		"Authorization",
		fmt.Sprintf(
			"Basic %s",
			b64.StdEncoding.EncodeToString([]byte("test_client_1:test_secret")),
		),
	)

	// And serve the request
	w := httptest.NewRecorder()
	suite.router.ServeHTTP(w, r)

	// Check the response
	testutil.TestResponseForError(suite.T(), w, accounts.ErrInvitationNotFound.Error(), 404)
}
Beispiel #2
0
// NewGroup creates Group instance
func NewGroup(tasks ...*signatures.TaskSignature) *Group {
	// Generate a group UUID
	groupUUID := fmt.Sprintf("group_%v", uuid.New())

	// Auto generate task UUIDs
	// Group tasks by common UUID
	for _, task := range tasks {
		if task.UUID == "" {
			task.UUID = fmt.Sprintf("task_%v", uuid.New())
		}
		task.GroupUUID = groupUUID
		task.GroupTaskCount = len(tasks)
	}

	return &Group{
		GroupUUID: groupUUID,
		Tasks:     tasks,
	}
}
Beispiel #3
0
// NewAuthorizationCode creates new AuthorizationCode instance
func NewAuthorizationCode(client *Client, user *User, expiresIn int, redirectURI, scope string) *AuthorizationCode {
	return &AuthorizationCode{
		ClientID:    util.PositiveIntOrNull(int64(client.ID)),
		UserID:      util.PositiveIntOrNull(int64(user.ID)),
		Code:        uuid.New(),
		ExpiresAt:   time.Now().UTC().Add(time.Duration(expiresIn) * time.Second),
		RedirectURI: util.StringOrNull(redirectURI),
		Scope:       scope,
	}
}
Beispiel #4
0
// NewChord creates Chord instance
func NewChord(group *Group, callback *signatures.TaskSignature) *Chord {
	// Generate a UUID for the chord callback
	callback.UUID = fmt.Sprintf("chord_%v", uuid.New())

	// Add a chord callback to all tasks
	for _, task := range group.Tasks {
		task.ChordCallback = callback
	}

	return &Chord{Group: group, Callback: callback}
}
Beispiel #5
0
// NewAccessToken creates new AccessToken instance
func NewAccessToken(client *Client, user *User, expiresIn int, scope string) *AccessToken {
	accessToken := &AccessToken{
		ClientID:  util.PositiveIntOrNull(int64(client.ID)),
		Token:     uuid.New(),
		ExpiresAt: time.Now().UTC().Add(time.Duration(expiresIn) * time.Second),
		Scope:     scope,
	}
	if user != nil {
		accessToken.UserID = util.PositiveIntOrNull(int64(user.ID))
	}
	return accessToken
}
Beispiel #6
0
// NewPasswordReset creates new PasswordReset instance
func NewPasswordReset(user *User, expiresIn int) (*PasswordReset, error) {
	userID := util.PositiveIntOrNull(int64(user.ID))
	passwordReset := &PasswordReset{
		EmailTokenModel: EmailTokenModel{
			Reference:   uuid.New(),
			EmailSentAt: nil,
			ExpiresAt:   time.Now().UTC().Add(time.Duration(expiresIn) * time.Second),
		},
		UserID: userID,
	}
	return passwordReset, nil
}
Beispiel #7
0
// NewConfirmation creates new Confirmation instance
func NewConfirmation(user *User, expiresIn int) (*Confirmation, error) {
	userID := util.PositiveIntOrNull(int64(user.ID))
	confirmation := &Confirmation{
		EmailTokenModel: EmailTokenModel{
			Reference:   uuid.New(),
			EmailSentAt: nil,
			ExpiresAt:   time.Now().UTC().Add(time.Duration(expiresIn) * time.Second),
		},
		UserID: userID,
	}
	return confirmation, nil
}
func (suite *AccountsTestSuite) TestConfirmEmailNotFound() {
	bogusUUID := uuid.New()
	testutil.TestGetErrorExpectedResponse(
		suite.T(),
		suite.router,
		fmt.Sprintf("http://1.2.3.4/v1/confirmations/%s", bogusUUID),
		"confirm_email",
		"test_client_token",
		accounts.ErrConfirmationNotFound.Error(),
		http.StatusNotFound,
		suite.assertMockExpectations,
	)
}
func (suite *AccountsTestSuite) TestConfirmEmailRequiresAccountAuthentication() {
	bogusUUID := uuid.New()
	testutil.TestGetErrorExpectedResponse(
		suite.T(),
		suite.router,
		fmt.Sprintf("http://1.2.3.4/v1/confirmations/%s", bogusUUID),
		"confirm_email",
		"", // no access token
		accounts.ErrAccountAuthenticationRequired.Error(),
		http.StatusUnauthorized,
		suite.assertMockExpectations,
	)
}
func (suite *AccountsTestSuite) TestConfirmPasswordResetNotFound() {
	bogusUUID := uuid.New()
	testutil.TestPostErrorExpectedResponse(
		suite.T(),
		suite.router,
		fmt.Sprintf("http://1.2.3.4/v1/password-resets/%s", bogusUUID),
		"confirm_password_reset",
		strings.NewReader("{}"), //data
		"test_client_token",
		accounts.ErrPasswordResetNotFound.Error(),
		http.StatusNotFound,
		suite.assertMockExpectations,
	)
}
Beispiel #11
0
// NewInvitation creates new Invitation instance
func NewInvitation(invitedUser, invitedByUser *User, expiresIn int) (*Invitation, error) {
	invitedUserID := util.PositiveIntOrNull(int64(invitedUser.ID))
	invitedByUserID := util.PositiveIntOrNull(int64(invitedByUser.ID))
	invitation := &Invitation{
		EmailTokenModel: EmailTokenModel{
			Reference:   uuid.New(),
			EmailSentAt: nil,
			ExpiresAt:   time.Now().UTC().Add(time.Duration(expiresIn) * time.Second),
		},
		InvitedUserID:   invitedUserID,
		InvitedByUserID: invitedByUserID,
	}
	return invitation, nil
}
Beispiel #12
0
// NewChain creates Chain instance
func NewChain(tasks ...*signatures.TaskSignature) *Chain {
	for i := len(tasks) - 1; i > 0; i-- {
		if i > 0 {
			tasks[i-1].OnSuccess = []*signatures.TaskSignature{tasks[i]}
		}
	}

	chain := &Chain{Tasks: tasks}

	// Auto generate task UUIDs
	for _, task := range chain.Tasks {
		task.UUID = fmt.Sprintf("task_%v", uuid.New())
	}

	return chain
}
func (suite *AccountsTestSuite) TestConfirmInvitationFailsWithoutAccountAuthentication() {
	// Prepare a request
	bogusUUID := uuid.New()
	r, err := http.NewRequest(
		"POST",
		fmt.Sprintf("http://1.2.3.4/v1/invitations/%s", bogusUUID),
		nil,
	)
	assert.NoError(suite.T(), err, "Request setup should not get an error")

	// And serve the request
	w := httptest.NewRecorder()
	suite.router.ServeHTTP(w, r)

	assert.Equal(suite.T(), http.StatusUnauthorized, w.Code, "This requires an authenticated account")
}
Beispiel #14
0
// SendTask publishes a task to the default queue
func (server *Server) SendTask(signature *signatures.TaskSignature) (*backends.AsyncResult, error) {
	// Make sure result backend is defined
	if server.backend == nil {
		return nil, errors.New("Result backend required")
	}

	// Auto generate a UUID if not set already
	if signature.UUID == "" {
		signature.UUID = fmt.Sprintf("task_%v", uuid.New())
	}

	// Set initial task state to PENDING
	if err := server.backend.SetStatePending(signature); err != nil {
		return nil, fmt.Errorf("Set State Pending: %v", err)
	}

	if err := server.broker.Publish(signature); err != nil {
		return nil, fmt.Errorf("Publish Message: %v", err)
	}

	return backends.NewAsyncResult(signature, server.backend), nil
}