Skip to content

Commit

Permalink
[js] Moving from static to const to make js-dossier happy
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Aug 11, 2022
1 parent f5f2887 commit b8ede33
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 39 deletions.
1 change: 1 addition & 0 deletions javascript/node/gendocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function getModules() {
path.join(__dirname, 'selenium-webdriver/lib/safari'),
path.join(__dirname, 'selenium-webdriver/lib/test'),
path.join(__dirname, 'selenium-webdriver/lib/tools'),
path.join(__dirname, 'selenium-webdriver/devtools/generator'),
path.join(__dirname, 'selenium-webdriver/node_modules'),
path.join(__dirname, 'selenium-webdriver/test')
];
Expand Down
53 changes: 30 additions & 23 deletions javascript/node/selenium-webdriver/lib/virtual_authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,38 @@

'use strict'

/**
* Protocol for virtual authenticators
* @enum {string}
*/
const Protocol = {
'CTAP2': 'ctap2',
'U2F': 'ctap1/u2f',
}

/**
* AuthenticatorTransport values
* @enum {string}
*/
const Transport = {
'BLE': 'ble',
'USB': 'usb',
'NFC': 'nfc',
'INTERNAL': 'internal',
}

/**
* Options for the creation of virtual authenticators.
* @see http://w3c.github.io/webauthn/#sctn-automation
*/
class VirtualAuthenticatorOptions {

static Protocol = {
"CTAP2": 'ctap2',
"U2F": 'ctap1/u2f',
}

static Transport = {
"BLE": 'ble',
"USB": 'usb',
"NFC": 'nfc',
"INTERNAL": 'internal',
}

/**
* Constructor to initialise VirtualAuthenticatorOptions object.
*/
constructor() {
this._protocol = VirtualAuthenticatorOptions.Protocol["CTAP2"]
this._transport = VirtualAuthenticatorOptions.Transport["USB"]
this._protocol = Protocol['CTAP2']
this._transport = Transport['USB']
this._hasResidentKey = false
this._hasUserVerification = false
this._isUserConsenting = true
Expand Down Expand Up @@ -102,8 +110,7 @@ class VirtualAuthenticatorOptions {
"hasResidentKey": this.getHasResidentKey(),
"hasUserVerification": this.getHasUserVerification(),
"isUserConsenting": this.getIsUserConsenting(),
"isUserVerified": this.getIsUserVerified(),

'isUserVerified': this.getIsUserVerified()
}
}
}
Expand All @@ -113,14 +120,13 @@ class VirtualAuthenticatorOptions {
* @see https://w3c.github.io/webauthn/#credential-parameters
*/
class Credential {
constructor(
constructor (
credentialId,
isResidentCredential,
rpId,
userHandle,
privateKey,
signCount
) {
signCount) {
this._id = credentialId
this._isResidentCredential = isResidentCredential
this._rpId = rpId
Expand Down Expand Up @@ -224,7 +230,8 @@ class Credential {
}
}

module.exports = {
Credential,
VirtualAuthenticatorOptions,
}
module.exports.Credential = Credential
module.exports.VirtualAuthenticatorOptions = VirtualAuthenticatorOptions
module.exports.Transport = Transport
module.exports.Protocol = Protocol

2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ class WebDriver {

/**
* Adds a virtual authenticator with the given options.
* @param options VirtualAuthenticatorOptions object to set authenticator optons.
* @param options VirtualAuthenticatorOptions object to set authenticator options.
*/
async addVirtualAuthenticator(options) {
this.authenticatorId_ = await this.execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
const assert = require('assert')
const virtualAuthenticatorOptions =
require('../../lib/virtual_authenticator').VirtualAuthenticatorOptions
const Transport = require('../../lib/virtual_authenticator').Transport
const Protocol = require('../../lib/virtual_authenticator').Protocol

let options

Expand All @@ -29,34 +31,34 @@ describe('VirtualAuthenticatorOptions', function () {
})

it('can testSetTransport', function () {
options.setTransport(virtualAuthenticatorOptions.Transport['USB'])
options.setTransport(Transport['USB'])
assert.equal(
options.getTransport(),
virtualAuthenticatorOptions.Transport['USB']
Transport['USB']
)
})

it('can testGetTransport', function () {
options._transport = virtualAuthenticatorOptions.Transport['NFC']
options._transport = Transport['NFC']
assert.equal(
options.getTransport(),
virtualAuthenticatorOptions.Transport['NFC']
Transport['NFC']
)
})

it('can testSetProtocol', function () {
options.setProtocol(virtualAuthenticatorOptions.Protocol['U2F'])
options.setProtocol(Protocol['U2F'])
assert.equal(
options.getProtocol(),
virtualAuthenticatorOptions.Protocol['U2F']
Protocol['U2F']
)
})

it('can testGetProtocol', function () {
options._protocol = virtualAuthenticatorOptions.Protocol['CTAP2']
options._protocol = Protocol['CTAP2']
assert.equal(
options.getProtocol(),
virtualAuthenticatorOptions.Protocol['CTAP2']
Protocol['CTAP2']
)
})

Expand Down Expand Up @@ -104,11 +106,11 @@ describe('VirtualAuthenticatorOptions', function () {
let default_options = options.toDict()
assert.equal(
default_options['transport'],
virtualAuthenticatorOptions.Transport['USB']
Transport['USB']
)
assert.equal(
default_options['protocol'],
virtualAuthenticatorOptions.Protocol['CTAP2']
Protocol['CTAP2']
)
assert.equal(default_options['hasResidentKey'], false)
assert.equal(default_options['hasUserVerification'], false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const virtualAuthenticatorCredential =
require('../lib/virtual_authenticator').Credential
const virtualAuthenticatorOptions =
require('../lib/virtual_authenticator').VirtualAuthenticatorOptions
const Protocol = require('../lib/virtual_authenticator').Protocol
const { ignore, suite } = require('../lib/test')
const { Browser } = require('../lib/capabilities')
const fileServer = require('../lib/test/fileserver')
Expand All @@ -37,7 +38,7 @@ const GET_CREDENTIAL = `getCredential([{
async function createRkEnabledU2fAuthenticator(driver) {
let options
options = new virtualAuthenticatorOptions()
options.setProtocol(virtualAuthenticatorOptions.Protocol['U2F'])
options.setProtocol(Protocol['U2F'])
options.setHasResidentKey(true)
await driver.addVirtualAuthenticator(options)
return driver
Expand All @@ -46,7 +47,7 @@ async function createRkEnabledU2fAuthenticator(driver) {
async function createRkDisabledU2fAuthenticator(driver) {
let options
options = new virtualAuthenticatorOptions()
options.setProtocol(virtualAuthenticatorOptions.Protocol['U2F'])
options.setProtocol(Protocol['U2F'])
options.setHasResidentKey(false)
await driver.addVirtualAuthenticator(options)
return driver
Expand All @@ -55,7 +56,7 @@ async function createRkDisabledU2fAuthenticator(driver) {
async function createRkEnabledCTAP2Authenticator(driver) {
let options
options = new virtualAuthenticatorOptions()
options.setProtocol(virtualAuthenticatorOptions.Protocol['CTAP2'])
options.setProtocol(Protocol['CTAP2'])
options.setHasResidentKey(true)
options.setHasUserVerification(true)
options.setIsUserVerified(true)
Expand All @@ -66,7 +67,7 @@ async function createRkEnabledCTAP2Authenticator(driver) {
async function createRkDisabledCTAP2Authenticator(driver) {
let options
options = new virtualAuthenticatorOptions()
options.setProtocol(virtualAuthenticatorOptions.Protocol['CTAP2'])
options.setProtocol(Protocol['CTAP2'])
options.setHasResidentKey(false)
options.setHasUserVerification(true)
options.setIsUserVerified(true)
Expand Down
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/testing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function warn(msg) {
* Extracts the browsers for a test suite to target from the `SELENIUM_BROWSER`
* environment variable.
*
* @return {{name: string, version: string, platform: string}[]} the browsers to target.
* @return {{name: string, version: string, platform: string}}[] the browsers to target.
*/
function getBrowsersToTestFromEnv() {
let browsers = process.env['SELENIUM_BROWSER']
Expand Down

0 comments on commit b8ede33

Please sign in to comment.