@@ -5,6 +5,7 @@ const chaiHttp = require("chai-http");
55const passport = require ( "passport" ) ;
66const app = require ( "../../server" ) ;
77const cleanDb = require ( "../utils/cleanDb" ) ;
8+ const config = require ( "config" ) ;
89const { generateGithubAuthRedirectUrl } = require ( "..//utils/github" ) ;
910const { generateGoogleAuthRedirectUrl, stubPassportAuthenticate } = require ( "..//utils/googleauth" ) ;
1011const { addUserToDBForTest } = require ( "../../utils/users" ) ;
@@ -404,7 +405,7 @@ describe("auth", function () {
404405 } ) ;
405406 } ) ;
406407
407- it ( "should redirect the google user to login page if the user is a developer " , async function ( ) {
408+ it ( "should return 403 Forbidden if a developer tries to log in using google " , async function ( ) {
408409 await addUserToDBForTest ( googleUserInfo [ 3 ] ) ;
409410 const rdsUiUrl = new URL ( config . get ( "services.rdsUi.baseUrl" ) ) . href ;
410411 stubPassportAuthenticate ( googleUserInfo [ 2 ] ) ;
@@ -414,20 +415,19 @@ describe("auth", function () {
414415 . get ( "/auth/google/callback" )
415416 . query ( { code : "codeReturnedByGoogle" , state : rdsUiUrl } )
416417 . redirects ( 0 ) ;
417- expect ( res ) . to . have . status ( 302 ) ;
418- const errorMessage = "Google login is restricted for developer role." ;
419- const expectedUrl = `https://realdevsquad.com/?error=${ encodeURIComponent ( errorMessage ) } ` ;
420- expect ( res . headers . location ) . to . equal ( expectedUrl ) ;
418+ expect ( res ) . to . have . status ( 403 ) ;
419+ const errorMessage = "Google Login is restricted for developers,please use github Login" ;
420+ expect ( res . body . message ) . to . equal ( errorMessage ) ;
421421 } ) ;
422422
423- it ( "should log in existing google user with same email via github OAuth " , async function ( ) {
424- await addUserToDBForTest ( googleUserInfo [ 1 ] ) ;
423+ it ( "should return 403 Forbidden if a non-developer tries to login using github " , async function ( ) {
424+ await addUserToDBForTest ( userData [ 3 ] ) ;
425425 const rdsUiUrl = new URL ( config . get ( "services.rdsUi.baseUrl" ) ) . href ;
426426 const userInfoFromGitHub = {
427427 ...githubUserInfo [ 0 ] ,
428428 _json : {
429429 ...githubUserInfo [ 0 ] . _json ,
430- email : "test12 @gmail.com" ,
430+ email : "abc1 @gmail.com" ,
431431 } ,
432432 } ;
433433 stubPassportAuthenticate ( userInfoFromGitHub ) ;
@@ -437,13 +437,14 @@ describe("auth", function () {
437437 . get ( "/auth/github/callback" )
438438 . query ( { code : "codeReturnedByGithub" , state : rdsUiUrl } )
439439 . redirects ( 0 ) ;
440- expect ( res ) . to . have . status ( 302 ) ;
441- expect ( res . headers . location ) . to . equal ( rdsUiUrl ) ;
440+ expect ( res ) . to . have . status ( 403 ) ;
441+ const errorMessage = "Github Login is restricted for non-developers,please use Google Login" ;
442+ expect ( res . body . message ) . to . equal ( errorMessage ) ;
442443 } ) ;
443444
444- it ( "should log in existing github user with same email via google OAuth" , async function ( ) {
445- await addUserToDBForTest ( userData [ 0 ] ) ;
446- const rdsUiUrl = new URL ( config . get ( "services.rdsUi.baseUrl " ) ) . href ;
445+ it ( "should log in existing github user with no role and same email via google OAuth" , async function ( ) {
446+ await addUserToDBForTest ( userData [ 1 ] ) ;
447+ const newSignupUrl = new URL ( config . get ( "services.rdsUi.newSignupUrl " ) ) . href ;
447448 const userInfoFromGoogle = {
448449 ...googleUserInfo [ 0 ] ,
449450 emails :
[ { value :
"[email protected] " , verified :
true } ] , @@ -453,10 +454,10 @@ describe("auth", function () {
453454 const res = await chai
454455 . request ( app )
455456 . get ( "/auth/google/callback" )
456- . query ( { code : "codeReturnedByGoogle" , state : rdsUiUrl } )
457+ . query ( { code : "codeReturnedByGoogle" , state : newSignupUrl } )
457458 . redirects ( 0 ) ;
458459 expect ( res ) . to . have . status ( 302 ) ;
459- expect ( res . headers . location ) . to . equal ( rdsUiUrl ) ;
460+ expect ( res . headers . location ) . to . equal ( newSignupUrl ) ;
460461 } ) ;
461462
462463 it ( "should get the verified email and redirect the google user to the goto page on successful login" , async function ( ) {
0 commit comments