Skip to content

Commit

Permalink
[JS] Fix: making methods static (#11182)
Browse files Browse the repository at this point in the history
  • Loading branch information
TamsilAmani authored Nov 1, 2022
1 parent 3bdde2a commit 472eebb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
10 changes: 10 additions & 0 deletions javascript/node/selenium-webdriver/lib/virtual_authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,34 @@ class Credential {
* @param userHandle userHandle associated to the credential. Must be Base64 encoded string.
* @param privateKey Base64 encoded PKCS
* @param signCount initial value for a signature counter.
* @deprecated This method has been made static. Call it with class name. Example, Credential.createResidentCredential()
* @returns A resident credential
*/
createResidentCredential(id, rpId, userHandle, privateKey, signCount) {
return new Credential(id, true, rpId, userHandle, privateKey, signCount)
}

static createResidentCredential(id, rpId, userHandle, privateKey, signCount) {
return new Credential(id, true, rpId, userHandle, privateKey, signCount)
}

/**
* Creates a non-resident (i.e. stateless) credential.
* @param id Unique base64 encoded string.
* @param rpId Relying party identifier.
* @param privateKey Base64 encoded PKCS
* @param signCount initial value for a signature counter.
* @deprecated This method has been made static. Call it with class name. Example, Credential.createNonResidentCredential()
* @returns A non-resident credential
*/
createNonResidentCredential(id, rpId, privateKey, signCount) {
return new Credential(id, false, rpId, null, privateKey, signCount)
}

static createNonResidentCredential(id, rpId, privateKey, signCount) {
return new Credential(id, false, rpId, null, privateKey, signCount)
}

toDict() {
let credentialData = {
credentialId: Buffer.from(this._id).toString('base64url'),
Expand Down
32 changes: 15 additions & 17 deletions javascript/node/selenium-webdriver/test/lib/credentials_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ describe('Credentials', function () {

it('can testRkEnabledCredential', function () {
const { _id, rpId, userHandle, privateKey, signCount } = data
const credential =
new virtualAuthenticatorCredential().createResidentCredential(
_id,
rpId,
userHandle,
privateKey,
signCount
)
const credential = virtualAuthenticatorCredential.createResidentCredential(
_id,
rpId,
userHandle,
privateKey,
signCount
)

let testCredentialId = new Uint8Array([1, 2, 3, 4])

Expand Down Expand Up @@ -105,7 +104,7 @@ describe('Credentials', function () {
it('can testRkDisabledCredential', function () {
const { _id, rpId, privateKey, signCount } = data
const credential =
new virtualAuthenticatorCredential().createNonResidentCredential(
virtualAuthenticatorCredential.createNonResidentCredential(
_id,
rpId,
privateKey,
Expand Down Expand Up @@ -141,14 +140,13 @@ describe('Credentials', function () {

it('can testToDict', function () {
const { _id, rpId, userHandle, privateKey, signCount } = data
const credential =
new virtualAuthenticatorCredential().createResidentCredential(
_id,
rpId,
userHandle,
privateKey,
signCount
)
const credential = virtualAuthenticatorCredential.createResidentCredential(
_id,
rpId,
userHandle,
privateKey,
signCount
)

let credential_dict = credential.toDict()
assert.equal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ suite(function (env) {
*/
driver = await createRkDisabledCTAP2Authenticator(driver)
let credential =
new virtualAuthenticatorCredential().createNonResidentCredential(
virtualAuthenticatorCredential.createNonResidentCredential(
new Uint8Array([1, 2, 3, 4]),
'localhost',
Buffer.from(BASE64_ENCODED_PK, 'base64').toString('binary'),
Expand Down Expand Up @@ -223,7 +223,7 @@ suite(function (env) {
'RmgsJYxGP__fWN_S-j5sN4tT15XEpN_7QZnt14YvI6uvAgO0uJEboFaZlOEB'

let credential =
new virtualAuthenticatorCredential().createNonResidentCredential(
virtualAuthenticatorCredential.createNonResidentCredential(
new Uint8Array([1, 2, 3, 4]),
'localhost',
Buffer.from(base64EncodedPK, 'base64').toString('binary'),
Expand All @@ -248,7 +248,7 @@ suite(function (env) {
driver = await createRkEnabledCTAP2Authenticator(driver)

let credential =
new virtualAuthenticatorCredential().createResidentCredential(
virtualAuthenticatorCredential.createResidentCredential(
new Uint8Array([1, 2, 3, 4]),
'localhost',
new Uint8Array([1]),
Expand Down Expand Up @@ -286,7 +286,7 @@ suite(function (env) {
'RmgsJYxGP__fWN_S-j5sN4tT15XEpN_7QZnt14YvI6uvAgO0uJEboFaZlOEB'

let credential =
new virtualAuthenticatorCredential().createResidentCredential(
virtualAuthenticatorCredential.createResidentCredential(
new Uint8Array([1, 2, 3, 4]),
'localhost',
new Uint8Array([1]),
Expand Down

0 comments on commit 472eebb

Please sign in to comment.