forked from Mirrors/keyoxide-web
Initial testing of configurable scheme code with mocks
This commit is contained in:
parent
ba9ae78d7d
commit
f5ef4b6623
3 changed files with 69 additions and 0 deletions
|
@ -30,6 +30,7 @@
|
||||||
"chai": "^4.3.6",
|
"chai": "^4.3.6",
|
||||||
"copy-webpack-plugin": "^10.2.4",
|
"copy-webpack-plugin": "^10.2.4",
|
||||||
"css-loader": "^6.6.0",
|
"css-loader": "^6.6.0",
|
||||||
|
"esmock": "^2.3.1",
|
||||||
"license-check-and-add": "^4.0.5",
|
"license-check-and-add": "^4.0.5",
|
||||||
"mini-css-extract-plugin": "^2.5.3",
|
"mini-css-extract-plugin": "^2.5.3",
|
||||||
"mocha": "^10.1.0",
|
"mocha": "^10.1.0",
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import 'chai/register-should.js'
|
import 'chai/register-should.js'
|
||||||
|
import esmock from 'esmock'
|
||||||
|
|
||||||
import * as utils from '../src/server/utils.js'
|
import * as utils from '../src/server/utils.js'
|
||||||
|
|
||||||
|
const _env = Object.assign({},process.env)
|
||||||
|
|
||||||
describe('server', function () {
|
describe('server', function () {
|
||||||
describe('utils', function () {
|
describe('utils', function () {
|
||||||
describe('computeWKDLocalPart()', 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}`)
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
|
@ -2204,6 +2204,11 @@ eslint@^8.13.0:
|
||||||
strip-json-comments "^3.1.0"
|
strip-json-comments "^3.1.0"
|
||||||
text-table "^0.2.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:
|
espree@^9.4.0:
|
||||||
version "9.4.1"
|
version "9.4.1"
|
||||||
resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.1.tgz#51d6092615567a2c2cff7833445e37c28c0065bd"
|
resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.1.tgz#51d6092615567a2c2cff7833445e37c28c0065bd"
|
||||||
|
|
Loading…
Reference in a new issue