Fix failing tests

This commit is contained in:
Girish Ramakrishnan
2021-04-30 09:44:25 -07:00
parent 549b2f2a6b
commit 44027f61e6
3 changed files with 14 additions and 9 deletions
+6 -4
View File
@@ -537,11 +537,13 @@ function checkLoginLocation(user, ip, userAgent) {
debug(`checkLoginLocation: ${user.id} ${ip} ${userAgent}`);
superagent.get('https://geolocation.cloudron.io/json').query({ ip: ip }).end(function (error, result) {
superagent.get('https://geolocation.cloudron.io/json').query({ ip }).end(function (error, result) {
if (error) return console.error('Failed to get geoip info:', error);
const country = result.body.country.names.en;
const city = result.body.city.names.en;
const country = safe.query(result.body, 'country.names.en', '');
const city = safe.query(result.body, 'city.names.en', '');
if (!city || !country) return;
const knownLogin = user.locations.find(function (l) {
return l.userAgent === userAgent && l.country === country && l.city === city;
@@ -551,7 +553,7 @@ function checkLoginLocation(user, ip, userAgent) {
// purge potentially old locations where ts > now() - 6 months
const sixMonthsBack = Date.now() - 6 * 30 * 24 * 60 * 60 * 1000;
var locations = user.locations.filter(function (l) { return l.ts > sixMonthsBack; });
let locations = user.locations.filter(function (l) { return l.ts > sixMonthsBack; });
locations.push({ ts: Date.now(), ip, userAgent, country, city });
userdb.update(user.id, { locations }, function (error) {