Initial testing of configurable scheme code with mocks

This commit is contained in:
Preston Maness 2023-07-04 00:06:33 -05:00
parent ba9ae78d7d
commit f5ef4b6623
3 changed files with 69 additions and 0 deletions

View file

@ -30,6 +30,7 @@
"chai": "^4.3.6",
"copy-webpack-plugin": "^10.2.4",
"css-loader": "^6.6.0",
"esmock": "^2.3.1",
"license-check-and-add": "^4.0.5",
"mini-css-extract-plugin": "^2.5.3",
"mocha": "^10.1.0",

View file

@ -1,6 +1,10 @@
import 'chai/register-should.js'
import esmock from 'esmock'
import * as utils from '../src/server/utils.js'
const _env = Object.assign({},process.env)
describe('server', function () {
describe('utils', function () {
describe('computeWKDLocalPart()', function () {
@ -26,4 +30,63 @@ describe('server', function () {
})
})
})
describe('index', function () {
// Brittle mocking :(
describe('generateHKPProfile', function() {
it('should handle implicit scheme with implicit keys.openpgp.org keyserver', async function () {
// Arrange
const fingerprint = '79895B2E0F87503F1DDE80B649765D7F0DDD9BD5'
// the process.env needs to be here, before the esmock setup.
process.env.DOMAIN = "keyoxide.org"
//process.env.SCHEME = "http"
const index = await esmock('../src/server/index.js', {
'../src/server/keys.js': {
fetchHKP: () => {
return Promise.resolve({
publicKey: {
getPrimaryUser: () => {
return {
user: {
userID: {
email: "example@example.org"
}
}
}
}
},
fetchURL: 'example.com'
})
}
},
'doipjs': {
keys: {
process: () => {
return {
key: {},
'fingerprint': fingerprint,
users: []
}
}
}
},
'libravatar': {
get_avatar_url: () => {
return "example.org/avatar.png"
}
}
})
// Act
const local = await index.generateHKPProfile(fingerprint)
// Assert
local.keyoxide.url.should.equal(`https://keyoxide.org/hkp/${fingerprint}`)
})
})
})
})

View file

@ -2204,6 +2204,11 @@ eslint@^8.13.0:
strip-json-comments "^3.1.0"
text-table "^0.2.0"
esmock@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/esmock/-/esmock-2.3.1.tgz#27a3afea73d7fb352f27c7ac04f66cfbd2c34316"
integrity sha512-ZxuxfhwGSlStiJFbw6Z+a70fB6SutTcUr0X8dhehx6aqiC5kgBvEYV4xNW94cKaD8gaqD7P00RjBH/pfao2CQA==
espree@^9.4.0:
version "9.4.1"
resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.1.tgz#51d6092615567a2c2cff7833445e37c28c0065bd"