Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Invalid User Tests #944

Closed
6 tasks done
greaterweb opened this issue Dec 22, 2014 · 6 comments
Closed
6 tasks done

FIX: Invalid User Tests #944

greaterweb opened this issue Dec 22, 2014 · 6 comments
Assignees

Comments

@greaterweb
Copy link
Contributor

There appear to be a number of issues present with the User model tests.

  • invalidCredentials are actually valid (see validCredentialsEmailVerified)
  • test using invalidCredentials should actually fail but it doesn't (broader problem, see below)
  • use off .expect needs to be paired with logic in the .end callback (eg. if (err) return done(err);) when testing REST calls, this is not applied to all instances. to confirm these are failing, change one of the .expect values and note the test still passes
  • could also extend to create API test where there are only REST tests, for example there is only a REST test for invalidCredentials and nothing specific for API call

Regarding the point of .expect usage, it's probably worth looking into any other REST unit tests to make sure they are correct in implementation.

A question in general. There is both vanilla assert statements and chai expect statements, which is the preferred approach for testing?

Additional tests to add

  • check reset password fails without email address (API and REST)
  • reset password over REST
@greaterweb
Copy link
Contributor Author

@raymondfeng I need some help deciphering this test below, it looks like you were originally responsible for authoring it.

The wrong Content-Type test fails when updated as suggested in the original ticket.

    it('Login a user over REST with the wrong Content-Type', function(done) {
      request(app)
        .post('/users/login')
        .set('Content-Type', null)
        .expect('Content-Type', /json/)
        .expect(400)
        .send(validCredentials)
        .end(function(err, res) {
          if (err) {
            return done(err);
          }
          done();
        });
    });
  1) User User.login Login a user over REST with the wrong Content-Type:
     Error: expected 400 "Bad Request", got 200 "OK"

What is the desired behavior if Content-Type is set to null with the request? In doing some basic debugging, I'm getting a 200 with a valid accessToken as the res value.

@greaterweb
Copy link
Contributor Author

Some troubleshooting information related to the wrong Content-Type test.

The combination of .set('Content-Type', null) and .send(validCredentials) produce request headers of:

{ 
  host: '127.0.0.1:57654',
  'accept-encoding': 'gzip, deflate',
  cookie: '',
  'user-agent': 'node-superagent/0.18.0',
  'content-type': 'application/json'',
  'content-length': 40 
}

Updating the send body to .send(JSON.stringify(validCredentials)) will set Content-Type to application/x-www-form-urlencoded and produce a 400 with message "username or email is required", this is likely closer to the intention of mismatching Content-Type value to request body.

Not sure if this is the actual 400 message that is desired but a 400 none the less. Is the intention that we get a generic 400 bad request or will this 400 be sufficient?

greaterweb added a commit to greaterweb/loopback that referenced this issue Dec 22, 2014
greaterweb added a commit to greaterweb/loopback that referenced this issue Dec 22, 2014
greaterweb added a commit to greaterweb/loopback that referenced this issue Dec 22, 2014
greaterweb added a commit to greaterweb/loopback that referenced this issue Dec 22, 2014
greaterweb added a commit to greaterweb/loopback that referenced this issue Dec 22, 2014
greaterweb added a commit to greaterweb/loopback that referenced this issue Dec 22, 2014
@greaterweb
Copy link
Contributor Author

I've made some fixes to the issues noted and had a review of other tests making REST calls. All seems to be in good shape. Once I can get some confirmation on the test above I'll be sure to submit a pull request.

greaterweb added a commit to greaterweb/loopback that referenced this issue Dec 23, 2014
@greaterweb greaterweb changed the title BUG: Invalid User Tests FIX: Invalid User Tests Dec 23, 2014
@raymondfeng
Copy link
Member

@greaterweb Thank you for making efforts to improve the tests. Sorry for the delay as some of us were on holidays.

A few comments:

  • Good catch to the invalidCredential
  • Good catch to the end(), which will receive an error if the expected status code doesn't match
  • For the content type test, we should set it to something like text/html

Can you create a pull request from your repo? It would be simpler to add inline comments with the PR.

greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 5, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 5, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 5, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 5, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 5, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 5, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 5, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 6, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 6, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 6, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 6, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 6, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 6, 2015
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 6, 2015
@greaterweb
Copy link
Contributor Author

@raymondfeng I rebased my fix branch with the current loopback master and created the pull request.

Please feel free to add your comments to the PR and I'll adjust accordingly.

@greaterweb
Copy link
Contributor Author

Closing as PR has been merged.

bajtos pushed a commit that referenced this issue Jan 7, 2015
2.8.8

 * Fix context middleware to preserve domains (Pham Anh Tuan)

 * Additional password reset unit tests for API and REST  - #944 (Ron Edgecomb)

 * Small formatting update to have consistency with identical logic in other areas.   - #944 (Ron Edgecomb)

 * Simplify the API test for invalidCredentials (removed create), move above REST calls for better grouping of tests   - #944 (Ron Edgecomb)

 * Force request to send body as string, this ensures headers aren't automatically set to application/json  - #944 (Ron Edgecomb)

 * Ensure error checking logic is in place for all REST calls, expand formatting for consistency with existing instances.  - #944 (Ron Edgecomb)

 * Correct invalidCredentials so that it differs from validCredentialsEmailVerified, unit test now passes as desired.  - #944 (Ron Edgecomb)

 * Update to demonstrate unit test is actually failing due to incorrect values of invalidCredentials  - #944 (Ron Edgecomb)

 * fix jscs warning (Clark Wang)

 * fix nestRemoting is nesting hooks from other relations (Clark Wang)
greaterweb added a commit to greaterweb/loopback that referenced this issue Jan 8, 2015
…globalize-error-messages

* 'master' of github.com:strongloop/loopback: (25 commits)
  Update strong-remoting dep
  Allow accessType per remote method
  v2.9.0
  Update juggler dep
  v2.8.8
  Fix context middleware to preserve domains
  Fix Geo test cases
  Allow User.hashPassword/validatePassword to be overridden
  Additional password reset unit tests for API and REST  - strongloop#944
  Small formatting update to have consistency with identical logic in other areas.   - strongloop#944
  Simplify the API test for invalidCredentials (removed create), move above REST calls for better grouping of tests   - strongloop#944
  Force request to send body as string, this ensures headers aren't automatically set to application/json  - strongloop#944
  Ensure error checking logic is in place for all REST calls, expand formatting for consistency with existing instances.  - strongloop#944
  Correct invalidCredentials so that it differs from validCredentialsEmailVerified, unit test now passes as desired.  - strongloop#944
  Update to demonstrate unit test is actually failing due to incorrect values of invalidCredentials  - strongloop#944
  v2.8.7
  API and REST tests added to ensure complete and valid credentials are supplied for verified error message to be returned  - tests added as suggested and fail under previous version of User model  - strongloop#931
  Require valid login credentials before verified email check.  - strongloop#931.
  Change urlNotFound.js to url-not-found.js
  Add lib/server-app.js
  ...

Conflicts:
	common/models/user.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants