mirror of
https://github.com/mtan93/homebridge.git
synced 2026-05-22 14:18:52 +01:00
Add test for valid username
Like a MAC address, a valid username can only contain 6 pairs of hexadecimal characters, and for homebridge purposes must be colon-separated. This adds a simple regex test for a proper username, since I just spent nearly 24h trying to debug an issue that all came down to not realizing that a MAC address could only have letters A-F (see https://github.com/nfarina/homebridge/issues/385).
This commit is contained in:
@@ -124,6 +124,15 @@ Server.prototype._loadConfig = function() {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var accessoryCount = (config.accessories && config.accessories.length) || 0;
|
||||||
|
|
||||||
|
var username = config.bridge.username;
|
||||||
|
var validMac = /^([0-9A-F]{2}:){5}([0-9A-F]{2})$/;
|
||||||
|
if (!validMac.test(username)){
|
||||||
|
throw new Error('Not a valid username: ' + username + '. Must be 6 pairs of colon-' +
|
||||||
|
'separated hexadecimal chars (A-F 0-9), like a MAC address.');
|
||||||
|
}
|
||||||
|
|
||||||
var accessoryCount = (config.accessories && config.accessories.length) || 0;
|
var accessoryCount = (config.accessories && config.accessories.length) || 0;
|
||||||
var platformCount = (config.platforms && config.platforms.length) || 0;
|
var platformCount = (config.platforms && config.platforms.length) || 0;
|
||||||
log.info("Loaded config.json with %s accessories and %s platforms.", accessoryCount, platformCount);
|
log.info("Loaded config.json with %s accessories and %s platforms.", accessoryCount, platformCount);
|
||||||
|
|||||||
Reference in New Issue
Block a user