debian-mirror-gitlab/spec/frontend/authentication/webauthn/mock_webauthn_device.js
2020-11-24 15:15:51 +05:30

35 lines
1.1 KiB
JavaScript

/* eslint-disable no-unused-expressions */
export default class MockWebAuthnDevice {
constructor() {
this.respondToAuthenticateRequest = this.respondToAuthenticateRequest.bind(this);
this.respondToRegisterRequest = this.respondToRegisterRequest.bind(this);
window.navigator.credentials || (window.navigator.credentials = {});
window.navigator.credentials.create = () =>
new Promise((resolve, reject) => {
this.registerCallback = resolve;
this.registerRejectCallback = reject;
});
window.navigator.credentials.get = () =>
new Promise((resolve, reject) => {
this.authenticateCallback = resolve;
this.authenticateRejectCallback = reject;
});
}
respondToRegisterRequest(params) {
return this.registerCallback(params);
}
respondToAuthenticateRequest(params) {
return this.authenticateCallback(params);
}
rejectRegisterRequest(params) {
return this.registerRejectCallback(params);
}
rejectAuthenticateRequest(params) {
return this.authenticateRejectCallback(params);
}
}