bedrock-app-identity
Advanced tools
Comparing version 1.1.0 to 1.2.0
# bedrock-app-identity ChangeLog | ||
## 1.2.0 - 2021-01-21 | ||
- Add additional tests. | ||
## 1.1.0 - 2021-11-18 | ||
@@ -4,0 +8,0 @@ |
@@ -58,3 +58,3 @@ /*! | ||
async function _generateApplicationIdentity({name, seedDescription}) { | ||
export async function _generateApplicationIdentity({name, seedDescription}) { | ||
if(APPLICATION_IDENTITY) { | ||
@@ -85,3 +85,3 @@ throw new BedrockError( | ||
async function _generateServiceIdentity({name, seedDescription}) { | ||
export async function _generateServiceIdentity({name, seedDescription}) { | ||
if(SERVICE_IDENTITIES.has(name)) { | ||
@@ -150,1 +150,6 @@ throw new BedrockError( | ||
} | ||
// For testing purposes only | ||
export function _resetApplicationIdentity() { | ||
APPLICATION_IDENTITY = undefined; | ||
} |
{ | ||
"name": "bedrock-app-identity", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Bedrock HTTP API", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
@@ -5,2 +5,8 @@ /* | ||
const {getAppIdentity, getServiceIdentities} = require('bedrock-app-identity'); | ||
const bedrock = require('bedrock'); | ||
const { | ||
_resetApplicationIdentity, | ||
_generateApplicationIdentity, | ||
_generateServiceIdentity | ||
} = require('bedrock-app-identity'); | ||
@@ -38,2 +44,126 @@ describe('bedrock-app-identity API', () => { | ||
}); | ||
it('throws error when attempting to configure app identity again', | ||
async () => { | ||
const {seeds} = bedrock.config['app-identity']; | ||
let err; | ||
let res; | ||
try { | ||
res = await _generateApplicationIdentity({seedDescription: seeds.app}); | ||
} catch(e) { | ||
err = e; | ||
} | ||
should.exist(err); | ||
should.not.exist(res); | ||
err.name.should.equal('DuplicateError'); | ||
err.message.should.equal( | ||
'Application identity was previously configured.'); | ||
}); | ||
it('throws error if service identity name was previously configured', | ||
async () => { | ||
let err; | ||
let res; | ||
try { | ||
// set service name to `test` which has already been configured | ||
res = await _generateServiceIdentity({name: 'test'}); | ||
} catch(e) { | ||
err = e; | ||
} | ||
should.exist(err); | ||
should.not.exist(res); | ||
err.name.should.equal('DuplicateError'); | ||
err.message.should.equal( | ||
'Service identity (test) was previously configured.'); | ||
}); | ||
it('throws error if the generated application ID does not match the ID found', | ||
async () => { | ||
_resetApplicationIdentity(); | ||
const seedDescription = { | ||
id: 'did:key:z6MkmXjRf7pMCH8ct1ekbdqFMEcak1zDJTR31gXDokDhA69h', | ||
// this seed will generate an unmatching application ID | ||
seedMultibase: 'z1AdmTr7Z4fr6nBMH634Uti7tgQmHaCvMmKwJ9bo9yBhz1q' | ||
}; | ||
let err; | ||
let res; | ||
try { | ||
res = await _generateApplicationIdentity( | ||
{name: 'test', seedDescription}); | ||
} catch(e) { | ||
err = e; | ||
} | ||
should.exist(err); | ||
should.not.exist(res); | ||
err.name.should.equal('InvalidStateError'); | ||
err.message.should.equal( | ||
'The generated application ID does not match the ID found in the ' + | ||
'identity\'s description.'); | ||
err.details.identityName.should.equal('test'); | ||
err.details.expectedId.should.equal( | ||
'did:key:z6MkmXjRf7pMCH8ct1ekbdqFMEcak1zDJTR31gXDokDhA69h'); | ||
err.details.actualId.should.equal( | ||
'did:key:z6Mki1LV6wD9z7BhsmJsVBPuQnxLB4pZRsfrSinD4qmG8UNL'); | ||
}); | ||
it('throws error if the generated service ID does not match the ID found', | ||
async () => { | ||
const seedDescription = { | ||
id: 'did:key:z6MkqazfWvQjrKJxu7caQsrz7gbg1sPzY6B2GtyPkrhdXekf', | ||
// this seed will generate an unmatching service ID | ||
seedMultibase: 'z1AhhfKGoQWcmFT5T4CqK78tUBFZqtGYThdxd5EZESgwCqD' | ||
}; | ||
_resetApplicationIdentity(); | ||
let err; | ||
let res; | ||
try { | ||
res = await _generateServiceIdentity({name: 'test2', seedDescription}); | ||
} catch(e) { | ||
err = e; | ||
} | ||
should.exist(err); | ||
should.not.exist(res); | ||
err.name.should.equal('InvalidStateError'); | ||
err.message.should.equal( | ||
'The generated service id does not match the id found in the ' + | ||
'service identity\'s description.'); | ||
err.details.seedName.should.equal('test2'); | ||
err.details.seedDescriptionId.should.equal( | ||
'did:key:z6MkqazfWvQjrKJxu7caQsrz7gbg1sPzY6B2GtyPkrhdXekf'); | ||
err.details.generatedKeyId.should.equal( | ||
'did:key:z6Mks7oWc1GaYXiXgCf9GXeUYVFiYC5JFQmnnnk5N7Vvfmhf'); | ||
}); | ||
it('throws error if "serviceType" is missing for service identity', | ||
async () => { | ||
const seedDescription = { | ||
id: 'did:key:z6MknnVVvr8HRx2FZcm3r8dEFmJPV3NgKLYBf9omS5zxbDrZ', | ||
seedMultibase: 'z1AjQcbsw5XA7emiBaLUuMusTowm3M7tjA3Yt1ZoqEg9Dwj' | ||
}; | ||
_resetApplicationIdentity(); | ||
let err; | ||
let res; | ||
try { | ||
res = await _generateServiceIdentity({name: 'test2', seedDescription}); | ||
} catch(e) { | ||
err = e; | ||
} | ||
should.exist(err); | ||
should.not.exist(res); | ||
err.name.should.equal('InvalidStateError'); | ||
err.message.should.equal( | ||
'Missing "serviceType" for service identity [test2].'); | ||
}); | ||
it('throws error if "APPLICATION_IDENTITY" is undefined', | ||
async () => { | ||
// Set APPLICATION_IDENTITY to undefined | ||
_resetApplicationIdentity(); | ||
let err; | ||
let res; | ||
try { | ||
res = getAppIdentity(); | ||
} catch(e) { | ||
err = e; | ||
} | ||
should.exist(err); | ||
should.not.exist(res); | ||
err.name.should.equal('NotFoundError'); | ||
err.message.should.equal('Application identity not found.'); | ||
}); | ||
}); |
@@ -7,4 +7,4 @@ { | ||
"test": "node --preserve-symlinks test.js test", | ||
"coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text-summary npm test", | ||
"coverage-ci": "cross-env NODE_ENV=test nyc --reporter=lcovonly npm test", | ||
"coverage": "cross-env NODE_ENV=test ESM_OPTIONS='{cache:false}' nyc --reporter=lcov --reporter=text-summary npm test", | ||
"coverage-ci": "cross-env NODE_ENV=test ESM_OPTIONS='{cache:false}' nyc --reporter=lcovonly npm test", | ||
"coverage-report": "nyc report" | ||
@@ -11,0 +11,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
21939
372
0