2020-10-23 14:35:53 -06:00
|
|
|
/*
|
2020-10-24 07:11:14 -06:00
|
|
|
Copyright 2020 Yarmo Mackenbach
|
2020-10-23 14:35:53 -06:00
|
|
|
|
2020-10-24 07:11:14 -06:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2020-10-23 14:35:53 -06:00
|
|
|
|
2020-10-24 07:11:14 -06:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2020-10-23 14:35:53 -06:00
|
|
|
|
2020-10-24 07:11:14 -06:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2020-10-23 14:35:53 -06:00
|
|
|
*/
|
2020-10-24 12:33:48 -06:00
|
|
|
const chai = require('chai')
|
|
|
|
const expect = chai.expect
|
2020-10-24 15:36:25 -06:00
|
|
|
const chaiMatchPattern = require('chai-match-pattern')
|
|
|
|
chai.use(chaiMatchPattern)
|
2020-11-07 18:07:02 -07:00
|
|
|
chai.use(require('chai-as-promised'))
|
2020-10-24 12:33:48 -06:00
|
|
|
|
2020-10-24 15:36:25 -06:00
|
|
|
const _ = chaiMatchPattern.getLodashModule()
|
2020-10-23 14:35:53 -06:00
|
|
|
const doipjs = require('../src')
|
|
|
|
|
2020-10-24 15:36:25 -06:00
|
|
|
const pattern = {
|
|
|
|
serviceprovider: {
|
|
|
|
type: _.isString,
|
2020-11-07 18:07:02 -07:00
|
|
|
name: _.isString,
|
2020-10-24 15:36:25 -06:00
|
|
|
},
|
|
|
|
profile: {
|
|
|
|
display: _.isString,
|
2020-11-05 18:27:56 -07:00
|
|
|
uri: _.isString,
|
2020-11-07 18:07:02 -07:00
|
|
|
qr: (x) => {
|
|
|
|
return _.isString(x) || _.isNull(x)
|
|
|
|
},
|
2020-10-24 15:36:25 -06:00
|
|
|
},
|
|
|
|
proof: {
|
2020-11-07 18:07:02 -07:00
|
|
|
uri: (x) => {
|
|
|
|
return _.isString(x) || _.isNull(x)
|
|
|
|
},
|
|
|
|
fetch: (x) => {
|
|
|
|
return _.isString(x) || _.isNull(x)
|
|
|
|
},
|
2020-10-24 15:36:25 -06:00
|
|
|
useProxy: _.isBoolean,
|
2020-11-07 18:07:02 -07:00
|
|
|
format: _.isString,
|
2020-10-24 15:36:25 -06:00
|
|
|
},
|
|
|
|
claim: {
|
2020-11-07 18:07:02 -07:00
|
|
|
fingerprint: (x) => {
|
|
|
|
return _.isString(x) || _.isNull(x)
|
|
|
|
},
|
2020-10-24 15:36:25 -06:00
|
|
|
format: _.isString,
|
|
|
|
path: _.isArray,
|
2020-11-07 18:07:02 -07:00
|
|
|
relation: _.isString,
|
|
|
|
},
|
|
|
|
customRequestHandler: (x) => {
|
|
|
|
return _.isFunction(x) || _.isNull(x) || _.isUndefined(x)
|
2020-10-24 15:36:25 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-11-16 17:18:12 -07:00
|
|
|
describe('claims.verify', () => {
|
2020-10-24 03:45:30 -06:00
|
|
|
it('should be a function (3 arguments)', () => {
|
2020-11-16 17:18:12 -07:00
|
|
|
expect(doipjs.claims.verify).to.be.a('function')
|
|
|
|
expect(doipjs.claims.verify).to.have.length(3)
|
2020-10-23 14:35:53 -06:00
|
|
|
})
|
2020-10-24 03:56:30 -06:00
|
|
|
it('should throw an error for non-valid URIs', () => {
|
2020-11-16 17:18:12 -07:00
|
|
|
return expect(doipjs.claims.verify('noURI')).to.eventually.be.rejectedWith(
|
2020-12-05 15:10:48 -07:00
|
|
|
'Invalid URI'
|
2020-11-07 18:07:02 -07:00
|
|
|
)
|
2020-11-16 16:57:07 -07:00
|
|
|
return expect(
|
2020-11-16 17:18:12 -07:00
|
|
|
doipjs.claims.verify('domain.org')
|
2020-12-05 15:10:48 -07:00
|
|
|
).to.eventually.be.rejectedWith('Invalid URI')
|
2020-10-24 03:56:30 -06:00
|
|
|
})
|
2020-10-24 18:02:19 -06:00
|
|
|
|
|
|
|
doipjs.serviceproviders.list.forEach((spName, i) => {
|
|
|
|
const sp = doipjs.serviceproviders.data[spName]
|
|
|
|
|
2020-11-07 18:07:02 -07:00
|
|
|
if (sp.tests.length == 0) {
|
|
|
|
return
|
|
|
|
}
|
2020-10-24 18:02:19 -06:00
|
|
|
|
|
|
|
it(`should return a valid object for the "${spName}" service provider`, async () => {
|
2020-11-16 17:18:12 -07:00
|
|
|
const matches = await doipjs.claims.verify(sp.tests[0].uri, null, {
|
2020-11-07 18:07:02 -07:00
|
|
|
returnMatchesOnly: true,
|
|
|
|
})
|
2020-10-24 18:02:19 -06:00
|
|
|
expect(matches).to.be.a('array')
|
2020-11-03 14:32:43 -07:00
|
|
|
expect(matches).to.be.length.above(0)
|
2020-10-24 18:02:19 -06:00
|
|
|
expect(matches[0].serviceprovider.name).to.be.equal(spName)
|
|
|
|
expect(matches[0]).to.matchPattern(pattern)
|
|
|
|
})
|
2020-10-24 17:54:37 -06:00
|
|
|
})
|
2020-10-23 14:35:53 -06:00
|
|
|
})
|