2020-10-24 16:45:07 -06:00
|
|
|
/*
|
2021-01-13 05:20:33 -07:00
|
|
|
Copyright 2021 Yarmo Mackenbach
|
2020-10-24 16:45:07 -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
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2023-07-08 00:17:13 -06:00
|
|
|
import { expect } from 'chai'
|
2020-10-24 16:45:07 -06:00
|
|
|
|
2023-07-08 00:17:13 -06:00
|
|
|
import { utils, enums } from '../src/index.js'
|
2020-10-24 16:45:07 -06:00
|
|
|
|
2022-09-10 04:14:05 -06:00
|
|
|
const textWithUrls = `This is text with URLs like https://domain.tld. Ow, a trailing dot.
|
|
|
|
What about (https://between.parentheses)? What about [https://between.brackets]?
|
|
|
|
What about https://in.question? What about https://in.exclamation!
|
|
|
|
And openpgp4fpr:123123, nonsense:123123`
|
|
|
|
const urlsFromText = ["https://domain.tld", "https://between.parentheses",
|
|
|
|
"https://between.brackets", "https://in.question", "https://in.exclamation",
|
|
|
|
"openpgp4fpr:123123", "nonsense:123123"]
|
|
|
|
|
2020-10-24 16:45:07 -06:00
|
|
|
describe('utils.generateClaim', () => {
|
|
|
|
it('should be a function (2 arguments)', () => {
|
2023-07-08 00:17:13 -06:00
|
|
|
expect(utils.generateClaim).to.be.a('function')
|
|
|
|
expect(utils.generateClaim).to.have.length(2)
|
2020-10-24 16:45:07 -06:00
|
|
|
})
|
|
|
|
it('should generate a correct "uri" claim', () => {
|
2021-04-19 05:38:09 -06:00
|
|
|
expect(
|
2023-07-08 00:17:13 -06:00
|
|
|
utils.generateClaim('123456789', enums.ClaimFormat.URI)
|
2021-04-19 05:38:09 -06:00
|
|
|
).to.equal('openpgp4fpr:123456789')
|
2020-10-24 16:45:07 -06:00
|
|
|
})
|
|
|
|
it('should generate a correct "fingerprint" claim', () => {
|
2021-04-19 05:38:09 -06:00
|
|
|
expect(
|
2023-07-08 00:17:13 -06:00
|
|
|
utils.generateClaim(
|
2021-04-19 05:38:09 -06:00
|
|
|
'123456789',
|
2023-07-08 00:17:13 -06:00
|
|
|
enums.ClaimFormat.FINGERPRINT
|
2021-04-19 05:38:09 -06:00
|
|
|
)
|
|
|
|
).to.equal('123456789')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('utils.generateProxyURL', () => {
|
|
|
|
it('should be a function (3 arguments)', () => {
|
2023-07-08 00:17:13 -06:00
|
|
|
expect(utils.generateProxyURL).to.be.a('function')
|
|
|
|
expect(utils.generateProxyURL).to.have.length(3)
|
2021-04-19 05:38:09 -06:00
|
|
|
})
|
2023-06-11 23:19:56 -06:00
|
|
|
it('should generate correct proxy URLs for explicit https scheme', () => {
|
2021-04-19 05:38:09 -06:00
|
|
|
const opts = {
|
|
|
|
proxy: {
|
|
|
|
hostname: 'localhost',
|
2023-06-11 22:59:06 -06:00
|
|
|
scheme: 'https'
|
2021-04-19 05:38:09 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
expect(
|
2023-07-08 00:17:13 -06:00
|
|
|
utils.generateProxyURL('http', { domain: 'domain.org' }, opts)
|
2021-06-03 01:51:43 -06:00
|
|
|
).to.equal('https://localhost/api/2/get/http?domain=domain.org')
|
2021-04-19 05:38:09 -06:00
|
|
|
expect(
|
2023-07-08 00:17:13 -06:00
|
|
|
utils.generateProxyURL('dns', { domain: 'domain.org' }, opts)
|
2021-06-03 01:51:43 -06:00
|
|
|
).to.equal('https://localhost/api/2/get/dns?domain=domain.org')
|
2020-10-24 16:45:07 -06:00
|
|
|
})
|
2023-06-11 23:19:56 -06:00
|
|
|
it('should generate correct proxy URLs for explicit http scheme', () => {
|
|
|
|
const opts = {
|
|
|
|
proxy: {
|
|
|
|
hostname: 'localhost',
|
|
|
|
scheme: 'http'
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expect(
|
2023-07-08 00:17:13 -06:00
|
|
|
utils.generateProxyURL('http', { domain: 'domain.org' }, opts)
|
2023-06-11 23:19:56 -06:00
|
|
|
).to.equal('http://localhost/api/2/get/http?domain=domain.org')
|
|
|
|
expect(
|
2023-07-08 00:17:13 -06:00
|
|
|
utils.generateProxyURL('dns', { domain: 'domain.org' }, opts)
|
2023-06-11 23:19:56 -06:00
|
|
|
).to.equal('http://localhost/api/2/get/dns?domain=domain.org')
|
|
|
|
})
|
|
|
|
it('should generate correct proxy URLs for default scheme', () => {
|
|
|
|
const opts = {
|
|
|
|
proxy: {
|
|
|
|
hostname: 'localhost'
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expect(
|
2023-07-08 00:17:13 -06:00
|
|
|
utils.generateProxyURL('http', { domain: 'domain.org' }, opts)
|
2023-06-11 23:19:56 -06:00
|
|
|
).to.equal('https://localhost/api/2/get/http?domain=domain.org')
|
|
|
|
expect(
|
2023-07-08 00:17:13 -06:00
|
|
|
utils.generateProxyURL('dns', { domain: 'domain.org' }, opts)
|
2023-06-11 23:19:56 -06:00
|
|
|
).to.equal('https://localhost/api/2/get/dns?domain=domain.org')
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-10-24 16:45:07 -06:00
|
|
|
})
|
2022-09-10 04:14:05 -06:00
|
|
|
|
|
|
|
describe('utils.getUriFromString', () => {
|
|
|
|
it('should be a function (1 arguments)', () => {
|
2023-07-08 00:17:13 -06:00
|
|
|
expect(utils.getUriFromString).to.be.a('function')
|
|
|
|
expect(utils.getUriFromString).to.have.length(1)
|
2022-09-10 04:14:05 -06:00
|
|
|
})
|
|
|
|
it('should extract URLs from text', () => {
|
|
|
|
expect(
|
2023-07-08 00:17:13 -06:00
|
|
|
utils.getUriFromString(textWithUrls)
|
2022-09-10 04:14:05 -06:00
|
|
|
).to.have.length(urlsFromText.length)
|
|
|
|
})
|
|
|
|
// TODO Properly check each URL
|
|
|
|
})
|