Commit dd18727d authored by Robert Knight's avatar Robert Knight

Rename random.{hexString => generateHexString}

Respond to CR feedback in
https://github.com/hypothesis/client/pull/476#discussion_r126539329
parent b14047de
...@@ -177,7 +177,7 @@ function auth($http, $window, flash, random, settings) { ...@@ -177,7 +177,7 @@ function auth($http, $window, flash, random, settings) {
function login() { function login() {
// Random state string used to check that auth messages came from the popup // Random state string used to check that auth messages came from the popup
// window that we opened. // window that we opened.
var state = random.hexString(16); var state = random.generateHexString(16);
// Promise which resolves or rejects when the user accepts or closes the // Promise which resolves or rejects when the user accepts or closes the
// auth popup. // auth popup.
......
...@@ -76,7 +76,7 @@ describe('sidebar.oauth-auth', function () { ...@@ -76,7 +76,7 @@ describe('sidebar.oauth-auth', function () {
}; };
fakeRandom = { fakeRandom = {
hexString: sinon.stub().returns('notrandom'), generateHexString: sinon.stub().returns('notrandom'),
}; };
fakeSettings = { fakeSettings = {
......
...@@ -13,12 +13,12 @@ function byteToHex(val) { ...@@ -13,12 +13,12 @@ function byteToHex(val) {
* @param {number} - An even-numbered length string to generate. * @param {number} - An even-numbered length string to generate.
* @return {string} * @return {string}
*/ */
function hexString(len) { function generateHexString(len) {
var bytes = new Uint8Array(len / 2); var bytes = new Uint8Array(len / 2);
crypto.getRandomValues(bytes); crypto.getRandomValues(bytes);
return Array.from(bytes).map(byteToHex).join(''); return Array.from(bytes).map(byteToHex).join('');
} }
module.exports = { module.exports = {
hexString, generateHexString,
}; };
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
var random = require('../random'); var random = require('../random');
describe('sidebar.util.random', () => { describe('sidebar.util.random', () => {
describe('#hexString', () => { describe('#generateHexString', () => {
[2,4,8,16].forEach((len) => { [2,4,8,16].forEach((len) => {
it(`returns a ${len} digit hex string`, () => { it(`returns a ${len} digit hex string`, () => {
var re = new RegExp(`^[0-9a-fA-F]{${len}}$`); var re = new RegExp(`^[0-9a-fA-F]{${len}}$`);
var str = random.hexString(len); var str = random.generateHexString(len);
assert.isTrue(re.test(str)); assert.isTrue(re.test(str));
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment