Skip to content

Commit

Permalink
fix(contacts): use webexapis.com url to avoid cors (#3834)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreenara authored Sep 14, 2024
1 parent 523ae6d commit 1de73b3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
11 changes: 8 additions & 3 deletions packages/calling/src/CallSettings/UcmBackendConnector.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import {LOGGER} from '../Logger/types';
import * as utils from '../common/Utils';
import {FAILURE_MESSAGE, SUCCESS_MESSAGE, UCM_CONNECTOR_FILE} from '../common/constants';
import {
FAILURE_MESSAGE,
SUCCESS_MESSAGE,
UCM_CONNECTOR_FILE,
WEBEX_API_CONFIG_INT_URL,
} from '../common/constants';
import {getTestUtilsWebex} from '../common/testUtil';
import {HTTP_METHODS, WebexRequestPayload} from '../common/types';
import {UcmBackendConnector} from './UcmBackendConnector';
import {CF_ENDPOINT, ORG_ENDPOINT, PEOPLE_ENDPOINT, WEBEX_APIS_INT_URL} from './constants';
import {CF_ENDPOINT, ORG_ENDPOINT, PEOPLE_ENDPOINT} from './constants';
import {CallForwardAlwaysSetting, CallForwardingSettingsUCM, IUcmBackendConnector} from './types';

describe('Call Settings Client Tests for UcmBackendConnector', () => {
Expand Down Expand Up @@ -44,7 +49,7 @@ describe('Call Settings Client Tests for UcmBackendConnector', () => {
},
};

const callForwardingUri = `${WEBEX_APIS_INT_URL}/${PEOPLE_ENDPOINT}/${userId}/${CF_ENDPOINT.toLowerCase()}?${ORG_ENDPOINT}=${orgId}`;
const callForwardingUri = `${WEBEX_API_CONFIG_INT_URL}/${PEOPLE_ENDPOINT}/${userId}/${CF_ENDPOINT.toLowerCase()}?${ORG_ENDPOINT}=${orgId}`;

beforeAll(() => {
callSettingsClient = new UcmBackendConnector(webex, {level: LOGGER.INFO}, false);
Expand Down
14 changes: 6 additions & 8 deletions packages/calling/src/CallSettings/UcmBackendConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ import {
SUCCESS_MESSAGE,
UCM_CONNECTOR_FILE,
VOICEMAIL,
WEBEX_API_CONFIG_INT_URL,
WEBEX_API_CONFIG_PROD_URL,
} from '../common/constants';
import {HTTP_METHODS, WebexRequestPayload} from '../common/types';
import {
CF_ENDPOINT,
ORG_ENDPOINT,
PEOPLE_ENDPOINT,
WEBEX_APIS_INT_URL,
WEBEX_APIS_PROD_URL,
} from './constants';
import {CF_ENDPOINT, ORG_ENDPOINT, PEOPLE_ENDPOINT} from './constants';
import {
CallForwardAlwaysSetting,
CallForwardingSettingsUCM,
Expand Down Expand Up @@ -132,7 +128,9 @@ export class UcmBackendConnector implements IUcmBackendConnector {
method: this.getCallForwardAlwaysSetting.name,
};

const webexApisUrl = this.useProdWebexApis ? WEBEX_APIS_PROD_URL : WEBEX_APIS_INT_URL;
const webexApisUrl = this.useProdWebexApis
? WEBEX_API_CONFIG_PROD_URL
: WEBEX_API_CONFIG_INT_URL;

try {
if (directoryNumber) {
Expand Down
2 changes: 0 additions & 2 deletions packages/calling/src/CallSettings/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ export const CF_ENDPOINT = 'features/callForwarding';
export const VM_ENDPOINT = 'features/voicemail';
export const CALL_WAITING_ENDPOINT = 'CallWaiting';
export const XSI_VERSION = 'v2.0';
export const WEBEX_APIS_INT_URL = 'https://integration.webexapis.com/v1/uc/config';
export const WEBEX_APIS_PROD_URL = 'https://webexapis.com/v1/uc/config';
3 changes: 2 additions & 1 deletion packages/calling/src/Contacts/ContactsClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SCIM_ENDPOINT_RESOURCE,
SCIM_USER_FILTER,
SUCCESS_MESSAGE,
WEBEX_API_BTS,
} from '../common/constants';
import log from '../Logger';
import {
Expand Down Expand Up @@ -59,7 +60,7 @@ describe('ContactClient Tests', () => {

// eslint-disable-next-line no-underscore-dangle
const contactServiceUrl = `${webex.internal.services._serviceUrls.contactsService}/${ENCRYPT_FILTER}/${USERS}/${CONTACT_FILTER}`;
const scimUrl = `${webex.internal.services._serviceUrls.identity}/${IDENTITY_ENDPOINT_RESOURCE}/${SCIM_ENDPOINT_RESOURCE}/${webex.internal.device.orgId}/${SCIM_USER_FILTER}id%20eq%20%22801bb994-343b-4f6b-97ae-d13c91d4b877%22`;
const scimUrl = `${WEBEX_API_BTS}/${IDENTITY_ENDPOINT_RESOURCE}/${SCIM_ENDPOINT_RESOURCE}/${webex.internal.device.orgId}/${SCIM_USER_FILTER}id%20eq%20%22801bb994-343b-4f6b-97ae-d13c91d4b877%22`;
// eslint-disable-next-line no-underscore-dangle
const contactServiceGroupUrl = `${webex.internal.services._serviceUrls.contactsService}/${ENCRYPT_FILTER}/${USERS}/${GROUP_FILTER}`;
const serviceErrorCodeHandlerSpy = jest.spyOn(utils, 'serviceErrorCodeHandler');
Expand Down
3 changes: 2 additions & 1 deletion packages/calling/src/common/Utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
INFER_ID_CONSTANT,
SCIM_ENDPOINT_RESOURCE,
SCIM_USER_FILTER,
WEBEX_API_BTS,
} from './constants';
import {CALL_EVENT_KEYS} from '../Events/types';

Expand Down Expand Up @@ -913,7 +914,7 @@ describe('Voicemail Sorting Tests', () => {
});

describe('resolveContact tests', () => {
const scimUrl = `${webex.internal.services._serviceUrls.identity}/${IDENTITY_ENDPOINT_RESOURCE}/${SCIM_ENDPOINT_RESOURCE}/${webex.internal.device.orgId}/${SCIM_USER_FILTER}`;
const scimUrl = `${WEBEX_API_BTS}/${IDENTITY_ENDPOINT_RESOURCE}/${SCIM_ENDPOINT_RESOURCE}/${webex.internal.device.orgId}/${SCIM_USER_FILTER}`;

it('Invalid CallingPartyInfo', () => {
const callingPartyInfo = {} as CallingPartyInfo;
Expand Down
7 changes: 6 additions & 1 deletion packages/calling/src/common/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ import {
IDENTITY_ENDPOINT_RESOURCE,
SCIM_ENDPOINT_RESOURCE,
SCIM_USER_FILTER,
WEBEX_API_PROD,
WEBEX_API_BTS,
} from './constants';
import {Model, WebexSDK} from '../SDKConnector/types';
import SDKConnector from '../SDKConnector';
Expand Down Expand Up @@ -1184,7 +1186,10 @@ export async function scimQuery(filter: string) {
const sdkConnector = SDKConnector;
const webex = sdkConnector.getWebex();

const scimUrl = `${webex.internal.services._serviceUrls.identity}/${IDENTITY_ENDPOINT_RESOURCE}/${SCIM_ENDPOINT_RESOURCE}/${webex.internal.device.orgId}/${SCIM_USER_FILTER}`;
const isProd = !webex.internal.device.url.includes('-int');
const webexHost = isProd ? WEBEX_API_PROD : WEBEX_API_BTS;

const scimUrl = `${webexHost}/${IDENTITY_ENDPOINT_RESOURCE}/${SCIM_ENDPOINT_RESOURCE}/${webex.internal.device.orgId}/${SCIM_USER_FILTER}`;
const query = scimUrl + encodeURIComponent(filter);

return <WebexRequestPayload>(<unknown>webex.request({
Expand Down
4 changes: 4 additions & 0 deletions packages/calling/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ export const UCM_CONNECTOR_FILE = 'UcmBackendConnector';
export const VOICEMAIL = 'VOICEMAIL';
export const SCIM_WEBEXIDENTITY_USER = 'urn:scim:schemas:extension:cisco:webexidentity:2.0:User';
export const SCIM_ENTERPRISE_USER = 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User';
export const WEBEX_API_PROD = 'https://webexapis.com';
export const WEBEX_API_BTS = 'https://integration.webexapis.com';
export const WEBEX_API_CONFIG_INT_URL = `https://${WEBEX_API_BTS}/v1/uc/config`;
export const WEBEX_API_CONFIG_PROD_URL = `https://${WEBEX_API_PROD}/v1/uc/config`;

0 comments on commit 1de73b3

Please sign in to comment.