Exemplo n.º 1
0
func validateOperation(req *models.Ping, context *apimodels.Context) error {
	// realtime doc id
	if req.FileId == "" {
		return errors.New("fileId not set")
	}

	// only logged in users can send a ping
	if !context.IsLoggedIn() {
		return errors.New("not logged in")
	}

	// override the account id and set created at
	req.AccountId = context.Client.Account.Id // if client is logged in, those values are all set
	req.CreatedAt = time.Now().UTC()

	return collaboration.CanOpen(req)
}
Exemplo n.º 2
0
func testPingTimes(
	req *models.Ping,
	pingCount int,
	mongoCache *cache.MongoCache,
	handler *Controller,
	expectedErr error,
) {
	req.FileId = req.FileId + strconv.Itoa(pingCount)
	req.CreatedAt = time.
		Now().
		UTC().
		Add(-pingDuration * time.Duration(pingCount))

	err := mongoCache.SetEx(
		PrepareFileKey(req.FileId),
		ExpireSessionKeyDuration, // expire the key after this period
		req.CreatedAt.Unix(),
	)

	err = handler.checkIfKeyIsValid(req)
	So(err, ShouldEqual, expectedErr)
}