doipjs/test/claims.test.js

87 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-10-23 14:35:53 -06:00
/*
2021-01-13 05:20:33 -07:00
Copyright 2021 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)
},
2021-04-12 08:15:16 -06:00
request: {
fetcher: _.isString,
access: _.isInteger,
format: _.isInteger,
data: _.isObject,
2020-11-07 18:07:02 -07:00
},
2020-10-24 15:36:25 -06:00
},
claim: {
2020-11-07 18:07:02 -07:00
fingerprint: (x) => {
return _.isString(x) || _.isNull(x)
},
2021-04-12 08:15:16 -06:00
format: _.isInteger,
relation: _.isInteger,
2020-10-24 15:36:25 -06:00
path: _.isArray,
},
}
describe('claims.verify', () => {
it('should be a function (3 arguments)', () => {
expect(doipjs.claims.verify).to.be.a('function')
expect(doipjs.claims.verify).to.have.length(3)
2020-10-23 14:35:53 -06:00
})
it('should return undefined for non-valid URIs', () => {
return expect(doipjs.claims.verify('noURI')).to.eventually.be.rejectedWith(
undefined
2020-11-07 18:07:02 -07:00
)
2020-10-24 03:56:30 -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
}
it(`should return a valid object for the "${spName}" service provider`, async () => {
const matches = await doipjs.claims.verify(sp.tests[0].uri, null, {
2020-11-07 18:07:02 -07:00
returnMatchesOnly: true,
})
expect(matches).to.be.a('array')
expect(matches).to.be.length.above(0)
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
})