This repository has been archived by the owner on Jul 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MFA-311] Support guardian policies, phone selected-provider and mess…
…age-types (#96) * feat: add support for guardian policies * feat: add support for guardian phone factor selected provider * feat: add support for guardian phone factor message types * chore: bump to v4.1.0
- Loading branch information
Showing
11 changed files
with
426 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import DefaultHandler from './default'; | ||
import constants from '../../constants'; | ||
|
||
export const schema = { | ||
type: 'object', | ||
properties: { | ||
message_types: { | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
enum: constants.GUARDIAN_PHONE_MESSAGE_TYPES | ||
} | ||
} | ||
}, | ||
required: [ 'message_types' ], | ||
additionalProperties: false | ||
}; | ||
|
||
|
||
export default class GuardianPhoneMessageTypesHandler extends DefaultHandler { | ||
constructor(options) { | ||
super({ | ||
...options, | ||
type: 'guardianPhoneFactorMessageTypes' | ||
}); | ||
} | ||
|
||
async getType() { | ||
// in case client version does not support the operation | ||
if (!this.client.guardian || typeof this.client.guardian.getPhoneFactorMessageTypes !== 'function') { | ||
return null; | ||
} | ||
|
||
if (this.existing) return this.existing; | ||
this.existing = await this.client.guardian.getPhoneFactorMessageTypes(); | ||
return this.existing; | ||
} | ||
|
||
async processChanges(assets) { | ||
// No API to delete or create guardianPhoneFactorMessageTypes, we can only update. | ||
const { guardianPhoneFactorMessageTypes } = assets; | ||
|
||
// Do nothing if not set | ||
if (!guardianPhoneFactorMessageTypes) return; | ||
|
||
const params = {}; | ||
const data = guardianPhoneFactorMessageTypes; | ||
await this.client.guardian.updatePhoneFactorMessageTypes(params, data); | ||
this.updated += 1; | ||
this.didUpdate(guardianPhoneFactorMessageTypes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import DefaultHandler from './default'; | ||
import constants from '../../constants'; | ||
|
||
export const schema = { | ||
type: 'object', | ||
properties: { | ||
provider: { | ||
type: 'string', | ||
enum: constants.GUARDIAN_PHONE_PROVIDERS | ||
} | ||
}, | ||
required: [ 'provider' ], | ||
additionalProperties: false | ||
}; | ||
|
||
|
||
export default class GuardianPhoneSelectedProviderHandler extends DefaultHandler { | ||
constructor(options) { | ||
super({ | ||
...options, | ||
type: 'guardianPhoneFactorSelectedProvider' | ||
}); | ||
} | ||
|
||
async getType() { | ||
// in case client version does not support the operation | ||
if (!this.client.guardian || typeof this.client.guardian.getPhoneFactorSelectedProvider !== 'function') { | ||
return null; | ||
} | ||
|
||
if (this.existing) return this.existing; | ||
this.existing = await this.client.guardian.getPhoneFactorSelectedProvider(); | ||
return this.existing; | ||
} | ||
|
||
async processChanges(assets) { | ||
// No API to delete or create guardianPhoneFactorSelectedProvider, we can only update. | ||
const { guardianPhoneFactorSelectedProvider } = assets; | ||
|
||
// Do nothing if not set | ||
if (!guardianPhoneFactorSelectedProvider) return; | ||
|
||
const params = {}; | ||
const data = guardianPhoneFactorSelectedProvider; | ||
await this.client.guardian.updatePhoneFactorSelectedProvider(params, data); | ||
this.updated += 1; | ||
this.didUpdate(guardianPhoneFactorSelectedProvider); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import DefaultHandler from './default'; | ||
import constants from '../../constants'; | ||
|
||
export const schema = { | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
enum: constants.GUARDIAN_POLICIES | ||
}, | ||
minLength: 0, | ||
maxLength: 1 | ||
}; | ||
|
||
|
||
export default class GuardianPoliciesHandler extends DefaultHandler { | ||
constructor(options) { | ||
super({ | ||
...options, | ||
type: 'guardianPolicies' | ||
}); | ||
} | ||
|
||
async getType() { | ||
// in case client version does not support the operation | ||
if (!this.client.guardian || typeof this.client.guardian.getPolicies !== 'function') { | ||
return null; | ||
} | ||
|
||
if (this.existing) return this.existing; | ||
this.existing = await this.client.guardian.getPolicies(); | ||
return this.existing; | ||
} | ||
|
||
async processChanges(assets) { | ||
// No API to delete or create guardianPolicies, we can only update. | ||
const { guardianPolicies } = assets; | ||
|
||
// Do nothing if not set | ||
if (!guardianPolicies) return; | ||
|
||
const params = {}; | ||
const data = guardianPolicies; | ||
await this.client.guardian.updatePolicies(params, data); | ||
this.updated += 1; | ||
this.didUpdate(guardianPolicies); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
tests/auth0/handlers/guardianPhoneFactorMessageTypes.tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const { expect } = require('chai'); | ||
const guardianPhoneFactorMessageTypes = require('../../../src/auth0/handlers/guardianPhoneFactorMessageTypes'); | ||
|
||
describe('#guardianPhoneFactorMessageTypes handler', () => { | ||
describe('#getType', () => { | ||
it('should support older version of auth0 client', async () => { | ||
const auth0 = { | ||
guardian: { | ||
// omitting getPhoneFactorMessageTypes() | ||
} | ||
}; | ||
|
||
const handler = new guardianPhoneFactorMessageTypes.default({ client: auth0 }); | ||
const data = await handler.getType(); | ||
expect(data).to.deep.equal(null); | ||
}); | ||
|
||
it('should get guardian phone factor message types', async () => { | ||
const auth0 = { | ||
guardian: { | ||
getPhoneFactorMessageTypes: () => ({ message_types: [ 'sms', 'voice' ] }) | ||
} | ||
}; | ||
|
||
const handler = new guardianPhoneFactorMessageTypes.default({ client: auth0 }); | ||
const data = await handler.getType(); | ||
expect(data).to.deep.equal({ message_types: [ 'sms', 'voice' ] }); | ||
}); | ||
}); | ||
|
||
describe('#processChanges', () => { | ||
it('should update guardian phone factor message types', async () => { | ||
const auth0 = { | ||
guardian: { | ||
updatePhoneFactorMessageTypes: (params, data) => { | ||
expect(data).to.eql({ message_types: [ 'sms', 'voice' ] }); | ||
return Promise.resolve(data); | ||
} | ||
} | ||
}; | ||
|
||
const handler = new guardianPhoneFactorMessageTypes.default({ client: auth0 }); | ||
const stageFn = Object.getPrototypeOf(handler).processChanges; | ||
|
||
await stageFn.apply(handler, [ | ||
{ guardianPhoneFactorMessageTypes: { message_types: [ 'sms', 'voice' ] } } | ||
]); | ||
}); | ||
|
||
it('should skip processing if assets are empty', async () => { | ||
const auth0 = { | ||
guardian: { | ||
updatePhoneFactorMessageTypes: () => { | ||
const err = new Error('updatePhoneFactorMessageTypes() should not have been called'); | ||
return Promise.reject(err); | ||
} | ||
} | ||
}; | ||
|
||
const handler = new guardianPhoneFactorMessageTypes.default({ client: auth0 }); | ||
const stageFn = Object.getPrototypeOf(handler).processChanges; | ||
|
||
await stageFn.apply(handler, [ | ||
{ guardianPhoneFactorMessageTypes: null } | ||
]); | ||
}); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
tests/auth0/handlers/guardianPhoneFactorSelectedProvider.tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const { expect } = require('chai'); | ||
const guardianPhoneFactorSelectedProvider = require('../../../src/auth0/handlers/guardianPhoneFactorSelectedProvider'); | ||
|
||
describe('#guardianPhoneFactorSelectedProvider handler', () => { | ||
describe('#getType', () => { | ||
it('should support older version of auth0 client', async () => { | ||
const auth0 = { | ||
guardian: { | ||
// omitting getPhoneFactorSelectedProvider() | ||
} | ||
}; | ||
|
||
const handler = new guardianPhoneFactorSelectedProvider.default({ client: auth0 }); | ||
const data = await handler.getType(); | ||
expect(data).to.deep.equal(null); | ||
}); | ||
|
||
it('should get guardian phone factor selected provider', async () => { | ||
const auth0 = { | ||
guardian: { | ||
getPhoneFactorSelectedProvider: () => ({ provider: 'twilio' }) | ||
} | ||
}; | ||
|
||
const handler = new guardianPhoneFactorSelectedProvider.default({ client: auth0 }); | ||
const data = await handler.getType(); | ||
expect(data).to.deep.equal({ provider: 'twilio' }); | ||
}); | ||
}); | ||
|
||
describe('#processChanges', () => { | ||
it('should update guardian phone factor selected provider', async () => { | ||
const auth0 = { | ||
guardian: { | ||
updatePhoneFactorSelectedProvider: (params, data) => { | ||
expect(data).to.eql({ provider: 'twilio' }); | ||
return Promise.resolve(data); | ||
} | ||
} | ||
}; | ||
|
||
const handler = new guardianPhoneFactorSelectedProvider.default({ client: auth0 }); | ||
const stageFn = Object.getPrototypeOf(handler).processChanges; | ||
|
||
await stageFn.apply(handler, [ | ||
{ guardianPhoneFactorSelectedProvider: { provider: 'twilio' } } | ||
]); | ||
}); | ||
|
||
it('should skip processing if assets are empty', async () => { | ||
const auth0 = { | ||
guardian: { | ||
updatePhoneFactorSelectedProvider: () => { | ||
const err = new Error('updatePhoneFactorSelectedProvider() should not have been called'); | ||
return Promise.reject(err); | ||
} | ||
} | ||
}; | ||
|
||
const handler = new guardianPhoneFactorSelectedProvider.default({ client: auth0 }); | ||
const stageFn = Object.getPrototypeOf(handler).processChanges; | ||
|
||
await stageFn.apply(handler, [ | ||
{ guardianPhoneFactorSelectedProvider: null } | ||
]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.