Commit Graph

552 Commits

Author SHA1 Message Date
Miroslav Bajtoš 1575becb92 Babelify juggler for Karma tests
Fix configuration of Karma:

 - Disable ES6 modules. The ES6 module transpiler is adding
  "use strict" to all source files, this breaks e.g. chai or juggler
 - Relax "ignore" setting to exclude only strong-task-emitter,
   thus bring back Babel transpilation for chai and juggler.
2018-02-09 10:38:22 -05:00
Miroslav Bajtoš b2cf877d14 Fix Karma config to babelify node_modules too
Before this change, dependencies in node_modules (e.g. strong-remoting)
were not transformed to ES5 and thus crashed the tests in PhantomJS.

Note that loopback-datasource-juggler cannot be babelified to ES5
because it does not correctly support strict mode yet.
2018-02-08 16:58:12 -05:00
Samuel Reed 787f393c7c
fix(AccessContext): Tighten userid/appid checks
An application may have a use for a falsy ID.
2017-12-05 08:51:21 -06:00
Miroslav Bajtoš 4f928bf965
test: fix too strict test assertion
Rework the test verifying properties of `loopback` to ignore
new express properties added after the test was written.

Ignore "json" and "urlencoded" middleware that was added back
to Express, keep using our wrappers printing a deprecation message.
2017-10-17 14:16:20 +02:00
loay 22bd0fc81f Add unit test for empty password 2017-07-21 15:46:21 -04:00
Aaron Buchanan 50e0e4808a
Fix user-literal rewrite for anonymous requests
Currently any `currentUserLiteral` routes when accessed with a bad
token throw a 500 due to a SQL error that is raised because
`Model.findById` is invoked with `id={currentUserLiteral}`
(`id=me` in our case) when the url rewrite fails.

This commit changes the token middleware to return 401 Not Authorized
when the client is requesting a currentUserLiteral route without
a valid access token.
2017-04-04 18:55:34 +02:00
Miroslav Bajtoš a5ac1506e6
Forward options in prepareForTokenInvalidation 2017-03-24 15:01:05 +01:00
phairow 91502db9f1
Fix User.verify to convert uid to string
Applications using MongoDB connectors typically have `user.id`
property of type ObjectID.

This commit fixes the code building the verification URL to
correctly convert the user id value into string.
2017-03-08 16:30:01 +01:00
Miroslav Bajtoš 09b1fce34b Fix creation of verification links
Fix User.prototype.verify to call `querystring.stringify` instead
of concatenating query-string components directly.

In particular, this fixes the bug where `options.redirect` containing
a hash fragment like `#/home?arg1=value1&arg2=value2` produced incorrect
URL, because the `redirect` value was not correctly encoded.
2017-02-09 13:33:57 +01:00
Miroslav Bajtoš 05db4337cf Preserve sessions on User.save() making no changes 2017-01-31 14:43:24 +01:00
Ritchie Martori 1dac9ada0b Fix logout to handle no or missing accessToken
Return 401 when the request does not provide any accessToken argument
or the token was not found.

Also simplify the implementation of the `logout` method to make only
a single database call (`deleteById`) instead of `findById` + `delete`.
2017-01-30 10:39:40 +01:00
Miroslav Bajtoš 98110f1b84 Use English when running Mocha tests 2017-01-27 11:26:24 +01:00
Benjamin Kroeger 56ad85ae2a Role model: resolves related models by name
Resolve models related to the `Role` model by name instead of class.
2017-01-25 11:02:55 +01:00
Aris Kemper 5e7e7ca7e9 Fix User methods to use correct Primary Key
Do not use hard-coded "id" property name, call `idName()` to get the
name of the PK property.
2017-01-23 09:51:41 +01:00
Miroslav Bajtoš f1e31ca50c Add app setting logoutSessionsOnSensitiveChanges
Disable invalidation of access tokens by default to restore backwards
compatibility with older 2.x versions.

Add a new application-wide flag logoutSessionsOnSensitiveChanges
that can be used to explicitly turn on/off the token invalidation.

When the flag is not set, a verbose warning is printed to nudge the user
to make a decision how they want to handle token invalidation.
2017-01-20 12:57:23 +01:00
João Ribeiro b8f9b85609 Fix User.resetPassword to call createAccessToken()
This allows User subclasses to override the algorithm used for building
one-time access tokens for password recovery.
2017-01-20 10:59:46 +01:00
Miroslav Bajtoš afd6dd7073 Preserve current session when invalidating tokens
Fix User model to preserve the current session (provided via
"options.accessToken") when invalidating access tokens after a change
of email or password property.
2017-01-16 11:02:29 +01:00
Miroslav Bajtoš f8b013dab8 Clean up access-token-invalidation tests 2017-01-16 10:39:49 +01:00
Sergey Reus 5233dcb557 Emit resetPasswordRequest event with options 2017-01-05 15:36:01 +01:00
박대선 659e9ce09b Fix false emailVerified on user model update
We noticed that every time the user model updates, the emailVerified
column would change to false, even though the email was not changed
at all.

I took a look and realized there might be an error in
https://github.com/strongloop/loopback/commit/eb640d8

The intent of the commit just mention is to make emailVerified false
when the email gets changed, but notice that ctx.data.email is null
on updates, so the condition is always met and emailVerified always
becomes false.

This commit fixes the issue just mentioned.
2017-01-05 11:08:35 +01:00
Miroslav Bajtoš 74bb1daf8a Add new flag injectOptionsFromRemoteContext
Hide the new "options" arguments behind a feature flag
injectOptionsFromRemoteContext that is disabled by default for backwards
compatibility.

Fix construction of sharedCtor remoting metadata to prevent the
situation when we are configuring remoting metadata after
strong-remoting has already picked up data from our parent (base) model.
2017-01-05 10:18:56 +01:00
Miroslav Bajtoš 693d52fc59 Contextify DAO and relation methods
Modify remoting metadata of data-access methods in PersistedModel
and relation method in Model and add an "options" argument to "accepts"
list.
2017-01-05 10:18:56 +01:00
Miroslav Bajtoš ee106e4e15 Implement new http arg mapping optionsFromRequest
Define a new Model method "createOptionsFromRemotingContext" that allows
models to define what "options" should be passed to methods invoked
via strong-remoting (e.g. REST).

Define a new http mapping `http: 'optionsFromRequest'` that invokes
`Model.createOptionsFromRemotingContext` to build the value from
remoting context.

This should provide enough infrastructure for components and
applications to implement their own ways of building the "options"
object.
2017-01-05 10:18:56 +01:00
kobaska b3a5bc739b Add option disabling periodic change rectification
When `Model.settings.changeCleanupInterval` is set to a negative value,
no periodic cleanup is performed at all.
2016-12-21 15:39:08 +01:00
Miroslav Bajtoš 4ee086dcd0 Invalidate AccessTokens on password change
Invalidate all existing sessions (delete all access tokens)
after user's password was changed.
2016-12-12 13:58:20 +01:00
Miroslav Bajtoš 4d41c67c54 Remove "options.template" from Email payload
Fix User.confirm to exclude "options.template" when sending the
confirmation email. Certain nodemailer transport plugins are rejecting
such requests.
2016-12-07 10:54:17 +01:00
Bram Borggreve e7831f6c4d
Allow password reset request for users in realms 2016-11-30 16:57:59 -05:00
Eric a4a96eb39f Add "returnOnlyRoleNames" option to Role.getRoles
Currently the return type of Role.getRoles() method is inconsistent:
role names are returned for smart roles and role ids are returned for
static roles (configured through user-role mapping).

This commit adds a new option to Role.getRoles() allowing the caller
to request role names to be returned for all types of roles.
2016-11-30 17:10:41 +01:00
Miroslav Bajtoš c0e96ffa12 Merge pull request #2940 from kobaska/add-optional-options-to-bulkupdate
Add options to bulkUpdate
2016-11-15 17:34:06 +01:00
codyolsen d99d608876 Fix context within listByPrincipalType role method
- Fix for current implimentation that returned all models that had any
  assigned roles. Context was not carried into listByPrincipalType,
  setting roleId as null.
2016-11-15 16:27:56 +01:00
Adrien Kiren 5c1558f969 Add templateFn option to User#verify() 2016-11-15 13:46:35 +01:00
Kogulan Baskaran bc923bd781 Add options to bulkUpdate 2016-11-15 13:02:23 +11:00
Loay 67e5c6ec1e Require verification after email change
When the User model is configured to require email verification,
then any change of the email address should trigger re-verification.
2016-11-09 11:51:37 -05:00
Dhaval Trivedi 6e880137e4 adding check of string for case insensitive emails 2016-11-04 10:35:08 -04:00
Miroslav Bajtoš bf5c206bd6 Fix description of updateAll response
Correctly describe the first non-error callback arg as an `info` object
containing a `count` property.
2016-10-12 13:04:35 +02:00
Miroslav Bajtoš b3497c6778 Allow tokens with eternal TTL (value -1)
- Add a new User setting 'allowEternalTokens'
 - Enhance 'AccessToken.validate' to support eternal tokens with ttl
   value -1 when the user model allows it.
2016-10-12 12:30:33 +02:00
Tim van der Staaij b8b92fbeda Fix support for remote hooks returning a Promise
Fix beforeRemote/afterRemote to correctly return promises returned
by the user-provided hook callback.
2016-10-05 11:02:36 +02:00
Loay bdeaf654fa Validate non-email property partial update 2016-10-03 16:53:36 -04:00
gunjpan e244153eb7 Update tests to use registry for model creation
Current implementation of `app.model(modelName, settings)`
works as a sugar for model creation. In LB 3.0, this is
not supported anymore. This backporting:
- keeps the sugar method for model creation  for backward
compatibility
- updates test cases to use `app.registry.createModel()`
for model creation

Backport of #2401
2016-09-27 16:44:01 -04:00
Richard Pringle f7dbc97763 Call new disable remote method from model class. 2016-09-23 11:14:51 -04:00
Loay 59eeb99803 Allow resetPassword if email is verified 2016-09-20 11:29:56 -04:00
Loay fa310d5882 Invalidate sessions after email change 2016-09-19 14:55:23 -04:00
Miroslav Bajtoš 14b8426687 Merge pull request #2736 from strongloop/update/loopback-testing-in-2x
Upgrade loopback-testing to the latest ^1.4 [2.x-only]
2016-09-13 09:13:57 +02:00
Miroslav Bajtoš 3df5b2814c Fix double-slash in confirmation URL
Fix the code building the URL used in the email-verification email
to prevent double-slash in the URL when e.g. restApiRoot is '/'.

Before:

  http://example.com//users/confirm?...

Now:

  http://example.com/users/confirm?...
2016-09-12 17:12:24 +02:00
Miroslav Bajtoš c4214024be Upgrade loopback-testing to the latest ^1.4 2016-09-12 13:21:07 +02:00
Amir Jafarian 4d6f2da578 Fix data argument for upsertWithWhere
* Related PR: #2727
2016-09-07 13:52:35 -04:00
Sonali Samantaray 4c013deaae Expose upsertWithWhere
Backport of #2539
2016-09-07 12:41:56 -04:00
Miroslav Bajtoš fcfdb73bdb Fix remoting metadata for "data" arguments
Fix the definition of "data" argument to

    { type: 'object', model: modelName, ... }

That way strong-remoting passed the request body directly to the model
method (does not create a new model instance), but the swagger will
still provide correct schema for these arguments.

This fixes a bug where upsert in relation methods was adding default
property values to request payload.
2016-09-07 12:59:01 +02:00
Miroslav Bajtoš 381222bf7a Rework email validation to use isemail
Drop hand-crafted RegExp in favour of a 3rd-party module that supports
RFC5321, RFC5322 and other relevant standards.
2016-09-06 13:00:27 +02:00
Miroslav Bajtoš f362084770 Merge pull request #2697 from strongloop/fix/various
Fix app.enableAuth and test/user
2016-09-01 16:49:36 +02:00