1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-24 16:49:26 +01:00

Use 2fa.directory API v3 in inactive 2FA report (#1103)

* Use 2fa.directory API v3 in inactive 2FA report

* Fix issues

* Fix lint error

* Apply suggestions from code review

* Apply style suggestions

* Style fixes
This commit is contained in:
Arun Pattni 2021-11-24 15:25:01 +00:00 committed by GitHub
parent f8c943c042
commit cbf65c5f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,13 +59,13 @@ export class InactiveTwoFactorReportComponent extends CipherReportComponent impl
for (let i = 0; i < c.login.uris.length; i++) { for (let i = 0; i < c.login.uris.length; i++) {
const u = c.login.uris[i]; const u = c.login.uris[i];
if (u.uri != null && u.uri !== '') { if (u.uri != null && u.uri !== '') {
const hostname = Utils.getHostname(u.uri); const uri = u.uri.replace('www.', '');
if (hostname != null && this.services.has(hostname)) { const domain = Utils.getDomain(uri);
if (this.services.get(hostname) != null) { if (domain != null && this.services.has(domain)) {
docs.set(c.id, this.services.get(hostname)); if (this.services.get(domain) != null) {
docs.set(c.id, this.services.get(domain));
} }
inactive2faCiphers.push(c); inactive2faCiphers.push(c);
break;
} }
} }
} }
@ -84,26 +84,25 @@ export class InactiveTwoFactorReportComponent extends CipherReportComponent impl
if (this.services.size > 0) { if (this.services.size > 0) {
return; return;
} }
const response = await fetch(new Request('https://2fa.directory/api/v2/totp.json')); const response = await fetch(new Request('https://2fa.directory/api/v3/totp.json'));
if (response.status !== 200) { if (response.status !== 200) {
throw new Error(); throw new Error();
} }
const responseJson = await response.json(); const responseJson = await response.json();
for (const categoryName in responseJson) { for (const service of responseJson) {
if (responseJson.hasOwnProperty(categoryName)) { const serviceData = service[1];
const category = responseJson[categoryName]; if (serviceData.domain == null) {
for (const serviceName in category) { continue;
if (category.hasOwnProperty(serviceName)) { }
const service = category[serviceName]; if (serviceData.documentation == null) {
if (service.url != null) { continue;
const hostname = Utils.getHostname(service.url); }
if (hostname != null) { if (serviceData['additional-domains'] != null) {
this.services.set(hostname, service.doc); for (const additionalDomain of serviceData['additional-domains']) {
} this.services.set(additionalDomain, serviceData.documentation);
}
}
} }
} }
this.services.set(serviceData.domain, serviceData.documentation);
} }
} }
} }