Skip to content

Commit

Permalink
SDK-1741: Add support for biometric consent
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston committed Sep 10, 2020
1 parent 15d4d2d commit dcf32e2
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ class SessionSpecificationBuilder {
return this;
}

/**
* Sets whether or not to block the collection of biometric consent
*
* @param {bool} blockBiometricConsent
*
* @return {this}
*/
withBlockBiometricConsent(blockBiometricConsent) {
Validation.isBoolean(blockBiometricConsent, 'blockBiometricConsent');
this.blockBiometricConsent = blockBiometricConsent;
return this;
}

/**
* Builds the {@link SessionSpec} based on the values supplied to the builder
*
Expand All @@ -141,7 +154,8 @@ class SessionSpecificationBuilder {
this.requestedChecks,
this.requestedTasks,
this.sdkConfig,
this.requiredDocuments
this.requiredDocuments,
this.blockBiometricConsent
);
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/doc_scan_service/session/create/session.specification.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class SessionSpecification {
* The SDK configuration set on the session specification
* @param {RequiredDocument[]} requiredDocuments
* List of RequiredDocument defining the documents required from the client
* @param {bool} blockBiometricConsent
* Sets whether or not to block the collection of biometric consent
*/
constructor(
clientSessionTokenTtl,
Expand All @@ -39,7 +41,8 @@ class SessionSpecification {
requestedChecks,
requestedTasks,
sdkConfig,
requiredDocuments
requiredDocuments,
blockBiometricConsent
) {
Validation.isInteger(clientSessionTokenTtl, 'clientSessionTokenTtl', true);
this.clientSessionTokenTtl = clientSessionTokenTtl;
Expand Down Expand Up @@ -70,6 +73,9 @@ class SessionSpecification {
Validation.isArrayOfType(requiredDocuments, RequiredDocument, 'requiredDocuments');
this.requiredDocuments = requiredDocuments;
}

Validation.isBoolean(blockBiometricConsent, 'blockBiometricConsent', true);
this.blockBiometricConsent = blockBiometricConsent;
}

/**
Expand All @@ -85,6 +91,7 @@ class SessionSpecification {
requested_tasks: this.requestedTasks,
sdk_config: this.sdkConfig,
required_documents: this.requiredDocuments,
block_biometric_consent: this.blockBiometricConsent,
};
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/doc_scan_service/session/retrieve/get.session.result.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const TextDataCheckResponse = require('./text.data.check.response');
const LivenessCheckResponse = require('./liveness.check.response');
const IdDocumentComparisonCheckResponse = require('./id.document.comparison.check.response');
const DocScanConstants = require('../../doc.scan.constants');
const { YotiDate } = require('../../../data_type/date');

class GetSessionResult {
constructor(response) {
Expand Down Expand Up @@ -55,6 +56,10 @@ class GetSessionResult {
Validation.instanceOf(response.resources, Object);
this.resources = new ResourceContainer(response.resources);
}

if (response.biometric_consent) {
this.biometricConsent = YotiDate.fromDateString(response.biometric_consent);
}
}

/**
Expand Down Expand Up @@ -140,6 +145,13 @@ class GetSessionResult {
getUserTrackingId() {
return this.userTrackingId;
}

/**
* @returns {YotiDate}
*/
getBiometricConsentTimestamp() {
return this.biometricConsent;
}
}

module.exports = GetSessionResult;
6 changes: 5 additions & 1 deletion src/yoti_common/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ module.exports = class Validation {
/**
* @param {*} value
* @param {string} name
* @param {bool} optional the value can be undefined
*
* @throws {TypeError}
*/
static isBoolean(value, name) {
static isBoolean(value, name, optional = false) {
if ((typeof value) === 'undefined' && optional) {
return;
}
if ((typeof value) !== 'boolean') {
throw TypeError(`${name} must be a boolean`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,47 +65,51 @@ describe('SessionSpecificationBuilder', () => {
topics: [],
},
requested_checks: [
{
type: 'ID_DOCUMENT_FACE_MATCH',
config: {
manual_check: 'NEVER',
},
},
{
type: 'LIVENESS',
config: {
max_retries: 1,
liveness_type: 'ZOOM',
},
},
{
type: 'ID_DOCUMENT_AUTHENTICITY',
config: {},
},
faceMatchCheck,
livenessCheck,
docAuthenticityCheck,
],
requested_tasks: [
{
type: 'ID_DOCUMENT_TEXT_DATA_EXTRACTION',
config: {
manual_check: 'FALLBACK',
},
},
textExtractionTask,
],
sdk_config: {
allowed_capture_methods: 'CAMERA',
},
required_documents: [
{
type: 'ID_DOCUMENT',
filter: {
type: 'DOCUMENT_RESTRICTIONS',
inclusion: 'WHITELIST',
documents: [],
},
},
requiredDocument,
],
});

expect(JSON.stringify(sessionSpec)).toBe(expectedJson);
});

it('should build SessionSpecification with block biometric consent true', () => {
const sessionSpec = new SessionSpecificationBuilder()
.withBlockBiometricConsent(true)
.build();

const expectedJson = JSON.stringify({
requested_checks: [],
requested_tasks: [],
required_documents: [],
block_biometric_consent: true,
});

expect(JSON.stringify(sessionSpec)).toBe(expectedJson);
});

it('should build SessionSpecification with block biometric consent false', () => {
const sessionSpec = new SessionSpecificationBuilder()
.withBlockBiometricConsent(false)
.build();

const expectedJson = JSON.stringify({
requested_checks: [],
requested_tasks: [],
required_documents: [],
block_biometric_consent: false,
});

expect(JSON.stringify(sessionSpec)).toBe(expectedJson);
});
});
12 changes: 12 additions & 0 deletions tests/doc_scan_service/session/retrieve/get.session.result.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ const TextDataCheckResponse = require('../../../../src/doc_scan_service/session/
const LivenessCheckResponse = require('../../../../src/doc_scan_service/session/retrieve/liveness.check.response');
const ResourceContainer = require('../../../../src/doc_scan_service/session/retrieve/resource.container');
const IdDocumentComparisonCheckResponse = require('../../../../src/doc_scan_service/session/retrieve/id.document.comparison.check.response');
const { YotiDate } = require('../../../..');

const ID_DOCUMENT_AUTHENTICITY = 'ID_DOCUMENT_AUTHENTICITY';
const ID_DOCUMENT_FACE_MATCH = 'ID_DOCUMENT_FACE_MATCH';
const ID_DOCUMENT_TEXT_DATA_CHECK = 'ID_DOCUMENT_TEXT_DATA_CHECK';
const LIVENESS = 'LIVENESS';
const ID_DOCUMENT_COMPARISON = 'ID_DOCUMENT_COMPARISON';
const SOME_UNKNOWN_CHECK = 'SOME_UNKNOWN_CHECK';
const SOME_DATE_STRING = '2019-12-02T12:00:00.123Z';

describe('GetSessionResult', () => {
let session;
Expand Down Expand Up @@ -45,6 +47,7 @@ describe('GetSessionResult', () => {
type: ID_DOCUMENT_COMPARISON,
},
],
biometric_consent: SOME_DATE_STRING,
});
});

Expand Down Expand Up @@ -169,4 +172,13 @@ describe('GetSessionResult', () => {
expect(checks[0].getType()).toBe(SOME_UNKNOWN_CHECK);
});
});

describe('#getBiometricConsentTimestamp', () => {
it('should return biometric consent timestamp container', () => {
const biometricConsent = session.getBiometricConsentTimestamp();
expect(biometricConsent).toBeInstanceOf(YotiDate);
expect(biometricConsent).toBeInstanceOf(Date);
expect(biometricConsent.toISOString()).toBe(SOME_DATE_STRING);
});
});
});

0 comments on commit dcf32e2

Please sign in to comment.