mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 00:17:09 +08:00

* chore(angularsupport): delete feature toggle to disable angular * feat(angular-support): remove config.angularSupportEnabled * chore(jest): remove angular from setup file * chore(angular): delete angular deprecation ui components * refactor(angular): move migration featureflags into migration notice * chore(dashboard): remove angular deprecation notices * chore(annotations): remove angular editor loader * feat(appwrapper): no more angular app loading * feat(pluginscatalog): clean up angular plugin warnings and logic * chore(angular): delete angular app and associated files * feat(plugins): delete old angular graph plugin * feat(plugins): delete old angular table panel * feat(frontend): remove unused appEvent type * feat(dashboards): clean up angular from panel options and menu * feat(plugins): remove graph and table-old from built in plugins and delete sdk * feat(frontend): remove angular related imports in routes and explore graph * feat(theme): remove angular panel styles from global styles * chore(i18n): run make i18n-extract * test(api_plugins_test): refresh snapshot due to deleting old graph and table plugins * chore(angulardeprecation): delete angular migration notice components and usage * test(frontend): clean up tests that assert rendering angular deprecation notices * chore(backend): remove autoMigrateOldPanels feature flag * chore(config): remove angularSupportEnabled from config preventing loading angular plugins * chore(graphpanel): remove autoMigrateGraphPanel from feature toggles * chore(tablepanel): delete autoMigrateTablePanel feature flag * chore(piechart): delete autoMigratePiechartPanel feature flag * chore(worldmappanel): remove autoMigrateWorldmapPanel feature toggle * chore(statpanel): remove autoMigrateStatPanel feature flag * feat(dashboards): remove automigrate feature flags and always auto migrate angular panels * test(pluginsintegration): fix failing loader test * test(frontend): wip: fix failures and skip erroring migration tests * chore(codeowners): remove deleted angular related files and directories * test(graphite): remove angular mock from test file * test(dashboards): skip failing exporter test, remove angularSupportEnabled flags * test(dashbaord): skip another failing panel menu test * Tests: fixes pkg/services/pluginsintegration/loader/loader_test.go (#100505) * Tests: fixes pkg/services/pluginsintegration/plugins_integration_test.go * Trigger Build * chore(dashboards): remove angularComponent from getPanelMenu, update test * feat(dashboards): remove all usage of AngularComponent and getAngularLoader * chore(betterer): refresh results file * feat(plugins): remove PluginAngularBadge component and usage * feat(datasource_srv): remove usage of getLegacyAngularInjector * feat(queryeditor): delete AngularQueryComponentScope type * Chore: removes Angular from plugin_loader * Chore: remove angular from getPlugin * Chore: fix i18n * Trigger Build * Chore: remove more Angular from importPanelPlugin * Chore: remove search options warning * Chore: remove and deprecate Angular related * chore(angular): remove angular dependencies from core and runtime * chore(runtime): delete angular injector * chore(data): delete angular scope from event bus * chore(plugin-catalog): remove code pushing app plugins angular config page * chore(yarn): refresh lock file * chore(frontend): remove ng-loader from webpack configs, remove systemjs cjs plugin * chore(navigation): remove tether-drop cleanup from GrafanaRouter, delete dependency * chore(runtime): delete AngularLoader * chore(betterer): refresh results file * chore(betterer): fix out of sync results file * feat(query): fix type and import errors in QueryEditorRow * test(dashboards): delete skipped angular related tests * Tests: add back tests and fix betterer * Tests: fix broken test * Trigger build * chore(i18n): remove angular deprecation related strings * test: clean up connections and plugins catalog tests * chore(betterer): update results file --------- Co-authored-by: Hugo Häggmark <hugo.haggmark@gmail.com>
216 lines
9.3 KiB
TypeScript
216 lines
9.3 KiB
TypeScript
import { PluginMeta, PluginSignatureStatus, PluginSignatureType } from '@grafana/data';
|
|
import { config } from '@grafana/runtime';
|
|
import { contextSrv } from 'app/core/services/context_srv';
|
|
|
|
import { getPluginDetails } from '../admin/api';
|
|
import { CatalogPluginDetails } from '../admin/types';
|
|
import { getPluginSettings } from '../pluginSettings';
|
|
|
|
import {
|
|
shouldLoadPluginInFrontendSandbox,
|
|
setSandboxEnabledCheck,
|
|
isPluginFrontendSandboxEnabled,
|
|
isPluginFrontendSandboxEligible,
|
|
} from './sandbox_plugin_loader_registry';
|
|
|
|
jest.mock('@grafana/runtime', () => ({
|
|
config: {
|
|
featureToggles: { pluginsFrontendSandbox: true },
|
|
buildInfo: { env: 'production' },
|
|
enableFrontendSandboxForPlugins: [],
|
|
},
|
|
}));
|
|
|
|
jest.mock('../pluginSettings', () => ({
|
|
getPluginSettings: jest.fn(),
|
|
}));
|
|
|
|
jest.mock('../admin/api', () => ({
|
|
getPluginDetails: jest.fn(),
|
|
}));
|
|
|
|
const getPluginSettingsMock = jest.mocked(getPluginSettings);
|
|
const getPluginDetailsMock = jest.mocked(getPluginDetails);
|
|
const mockContextSrv = jest.mocked(contextSrv);
|
|
|
|
const fakePluginSettings: PluginMeta = {
|
|
id: 'test-plugin',
|
|
name: 'Test Plugin',
|
|
} as PluginMeta;
|
|
|
|
const fakePluginDetails: CatalogPluginDetails = {} as CatalogPluginDetails;
|
|
|
|
describe('Sandbox eligibility checks', () => {
|
|
const originalNodeEnv = process.env.NODE_ENV;
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
getPluginDetailsMock.mockReset();
|
|
getPluginSettingsMock.mockReset();
|
|
mockContextSrv.isSignedIn = true;
|
|
|
|
// restore default check
|
|
setSandboxEnabledCheck(isPluginFrontendSandboxEnabled);
|
|
|
|
config.enableFrontendSandboxForPlugins = [];
|
|
config.featureToggles.pluginsFrontendSandbox = true;
|
|
process.env.NODE_ENV = 'development';
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env.NODE_ENV = originalNodeEnv;
|
|
});
|
|
|
|
test('isPluginFrontendSandboxEligible returns false for unsigned users', async () => {
|
|
mockContextSrv.isSignedIn = false;
|
|
const isEligible = await isPluginFrontendSandboxEligible({ pluginId: 'test-plugin' });
|
|
expect(isEligible).toBe(false);
|
|
});
|
|
|
|
test('shouldLoadPluginInFrontendSandbox returns false when feature toggle is off', async () => {
|
|
config.featureToggles.pluginsFrontendSandbox = false;
|
|
const result = await shouldLoadPluginInFrontendSandbox({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test('setSandboxEnabledCheck sets custom check function', async () => {
|
|
getPluginDetailsMock.mockResolvedValue(fakePluginDetails);
|
|
const customCheck = jest.fn().mockResolvedValue(true);
|
|
setSandboxEnabledCheck(customCheck);
|
|
const result = await shouldLoadPluginInFrontendSandbox({ pluginId: 'test-plugin' });
|
|
expect(customCheck).toHaveBeenCalledWith({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('setSandboxEnabledCheck has precedence over default', async () => {
|
|
getPluginDetailsMock.mockResolvedValue(fakePluginDetails);
|
|
const customCheck = jest.fn().mockResolvedValue(false);
|
|
setSandboxEnabledCheck(customCheck);
|
|
// this should be ignored by the custom check
|
|
config.enableFrontendSandboxForPlugins = ['test-plugin'];
|
|
const result = await shouldLoadPluginInFrontendSandbox({ pluginId: 'test-plugin' });
|
|
expect(customCheck).toHaveBeenCalledWith({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
describe('with getPluginDetails', () => {
|
|
test('shouldLoadPluginInFrontendSandbox returns false for Grafana-signed plugins', async () => {
|
|
getPluginSettingsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
getPluginDetailsMock.mockResolvedValue({ ...fakePluginDetails, signatureType: PluginSignatureType.grafana });
|
|
|
|
const result = await shouldLoadPluginInFrontendSandbox({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test('shouldLoadPluginInFrontendSandbox returns true for community plugins', async () => {
|
|
getPluginSettingsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
getPluginDetailsMock.mockResolvedValue({ ...fakePluginDetails, signatureType: PluginSignatureType.community });
|
|
|
|
config.enableFrontendSandboxForPlugins = ['test-plugin'];
|
|
const result = await shouldLoadPluginInFrontendSandbox({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('isPluginFrontendSandboxEnabled returns false when plugin is not in the enabled list', async () => {
|
|
getPluginSettingsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
getPluginDetailsMock.mockResolvedValue({ ...fakePluginDetails, signatureType: PluginSignatureType.community });
|
|
config.enableFrontendSandboxForPlugins = ['other-plugin'];
|
|
const result = await isPluginFrontendSandboxEnabled({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test('shouldLoadPluginInFrontendSandbox returns true for commercial plugins in the enabled list', async () => {
|
|
getPluginSettingsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
getPluginDetailsMock.mockResolvedValue({ ...fakePluginDetails, signatureType: PluginSignatureType.commercial });
|
|
config.enableFrontendSandboxForPlugins = ['test-plugin'];
|
|
const result = await shouldLoadPluginInFrontendSandbox({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('shouldLoadPluginInFrontendSandbox returns true for private plugins in the enabled list', async () => {
|
|
getPluginSettingsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
getPluginDetailsMock.mockResolvedValue({ ...fakePluginDetails, signatureType: PluginSignatureType.private });
|
|
config.enableFrontendSandboxForPlugins = ['test-plugin'];
|
|
const result = await shouldLoadPluginInFrontendSandbox({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('isPluginFrontendSandboxEligible returns false for plugins with internal signature', async () => {
|
|
getPluginSettingsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
getPluginDetailsMock.mockResolvedValue({
|
|
...fakePluginDetails,
|
|
signatureType: PluginSignatureType.community,
|
|
signature: PluginSignatureStatus.internal,
|
|
});
|
|
|
|
const result = await isPluginFrontendSandboxEligible({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('with getPluginSettings', () => {
|
|
test('shouldLoadPluginInFrontendSandbox returns false for Grafana-signed plugins', async () => {
|
|
// if getPluginDetails fails it fallsback to getPluginSettings
|
|
getPluginDetailsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
getPluginSettingsMock.mockResolvedValue({ ...fakePluginSettings, signatureType: PluginSignatureType.grafana });
|
|
const result = await shouldLoadPluginInFrontendSandbox({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test('shouldLoadPluginInFrontendSandbox returns true for eligible plugins in the list', async () => {
|
|
// if getPluginDetails fails it fallsback to getPluginSettings
|
|
getPluginDetailsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
getPluginSettingsMock.mockResolvedValue({ ...fakePluginSettings, signatureType: PluginSignatureType.community });
|
|
config.enableFrontendSandboxForPlugins = ['test-plugin'];
|
|
const result = await shouldLoadPluginInFrontendSandbox({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('isPluginFrontendSandboxEnabled returns false when plugin is not in the enabled list', async () => {
|
|
// if getPluginDetails fails it fallsback to getPluginSettings
|
|
getPluginDetailsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
config.enableFrontendSandboxForPlugins = ['other-plugin'];
|
|
const result = await isPluginFrontendSandboxEnabled({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
test('shouldLoadPluginInFrontendSandbox returns true for commercial plugins in the enabled list', async () => {
|
|
// if getPluginDetails fails it fallsback to getPluginSettings
|
|
getPluginDetailsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
getPluginSettingsMock.mockResolvedValue({ ...fakePluginSettings, signatureType: PluginSignatureType.commercial });
|
|
config.enableFrontendSandboxForPlugins = ['test-plugin'];
|
|
const result = await shouldLoadPluginInFrontendSandbox({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('shouldLoadPluginInFrontendSandbox returns true for private plugins in the enabled list', async () => {
|
|
// if getPluginDetails fails it fallsback to getPluginSettings
|
|
getPluginDetailsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
getPluginSettingsMock.mockResolvedValue({ ...fakePluginSettings, signatureType: PluginSignatureType.private });
|
|
config.enableFrontendSandboxForPlugins = ['test-plugin'];
|
|
const result = await shouldLoadPluginInFrontendSandbox({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
test('isPluginFrontendSandboxEligible returns false for plugins with internal signature', async () => {
|
|
// if getPluginDetails fails it fallsback to getPluginSettings
|
|
getPluginDetailsMock.mockRejectedValueOnce(new Error('not found'));
|
|
|
|
getPluginSettingsMock.mockResolvedValue({ ...fakePluginSettings, signature: PluginSignatureStatus.internal });
|
|
const result = await isPluginFrontendSandboxEligible({ pluginId: 'test-plugin' });
|
|
expect(result).toBe(false);
|
|
});
|
|
});
|
|
});
|