Throw error for invalid URI

This commit is contained in:
Yarmo Mackenbach 2020-10-24 11:56:30 +02:00
parent 7f24354c1d
commit 1230e5b9d8
2 changed files with 5 additions and 1 deletions

View file

@ -16,7 +16,7 @@ const matchSp = (uri) => {
const verify = (uri, fingerprint, opts) => {
if (!validUrl.isUri(uri)) {
throw new Error('The provided URI was not valid')
throw new Error('Not a valid URI')
}
const spMatches = matchSp(uri)

View file

@ -37,6 +37,10 @@ describe('verify', () => {
expect(doipjs.verify).to.be.a('function')
expect(doipjs.verify).to.have.length(3)
})
it('should throw an error for non-valid URIs', () => {
expect(() => { doipjs.verify('noURI') }).to.throw('Not a valid URI')
expect(() => { doipjs.verify('domain.org') }).to.throw('Not a valid URI')
})
it('should match "dns:domain.org" to the DNS service provider', () => {
const matches = doipjs.verify('dns:domain.org', null, {returnMatchesOnly: true})
expect(matches).to.be.a('array')