Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove subdomain code (os.tc) #1142

Merged
merged 35 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ef3ec2c
move unsupported os.tc check
jkasten2 Nov 22, 2023
090d872
rm internalIsUsingSubscriptionWorkaround
jkasten2 Nov 22, 2023
4c06923
rm isUsingSubscriptionWorkaround()
jkasten2 Nov 22, 2023
3c53766
rm isUsingSubscriptionWorkaround
jkasten2 Nov 22, 2023
ab3c9a1
rm getIntegration, everything is secure now
jkasten2 Nov 22, 2023
42848b9
rm AltOriginManager
jkasten2 Nov 22, 2023
eb2176b
rm canTalkToServiceWorker()
jkasten2 Nov 22, 2023
a15799b
rm ONESIGNAL_HTTP_PROMPT_SHOWN
jkasten2 Nov 22, 2023
a2ad30e
rm getOneSignalSubdomainNotificationPermission
jkasten2 Nov 22, 2023
098cd76
rm DeprecatedApiError
jkasten2 Nov 22, 2023
efcfd85
rm LegacyManager and metrics for dropped APIs
jkasten2 Nov 22, 2023
ecf8389
rm httpPermissionRequest
jkasten2 Nov 22, 2023
7a15e3d
Clean up WindowEnvironmentKind
jkasten2 Nov 22, 2023
fa4da7b
rm lastKnownHostUrl and logic around it
jkasten2 Nov 23, 2023
9f42457
remove all proxy frame classes
jkasten2 Nov 23, 2023
1d1c652
rm HTTP logic from PermisionManager
jkasten2 Nov 23, 2023
3cc2b05
rm isFrameContextInsecure
jkasten2 Nov 23, 2023
964dbe7
rm MissingSubdomain
jkasten2 Nov 23, 2023
23ba387
rm isHttps checks, this is already true now
jkasten2 Nov 23, 2023
d4211ea
rm HttpHttpsEnvironment from tests
jkasten2 Nov 23, 2023
541d93d
rm subdomain checks from checkRestrictedOrigin
jkasten2 Nov 23, 2023
cf614a6
AppConfig.subdomain to hasUnsupportedSubdomain
jkasten2 Nov 23, 2023
3a4efe7
rm httpUseOneSignalCom
jkasten2 Nov 23, 2023
443c8b8
remove reduntent useSafariLegacyPush check
jkasten2 Nov 23, 2023
f8ec723
corrected ForSecure naming
jkasten2 Nov 23, 2023
522cf9c
rm isInsecureOrigin(), as it is deadcode
jkasten2 Nov 23, 2023
12e835a
rm postmam
jkasten2 Nov 23, 2023
5dc8959
clean up comments referring to subdomain feature
jkasten2 Nov 23, 2023
8a54932
rm misc types and properites related to os.tc
jkasten2 Nov 23, 2023
0235268
remove unused imports
jkasten2 Nov 23, 2023
97fdfd1
clean up Safari in iframe detection
jkasten2 Nov 23, 2023
e1be1bb
remove onSession HTTP test
jkasten2 Nov 23, 2023
593f80f
rm dead code getSubscriptionStateForInsecure
jkasten2 Nov 23, 2023
6efdb70
rm os.tc from cert gen config
jkasten2 Nov 23, 2023
d869a8e
fix flaky test carry over
jkasten2 Nov 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions __test__/support/environment/TestContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ import { DelayedPromptType } from '../../../src/shared/models/Prompts';
import { APP_ID } from '../constants';
import deepmerge from 'deepmerge';
import ConfigManager from '../../../src/page/managers/ConfigManager';
import { HttpHttpsEnvironment } from '../models/HttpHttpsEnvironment';
import { TestEnvironmentConfig } from './TestEnvironment';

export default class TestContext {
static getFakeServerAppConfig(
configIntegrationKind: ConfigIntegrationKind,
isHttps = true,
overrideServerConfig: RecursivePartial<ServerAppConfig> | null = null,
appId: string = APP_ID,
): ServerAppConfig {
if (configIntegrationKind === ConfigIntegrationKind.Custom) {
const customConfigHttps: ServerAppConfig = {
return {
success: true,
version: 2,
app_id: appId,
Expand Down Expand Up @@ -172,31 +170,6 @@ export default class TestContext {
},
generated_at: 1531177265,
};
if (isHttps) {
return customConfigHttps;
}
return {
...customConfigHttps,
config: {
...customConfigHttps.config,
subdomain: 'helloworld123',
origin: 'http://localhost:3000',
siteInfo: {
name: 'localhost http',
origin: 'http://localhost:3000',
proxyOrigin: 'helloworld123',
defaultIconUrl: null,
proxyOriginEnabled: true,
},
welcomeNotification: {
enable: true,
url: 'http://localhost:3000/?_osp=do_not_open',
title: 'localhost http',
message: 'Thanks for subscribing!',
urlEnabled: false,
},
},
};
}

const remoteConfigMockDefaults: ServerAppConfig = {
Expand Down Expand Up @@ -495,9 +468,6 @@ export default class TestContext {
const fakeUserConfig = config.userConfig || this.getFakeAppUserConfig();
const fakeServerConfig = this.getFakeServerAppConfig(
config.integration || ConfigIntegrationKind.Custom,
config.httpOrHttps
? config.httpOrHttps === HttpHttpsEnvironment.Https
: undefined,
config.overrideServerConfig,
);
const configManager = new ConfigManager();
Expand Down
3 changes: 0 additions & 3 deletions __test__/support/environment/TestEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
stubNotification,
mockUserAgent,
} from './TestEnvironmentHelpers';
import { HttpHttpsEnvironment } from '../models/HttpHttpsEnvironment';
import OperationCache from '../../../src/core/caching/OperationCache';
import 'fake-indexeddb/auto';
import { RecursivePartial } from '../../../src/shared/context/Utils';
Expand All @@ -35,9 +34,7 @@ export interface TestEnvironmentConfig {
permission?: NotificationPermission;
addPrompts?: boolean;
url?: string;
initializeAsIframe?: boolean;
userAgent?: BrowserUserAgent;
httpOrHttps?: HttpHttpsEnvironment;
overrideServerConfig?: RecursivePartial<ServerAppConfig>;
integration?: ConfigIntegrationKind;
useMockIdentityModel?: boolean;
Expand Down
25 changes: 3 additions & 22 deletions __test__/support/environment/TestEnvironmentHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import OneSignal from '../../../src/onesignal/OneSignal';
import { CUSTOM_LINK_CSS_CLASSES } from '../../../src/shared/slidedown/constants';
import { getSlidedownElement } from '../../../src/page/slidedown/SlidedownElement';
import { MockServiceWorkerContainerWithAPIBan } from '../mocks/models/MockServiceWorkerContainerWithAPIBan';
import { HttpHttpsEnvironment } from '../models/HttpHttpsEnvironment';
import BrowserUserAgent from '../models/BrowserUserAgent';
import TestContext from './TestContext';
import { CoreModuleDirector } from '../../../src/core/CoreModuleDirector';
Expand Down Expand Up @@ -83,15 +82,7 @@ export async function stubDomEnvironment(config: TestEnvironmentConfig) {
config = {};
}

let url: string | undefined = undefined;
let isSecureContext: boolean | undefined = undefined;
if (config.httpOrHttps == HttpHttpsEnvironment.Http) {
url = 'http://localhost:3000/webpush/sandbox?http=1';
isSecureContext = false;
} else {
url = 'https://localhost:3001/webpush/sandbox?https=1';
isSecureContext = true;
}
let url = 'https://localhost:3001/webpush/sandbox?https=1';

if (config.url) {
url = config.url.toString();
Expand Down Expand Up @@ -129,24 +120,14 @@ export async function stubDomEnvironment(config: TestEnvironmentConfig) {
new MockServiceWorkerContainerWithAPIBan();
// (windowDef as any).TextEncoder = TextEncoder;
// (windowDef as any).TextDecoder = TextDecoder;
(windowDef as any).isSecureContext = isSecureContext;
(windowDef as any).location = url;

addCustomEventPolyfill(windowDef);

const windowTop: DOMWindow = config.initializeAsIframe
? ({
location: {
get origin() {
throw new Error(
"SecurityError: Permission denied to access property 'origin' on cross-origin object",
);
},
},
} as any)
: windowDef;
const windowTop: DOMWindow = windowDef;
dom.reconfigure({ url, windowTop });
global.window = windowDef;
global.window.isSecureContext = true;
global.document = windowDef.document;
return dom;
}
Expand Down
4 changes: 0 additions & 4 deletions __test__/support/models/HttpHttpsEnvironment.ts

This file was deleted.

2 changes: 0 additions & 2 deletions __test__/unit/core/modelRepo.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import OneSignalUtils from '../../../src/shared/utils/OneSignalUtils';
import ModelCache from '../../../src/core/caching/ModelCache';
import CoreModule from '../../../src/core/CoreModule';
import { CoreModuleDirector } from '../../../src/core/CoreModuleDirector';
Expand Down Expand Up @@ -27,7 +26,6 @@ jest.mock('../../../src/core/operationRepo/Operation');
describe('ModelRepo tests', () => {
beforeEach(async () => {
test.stub(ModelCache.prototype, 'load', Promise.resolve({}));
test.stub(OneSignalUtils, 'isUsingSubscriptionWorkaround', () => false);
jest.useFakeTimers();
core = new CoreModule();
coreDirector = new CoreModuleDirector(core);
Expand Down
122 changes: 1 addition & 121 deletions __test__/unit/helpers/configHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import {
} from '../../../src/shared/models/AppConfig';
import { getRandomUuid } from '../../../src/shared/utils/utils';
import { TestEnvironment } from '../../support/environment/TestEnvironment';
import { HttpHttpsEnvironment } from '../../support/models/HttpHttpsEnvironment';
import { getFinalAppConfig } from '../../support/helpers/configHelper';
import { ConfigHelper } from '../../../src/shared/helpers/ConfigHelper';
import OneSignalUtils from '../../../src/shared/utils/OneSignalUtils';
import TestContext from '../../support/environment/TestContext';

describe('ConfigHelper Tests', () => {
beforeEach(async () => {
await TestEnvironment.initialize({
httpOrHttps: HttpHttpsEnvironment.Https,
});
await TestEnvironment.initialize();
test.stub(ConfigHelper, 'checkRestrictedOrigin');
});

Expand All @@ -38,28 +34,6 @@ describe('ConfigHelper Tests', () => {
expect(finalPromptOptions?.autoPrompt).toBe(true);
});

test('promptOptions 2 - autoRegister = true backwards compatibility for custom integration (shows slidedown on HTTP)', async () => {
test.stub(
OneSignalUtils,
'internalIsUsingSubscriptionWorkaround',
Promise.resolve(true),
);

const fakeUserConfig: AppUserConfig = {
appId: getRandomUuid(),
autoRegister: true,
};

const appConfig = await getFinalAppConfig(fakeUserConfig);
const finalPromptOptions = appConfig.userConfig.promptOptions;

expect(finalPromptOptions?.native?.enabled).toBe(false);
expect(finalPromptOptions?.native?.autoPrompt).toBe(false);

expect(finalPromptOptions?.slidedown?.prompts[0].autoPrompt).toBe(true);
expect(finalPromptOptions?.autoPrompt).toBe(true);
});

test('promptOptions 3 - autoRegister = false backwards compatibility for custom integration (no enabled prompts)', async () => {
const fakeUserConfig: AppUserConfig = {
appId: getRandomUuid(),
Expand Down Expand Up @@ -97,36 +71,6 @@ describe('ConfigHelper Tests', () => {
expect(finalPromptOptions?.autoPrompt).toBe(true);
});

test(`promptOptions 5 - autoRegister backwards compatibility for custom integration (ignores config, shows slidedown on HTTP)`, async () => {
const internalIsUsingSubscriptionWorkaround = test.stub(
OneSignalUtils,
'internalIsUsingSubscriptionWorkaround',
Promise.resolve(true),
);

const fakeUserConfig: AppUserConfig = {
appId: getRandomUuid(),
autoRegister: true,
};

(fakeUserConfig as any).promptOptions = {
slidedown: {
enabled: true,
},
};

const appConfig = await getFinalAppConfig(fakeUserConfig);
const finalPromptOptions = appConfig.userConfig.promptOptions;

expect(finalPromptOptions?.native?.enabled).toBe(false);
expect(finalPromptOptions?.native?.autoPrompt).toBe(false);

expect(finalPromptOptions?.slidedown?.prompts[0].autoPrompt).toBe(true);
expect(finalPromptOptions?.autoPrompt).toBe(true);

internalIsUsingSubscriptionWorkaround.mockRestore();
});

test(`promptOptions 6 - autoRegister = true backwards compatibility for custom integration (ignores config, shows native on HTTPS)`, async () => {
const fakeUserConfig: AppUserConfig = {
appId: getRandomUuid(),
Expand All @@ -150,37 +94,6 @@ describe('ConfigHelper Tests', () => {
expect(finalPromptOptions?.autoPrompt).toBe(true);
});

test(`promptOptions 7 - autoRegister = true backwards compatibility for custom integration (ignores config, shows slidedown on HTTP)`, async () => {
const internalIsUsingSubscriptionWorkaround = test.stub(
OneSignalUtils,
'internalIsUsingSubscriptionWorkaround',
Promise.resolve(true),
);

const fakeUserConfig: AppUserConfig = {
appId: getRandomUuid(),
autoRegister: true,
};

(fakeUserConfig as any).promptOptions = {
slidedown: {
enabled: true,
autoPrompt: false,
},
};

const appConfig = await getFinalAppConfig(fakeUserConfig);
const finalPromptOptions = appConfig.userConfig.promptOptions;

expect(finalPromptOptions?.native?.enabled).toBe(false);
expect(finalPromptOptions?.native?.autoPrompt).toBe(false);

expect(finalPromptOptions?.slidedown?.prompts[0].autoPrompt).toBe(true);
expect(finalPromptOptions?.autoPrompt).toBe(true);

internalIsUsingSubscriptionWorkaround.mockRestore();
});

test(`promptOptions 8 - autoRegister = true backwards compatibility for custom integration (ignores config, shows native on HTTPS)`, async () => {
const fakeUserConfig: AppUserConfig = {
appId: getRandomUuid(),
Expand Down Expand Up @@ -235,39 +148,6 @@ describe('ConfigHelper Tests', () => {
expect(finalPromptOptions?.autoPrompt).toBe(true);
});

test(`promptOptions 10 - autoRegister backwards compatibility for custom integration (ignores config, shows slidedown on HTTP)`, async () => {
test.stub(
OneSignalUtils,
'internalIsUsingSubscriptionWorkaround',
Promise.resolve(true),
);

const fakeUserConfig: AppUserConfig = {
appId: getRandomUuid(),
autoRegister: true,
};

(fakeUserConfig as any).promptOptions = {
native: {
enabled: true,
autoPrompt: false,
},
slidedown: {
enabled: true,
autoPrompt: false,
},
};

const appConfig = await getFinalAppConfig(fakeUserConfig);
const finalPromptOptions = appConfig.userConfig.promptOptions;

expect(finalPromptOptions?.native?.enabled).toBe(false);
expect(finalPromptOptions?.native?.autoPrompt).toBe(false);

expect(finalPromptOptions?.slidedown?.prompts[0].autoPrompt).toBe(true);
expect(finalPromptOptions?.autoPrompt).toBe(true);
});

test('autoResubscribe - autoRegister backwards compatibility for custom integration 1', () => {
const fakeUserConfig: AppUserConfig = {
appId: getRandomUuid(),
Expand Down
33 changes: 0 additions & 33 deletions __test__/unit/helpers/initHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import OneSignalUtils from '../../../src/shared/utils/OneSignalUtils';
import InitHelper from '../../../src/shared/helpers/InitHelper';
import { TestEnvironment } from '../../support/environment/TestEnvironment';
import { MessageChannel } from 'worker_threads';
Expand All @@ -13,28 +12,6 @@ describe('InitHelper', () => {
jest.restoreAllMocks();
});

/** registerForPushNotifications */
test('registerForPushNotifications: requesting a modal prompt', async () => {
await InitHelper.registerForPushNotifications({ modalPrompt: true });

expect(OneSignal.subscriptionModalHost).not.toBeUndefined();
expect(OneSignal.subscriptionModalHost.modal).not.toBeUndefined();
});

test('registerForPushNotifications: load fullscreen popup when using subscription workaround', async () => {
const utilsStub = jest
.spyOn(OneSignalUtils, 'isUsingSubscriptionWorkaround')
.mockReturnValue(true);
const loadStub = jest
.spyOn(InitHelper, 'loadSubscriptionPopup')
.mockResolvedValue(undefined);

await InitHelper.registerForPushNotifications();

expect(utilsStub).toHaveBeenCalledTimes(1);
expect(loadStub).toHaveBeenCalledTimes(1);
});

/** onSdkInitialized */
test('onSdkInitialized: ensure public sdk initialized triggered', async () => {
OneSignal.emitter.on(OneSignal.EVENTS.SDK_INITIALIZED_PUBLIC, () => {
Expand All @@ -58,11 +35,6 @@ describe('InitHelper', () => {
const spy = jest
.spyOn(OneSignal.context.updateManager, 'sendOnSessionUpdate')
.mockResolvedValue(undefined);
test.stub(
OneSignalUtils,
'isUsingSubscriptionWorkaround',
Promise.resolve(false),
);

OneSignal.config.userConfig.promptOptions.autoPrompt = false;
OneSignal.config.userConfig.autoResubscribe = false;
Expand All @@ -76,11 +48,6 @@ describe('InitHelper', () => {
const spy = jest
.spyOn(OneSignal.context.updateManager, 'sendOnSessionUpdate')
.mockResolvedValue(undefined);
test.stub(
OneSignalUtils,
'isUsingSubscriptionWorkaround',
Promise.resolve(false),
);

OneSignal.config.userConfig.promptOptions.autoPrompt = true;
OneSignal.config.userConfig.autoResubscribe = true;
Expand Down
5 changes: 1 addition & 4 deletions __test__/unit/helpers/mainHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import MainHelper from '../../../src/shared/helpers/MainHelper';
import { SubscriptionStateKind } from '../../../src/shared/models/SubscriptionStateKind';
import { HttpHttpsEnvironment } from '../../support/models/HttpHttpsEnvironment';
import { TestEnvironment } from '../../support/environment/TestEnvironment';
import { NotificationPermission } from '../../../src/shared/models/NotificationPermission';

describe('MainHelper Tests', () => {
beforeEach(async () => {
jest.useFakeTimers();
await TestEnvironment.initialize({
httpOrHttps: HttpHttpsEnvironment.Https,
});
await TestEnvironment.initialize();
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion __test__/unit/notifications/eventListeners.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import EventHelper from '../../../src/shared/helpers/EventHelper';

describe('Notification Events', () => {
beforeEach(async () => {
TestEnvironment.initialize();
await TestEnvironment.initialize();
});

afterEach(() => {
Expand Down
Loading
Loading