From 55b5c736225b1f9bcbefd811748e8691fa7cde1c Mon Sep 17 00:00:00 2001 From: Tom J Date: Tue, 28 Sep 2021 10:23:25 +0000 Subject: [PATCH 1/2] issue 3751 use client-configuration endpoint on FES --- extension/js/common/api/account-server.ts | 13 ++++++++++++- .../common/api/account-servers/enterprise-server.ts | 10 ++++++---- .../common/api/account-servers/flowcrypt-com-api.ts | 2 +- test/source/mock/fes/fes-endpoints.ts | 12 +++++------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/extension/js/common/api/account-server.ts b/extension/js/common/api/account-server.ts index be866a26be1..ecd6347e212 100644 --- a/extension/js/common/api/account-server.ts +++ b/extension/js/common/api/account-server.ts @@ -30,7 +30,18 @@ export class AccountServer extends Api { public accountGetAndUpdateLocalStore = async (fcAuth: FcUuidAuth): Promise => { if (await this.isFesUsed()) { const fes = new EnterpriseServer(this.acctEmail); - return await fes.getAccountAndUpdateLocalStore(); + const fetchedOrgRules = await fes.fetchAndSaveOrgRules(); + return { + domain_org_rules: fetchedOrgRules, + // the subscription and default_message_expire below is a refactor relic + // (used to come from a deprecated FES API that was authenticated) + // todo - remove this - issue #4012 + subscription: { level: 'pro', expired: false }, + // todo - rethink this. On FES, expiration is handled with S3 bucket policy regardless of this number + // which is set to 180 days on buckets we manage. This number below may still be rendered somewhere + // when composing, which should be evaluated. + account: { default_message_expire: 180 } + }; } else { return await FlowCryptComApi.accountGetAndUpdateLocalStore(fcAuth); } diff --git a/extension/js/common/api/account-servers/enterprise-server.ts b/extension/js/common/api/account-servers/enterprise-server.ts index a3e06360bb3..f01573798a0 100644 --- a/extension/js/common/api/account-servers/enterprise-server.ts +++ b/extension/js/common/api/account-servers/enterprise-server.ts @@ -15,6 +15,7 @@ import { FLAVOR } from '../../core/const.js'; import { Attachment } from '../../core/attachment.js'; import { Recipients } from '../email-provider/email-provider-api.js'; import { Buf } from '../../core/buf.js'; +import { DomainRulesJson } from '../../org-rules.js'; // todo - decide which tags to use type EventTag = 'compose' | 'decrypt' | 'setup' | 'settings' | 'import-pub' | 'import-prv'; @@ -24,6 +25,7 @@ export namespace FesRes { export type ReplyToken = { replyToken: string }; export type MessageUpload = { url: string }; export type ServiceInfo = { vendor: string, service: string, orgId: string, version: string, apiVersion: string } + export type ClientConfiguration = { clientConfiguration: DomainRulesJson }; } /** @@ -87,10 +89,10 @@ export class EnterpriseServer extends Api { await AcctStore.set(this.acctEmail, { fesAccessToken: response.accessToken }); } - public getAccountAndUpdateLocalStore = async (): Promise => { - const r = await this.request('GET', `/api/${this.apiVersion}/account/`, await this.authHdr()); - await AcctStore.set(this.acctEmail, { rules: r.domain_org_rules }); - return r; + public fetchAndSaveOrgRules = async (): Promise => { + const r = await this.request('GET', `/api/${this.apiVersion}/client-configuration?domain=${this.domain}`); + await AcctStore.set(this.acctEmail, { rules: r.clientConfiguration }); + return r.clientConfiguration; } public reportException = async (errorReport: ErrorReport): Promise => { diff --git a/extension/js/common/api/account-servers/flowcrypt-com-api.ts b/extension/js/common/api/account-servers/flowcrypt-com-api.ts index e5038e7ecc1..bb1839da8d9 100644 --- a/extension/js/common/api/account-servers/flowcrypt-com-api.ts +++ b/extension/js/common/api/account-servers/flowcrypt-com-api.ts @@ -20,7 +20,7 @@ export type SubscriptionInfo = { level?: SubscriptionLevel; expired?: boolean }; export namespace BackendRes { export type FcAccountLogin = { registered: boolean, verified: boolean }; - export type FcAccount$info = { alias: string, email: string, intro: string, name: string, photo: string, default_message_expire: number }; + export type FcAccount$info = { alias?: string | null, default_message_expire: number }; export type FcAccountGet = { account: FcAccount$info, subscription: SubscriptionInfo, domain_org_rules: DomainRulesJson }; export type FcAccountUpdate = { result: FcAccount$info, updated: boolean }; export type FcAccountSubscribe = { subscription: SubscriptionInfo }; diff --git a/test/source/mock/fes/fes-endpoints.ts b/test/source/mock/fes/fes-endpoints.ts index 7b15e2c76c3..17ca128c9e6 100644 --- a/test/source/mock/fes/fes-endpoints.ts +++ b/test/source/mock/fes/fes-endpoints.ts @@ -43,15 +43,13 @@ export const mockFesEndpoints: HandlersDefinition = { } throw new HttpClientErr('Not Found', 404); }, - '/api/v1/account/': async ({ }, req) => { + '/api/v1/client-configuration': async ({ }, req) => { + // ?domain=fes.localhost:8001 + // ?domain=fes.standardsubdomainfes.test:8001 + // ?domain=fes.google.mock.flowcryptlocal.test:8001 if (req.headers.host === standardFesUrl && req.method === 'GET') { - authenticate(req, 'fes'); return { - account: { - default_message_expire: 30 - }, - subscription: { level: 'pro', expire: null, method: 'group', expired: 'false' }, // tslint:disable-line:no-null-keyword - domain_org_rules: { disallow_attester_search_for_domains: ['got.this@fromstandardfes.com'] }, + clientConfiguration: { disallow_attester_search_for_domains: ['got.this@fromstandardfes.com'] }, }; } throw new HttpClientErr('Not Found', 404); From 0d751a3fd69700e97bbcea4aba98a901e373a7a6 Mon Sep 17 00:00:00 2001 From: Tom J Date: Tue, 28 Sep 2021 11:21:38 +0000 Subject: [PATCH 2/2] additional check in mock --- test/source/mock/fes/fes-endpoints.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/source/mock/fes/fes-endpoints.ts b/test/source/mock/fes/fes-endpoints.ts index 17ca128c9e6..92b3e8e0c02 100644 --- a/test/source/mock/fes/fes-endpoints.ts +++ b/test/source/mock/fes/fes-endpoints.ts @@ -44,9 +44,11 @@ export const mockFesEndpoints: HandlersDefinition = { throw new HttpClientErr('Not Found', 404); }, '/api/v1/client-configuration': async ({ }, req) => { - // ?domain=fes.localhost:8001 - // ?domain=fes.standardsubdomainfes.test:8001 - // ?domain=fes.google.mock.flowcryptlocal.test:8001 + // actual individual OrgRules are tested using FlowCrypt backend mock instead, + // see BackendData.getOrgRules + if (req.url !== '/api/v1/client-configuration?domain=standardsubdomainfes.test:8001') { + throw new HttpClientErr('Unexpected domain, expecting standardsubdomainfes.test:8001', 400); + } if (req.headers.host === standardFesUrl && req.method === 'GET') { return { clientConfiguration: { disallow_attester_search_for_domains: ['got.this@fromstandardfes.com'] },