Skip to content
14 changes: 14 additions & 0 deletions e2e_tests/api/server.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import GrafanaHelper from '@helpers/grafana.helper';
import { Timeouts } from '@helpers/timeouts';
import apiEndpoints from '@helpers/apiEndpoints';

export type DistributionMethod =
'DISTRIBUTION_METHOD_AMI' | 'DISTRIBUTION_METHOD_DOCKER' | 'DISTRIBUTION_METHOD_UNSPECIFIED';

export interface PmmVersion {
major: number;
minor: number;
Expand All @@ -11,12 +14,23 @@ export interface PmmVersion {
}

interface VersionResponse {
distribution_method?: DistributionMethod;
version: string;
}

export default class ServerApi {
constructor(private request: APIRequestContext) {}

getDistributionMethod = async (): Promise<DistributionMethod | undefined> => {
const response = await this.request.get(apiEndpoints.server.version, {
headers: GrafanaHelper.getAuthHeader(),
});

expect(response.status()).toEqual(200);

return ((await response.json()) as VersionResponse).distribution_method;
};

getPmmVersion = async (): Promise<PmmVersion> => {
const response = await this.request.get(apiEndpoints.server.version, {
headers: GrafanaHelper.getAuthHeader(),
Expand Down
1 change: 1 addition & 0 deletions e2e_tests/api/settings.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface SettingsResponse {
backup_management_enabled: boolean;
default_role_id?: number | string;
enable_access_control: boolean;
ssh_key: string;
};
}

Expand Down
1 change: 1 addition & 0 deletions e2e_tests/helpers/versionGates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const minPmmVersion: Record<string, string> = {
'PMM-T2266': '3.10.0',
'PMM-T2267': '3.10.0',
'PMM-T2268': '3.10.0',
'PMM-T2282': '3.10.0',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pmmTest from '@fixtures/pmmTest';
import { expect } from '@playwright/test';
import GrafanaHelper from '@helpers/grafana.helper';
import apiEndpoints from '@helpers/apiEndpoints';

pmmTest.describe('SSH key settings are unavailable off an AMI deployment.', () => {
pmmTest.beforeEach(async ({ grafanaHelper, page }) => {
await page.goto('');
await grafanaHelper.authorize();
});

pmmTest(
'PMM-T2282 - Verify the SSH key tab is hidden and its URL redirects on a non-AMI deployment @docker-configuration',
Comment thread
travagliad marked this conversation as resolved.
async ({ api, page, settingsPage }) => {
expect(await api.serverApi.getDistributionMethod()).toEqual('DISTRIBUTION_METHOD_DOCKER');

await pmmTest.step('Settings page offers no SSH key tab', async () => {
await page.goto(settingsPage.url);

await expect(settingsPage.tabs.metrics).toHaveAttribute('aria-selected', 'true');
await expect(settingsPage.tabs.ssh).toHaveCount(0);
Comment thread
travagliad marked this conversation as resolved.
});

await pmmTest.step('The SSH key URL redirects to the default tab', async () => {
await page.goto(settingsPage.urls.ssh);

await expect(settingsPage.tabs.metrics).toHaveAttribute('aria-selected', 'true');
await expect(page).toHaveURL(new RegExp(`${settingsPage.url}$`));
});

await pmmTest.step('The server refuses an SSH key', async () => {
const settingsBefore = await api.settingsApi.getSettings();
const response = await page.request.put(apiEndpoints.server.settings, {
data: {
ssh_key:
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEtU7ftdqg3rdRcv06kPAOnKX+WRmHlnG2UBpUNKw65h pmm-qa@distribution-method-test',
},
headers: GrafanaHelper.getAuthHeader(),
});

expect(response.status()).toEqual(500);

const body = (await response.json()) as { message: string };

expect(body.message).toContain('SSH key can be set only on AMI distribution');

const settingsAfter = await api.settingsApi.getSettings();

expect(settingsBefore.settings.ssh_key).toEqual('');
expect(settingsAfter.settings.ssh_key).toEqual('');
});
},
);
});
Loading