upd: finish url_gen function

This commit is contained in:
lancegin 2017-07-10 12:18:10 +08:00
parent cf1ee2b8f0
commit 62c23f4208
5 changed files with 54 additions and 0 deletions

View File

@ -56,4 +56,17 @@ export class HOTP extends OTP {
return false;
}
}
/*
* Generate a url with HOTP instance.
*
* @param {issuer}
* @type {String}
* @desc maybe it is the Service name
*
* @return {String}
*/
url_gen(issuer="") {
return super.url_gen(issuer, "hotp");
}
}

View File

@ -77,5 +77,21 @@ export class OTP {
return str_code;
}
/*
* Generate a url with TOTP or HOTP instance.
*
* @param {issuer}
* @type {String}
* @desc maybe it is the Service name
*
* @param {type}
* @type {String}
* @desc type of OTP instance
*
* @return {String}
*/
url_gen(issuer, type) {
return `otpauth://${type}/SK?secret=${this.secret}&issuer=${issuer}`;
}
}

View File

@ -81,4 +81,17 @@ export class TOTP extends OTP {
return false;
}
}
/*
* Generate a url with TOTP instance.
*
* @param {issuer}
* @type {String}
* @desc maybe it is the Service name
*
* @return {String}
*/
url_gen(issuer="") {
return super.url_gen(issuer, "totp");
}
}

View File

@ -17,5 +17,11 @@ describe('HOTP module test', function() {
assert.equal(true, a.verify(a.at(0), 0));
assert.equal(false, a.verify(a.at(0), 1));
})
});
describe('url_gen() function', function() {
it("should return string", function() {
assert.equal("string", typeof(a.url_gen()));
})
})
});

View File

@ -16,5 +16,11 @@ describe('TOTP module test', function() {
it("should verify the digit", function() {
assert.equal(true, a.verify(a.now()));
})
});
describe('url_gen() function', function() {
it("should return string", function() {
assert.equal("string", typeof(a.url_gen()));
})
})
});