openhim-core
Version:
The OpenHIM core application that provides logging and routing of http requests
46 lines (40 loc) • 1.45 kB
JavaScript
/* eslint-env mocha */
import { _getEnabledAuthenticationTypesFromConfig } from '../../src/api/authentication'
describe('API authentication', () => {
describe('getEnabledAuthenticationTypesFromConfig', () => {
it('returns authentication types if configured as an array', () => {
const authenticationTypes = ['token']
const enabledTypes = _getEnabledAuthenticationTypesFromConfig({
api: {
authenticationTypes
}
})
enabledTypes.should.deepEqual(authenticationTypes)
})
it('returns authentication types if configured as a JSON array', () => {
const authenticationTypes = ['token']
const enabledTypes = _getEnabledAuthenticationTypesFromConfig({
api: {
authenticationTypes: JSON.stringify(authenticationTypes)
}
})
enabledTypes.should.deepEqual(authenticationTypes)
})
it('returns an empty array if configured with JSON other than an array', () => {
const enabledTypes = _getEnabledAuthenticationTypesFromConfig({
api: {
authenticationTypes: '"basic"'
}
})
enabledTypes.should.deepEqual([])
})
it('returns an empty array if configured with invalid JSON', () => {
const enabledTypes = _getEnabledAuthenticationTypesFromConfig({
api: {
authenticationTypes: '[invalid, json]'
}
})
enabledTypes.should.deepEqual([])
})
})
})