test(auth): added test for serverinfo auth strategies test
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* istanbul ignore file */
|
||||
'use strict'
|
||||
const fs = require( 'fs' )
|
||||
const path = require( 'path' )
|
||||
|
||||
@@ -78,23 +78,30 @@ exports.init = ( app, options ) => {
|
||||
} )
|
||||
|
||||
// TODO: add logout route
|
||||
//
|
||||
|
||||
|
||||
// Strategies initialisation & listing
|
||||
// NOTE: if no strategies are defined, the local one will be enabled.
|
||||
|
||||
let strategyCount = 0
|
||||
|
||||
if ( process.env.STRATEGY_GITHUB === 'true' ) {
|
||||
let githubStrategy = require( './strategies/github' )( app, session, sessionAppId, finalizeAuth )
|
||||
authStrategies.push( githubStrategy )
|
||||
strategyCount++
|
||||
}
|
||||
|
||||
if ( process.env.STRATEGY_GOOGLE === 'true' ) {
|
||||
let googStrategy = require( './strategies/google' )( app, session, sessionAppId, finalizeAuth )
|
||||
authStrategies.push( googStrategy )
|
||||
strategyCount++
|
||||
}
|
||||
|
||||
if ( process.env.STRATEGY_LOCAL === 'true' ) {
|
||||
// Note: always leave the local strategy init for last so as to be able to
|
||||
// force enable it in case no others are present.
|
||||
if ( process.env.STRATEGY_LOCAL === 'true' || strategyCount === 0 ) {
|
||||
let localStrategy = require( './strategies/local' )( app, session, sessionAppId, finalizeAuth )
|
||||
authStrategies.push( localStrategy )
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@ const request = require( 'supertest' )
|
||||
const assert = require( 'assert' )
|
||||
const appRoot = require( 'app-root-path' )
|
||||
|
||||
const { init } = require( `${appRoot}/app` )
|
||||
const { init, startHttp } = require( `${appRoot}/app` )
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
const knex = require( `${appRoot}/db/knex` )
|
||||
|
||||
describe( 'Auth', ( ) => {
|
||||
describe( 'Auth @auth', ( ) => {
|
||||
|
||||
describe( 'Local authN @auth-local', ( ) => {
|
||||
let expressApp
|
||||
@@ -60,4 +60,46 @@ describe( 'Auth', ( ) => {
|
||||
.expect( 401 )
|
||||
} )
|
||||
} )
|
||||
|
||||
describe( 'Strategies List @auth-info', ( ) => {
|
||||
|
||||
let testServer
|
||||
|
||||
before( async ( ) => {
|
||||
|
||||
await knex.migrate.rollback( )
|
||||
await knex.migrate.latest( )
|
||||
|
||||
let { app } = await init( )
|
||||
let { server } = await startHttp( app )
|
||||
testServer = server
|
||||
|
||||
} )
|
||||
|
||||
after( async ( ) => {
|
||||
|
||||
testServer.close( )
|
||||
|
||||
} )
|
||||
|
||||
it( 'ServerInfo Query should return the auth strategies available', async ( ) => {
|
||||
|
||||
const query = `query sinfo { serverInfo { authStrategies { id name icon url color } } }`
|
||||
const res = await sendRequest( null, { query } )
|
||||
expect( res.body.errors ).to.not.exist
|
||||
expect( res.body.data.serverInfo.authStrategies ).to.be.an( 'array' )
|
||||
|
||||
} )
|
||||
|
||||
|
||||
} )
|
||||
|
||||
} )
|
||||
|
||||
const serverAddress = `http://localhost:${process.env.PORT || 3000}`
|
||||
|
||||
function sendRequest( auth, obj, address = serverAddress ) {
|
||||
|
||||
return chai.request( address ).post( '/graphql' ).set( 'Authorization', auth ).send( obj )
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user