Freecodecamp: Advanced Node and Express - Implementation of Social Authentication -> Test validation error with possible soultion

Created on 29 Jun 2018  路  7Comments  路  Source: freeCodeCamp/freeCodeCamp

Describe your problem and - if possible - how to reproduce it

Advanced Node and Express - Implementation of Social Authentication test validation fails,
although all steps done correctly and the live version of glitch project works fine.

As I reviewed the the validation test, I found a bug:
original : assert.match(data, /('|\")\/auth\/github('|\")[^]get.passport.authenticate.*github/gi,
(I found it on https://github.com/P1xt/fcc-is-forked/blob/master/src/app/services/challenges/data/06-information-security-and-quality-assurance/advanced-express-tools.json)

the correct regexp: /(\'|\")\/auth\/github(\'|\")[^]get.passport.authenticate.*github/gi

Add a Link to the page with the problem

Tell us about your browser and operating system

  • Browser Name: Chrome
  • Browser Version: Version 67.0.3396.99 (Official Build) (64-bit)
  • Operating System: Debian unstable

If possible, add a screenshot here

learn

Most helpful comment

I've been trying to get this test to pass for a bit.
This didn't work:

    app.route('/auth/github/callback')
      .get(passport.authenticate('github', {
      failureRedirect: '/'}),
      (req, res) => {
        res.redirect('/profile');
    });

This finally did:

      app.route('/auth/github/callback')
      .get(passport.authenticate('github', {failureRedirect: '/'}),
      (req, res) => {
        res.redirect('/profile');
    });

I played around with the regex a little and found that this:
/('|\")\/auth\/github\/callback('|\")[^]*get.*passport.authenticate.*github[\S\s]*failureRedirect:( |)(\"|')\/(\"|')/gi
allows for the new line before failureRedirect

And as you mentioned, the testing is done on the server.js file, which is fine if the project is not broken up in modules as it was in the prior challenge. I mentioned this here: https://github.com/freeCodeCamp/freeCodeCamp/issues/17068
The way the tests are organized now, it is not clear that we move to a new boilerplate at this challenge. I think it would be make more sense to just keep using the previous boilerplate, but then the tests would need to be changed to test in the routes.js or auth.js files instead of server.js.

All 7 comments

After examining the correct validation source (https://github.com/freeCodeCamp/freeCodeCamp/blob/master/seed/challenges/06-information-security-and-quality-assurance/advanced-express-tools.json)

I realised that the test can be passed if i us --> " <-- instead --> ' <--, and i do not put these options to the Auth.js file, because the validator tests the server.js file

I've been trying to get this test to pass for a bit.
This didn't work:

    app.route('/auth/github/callback')
      .get(passport.authenticate('github', {
      failureRedirect: '/'}),
      (req, res) => {
        res.redirect('/profile');
    });

This finally did:

      app.route('/auth/github/callback')
      .get(passport.authenticate('github', {failureRedirect: '/'}),
      (req, res) => {
        res.redirect('/profile');
    });

I played around with the regex a little and found that this:
/('|\")\/auth\/github\/callback('|\")[^]*get.*passport.authenticate.*github[\S\s]*failureRedirect:( |)(\"|')\/(\"|')/gi
allows for the new line before failureRedirect

And as you mentioned, the testing is done on the server.js file, which is fine if the project is not broken up in modules as it was in the prior challenge. I mentioned this here: https://github.com/freeCodeCamp/freeCodeCamp/issues/17068
The way the tests are organized now, it is not clear that we move to a new boilerplate at this challenge. I think it would be make more sense to just keep using the previous boilerplate, but then the tests would need to be changed to test in the routes.js or auth.js files instead of server.js.

To solve the authentication challenges let all the files be in server.js .This seemsto be the place where all tests are evaluated.i.e contents of auth and route should be returned to server.js.

I moved my two github routes to the server.js file, as @ibnthani2016 suggested. This passed the tests for me.

@RandellDawson ran into the same issue as @ibnthani2016 (I was able to fix by analyzing the assertions themselves, so I was able to pass the challenge) Seems like since the previous challenge is creating the new modules that the social auth test should be looking at the routes.js module for the new paths. This also seems to be unrelated to the original issue this was opened for. Should I create a new issue for that?

It's not very obvious, but after trying for an hour and a half to get the tests to pass yesterday, I figured out there's a different boilerplate you're supposed to use for the Social Authentication challenges which has all the code in server.js. The link is correct in the exercise, but it's not spelled out that it's different from the one being used up to that point.

@clandau
Finally, after 2 long days I was able to pass the test. Shocked to know that it was not passing due to indentation : )
Thank you soo much..

Was this page helpful?
0 / 5 - 0 ratings