Skip to content

Commit

Permalink
e2e tests for app-with-rbac and app-with-service-account
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukochka committed Jun 19, 2024
1 parent 2c76203 commit ffb3b87
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 132 deletions.
14 changes: 7 additions & 7 deletions examples/app-with-rbac/.config/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ENV DEV "${development}"
# Do NOT enable these settings in a public facing / production grafana instance
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
ENV GF_AUTH_ANONYMOUS_ENABLED "true"
ENV GF_AUTH_BASIC_ENABLED "false"
ENV GF_AUTH_BASIC_ENABLED "true"
# Set development mode so plugins can be loaded without the need to sign
ENV GF_DEFAULT_APP_MODE "development"

Expand All @@ -29,14 +29,14 @@ USER root
# Installing supervisor and inotify-tools
RUN if [ "${development}" = "true" ]; then \
if grep -i -q alpine /etc/issue; then \
apk add supervisor inotify-tools git; \
apk add supervisor inotify-tools git; \
elif grep -i -q ubuntu /etc/issue; then \
DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -y supervisor inotify-tools git && \
rm -rf /var/lib/apt/lists/*; \
DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -y supervisor inotify-tools git && \
rm -rf /var/lib/apt/lists/*; \
else \
echo 'ERROR: Unsupported base image' && /bin/false; \
echo 'ERROR: Unsupported base image' && /bin/false; \
fi \
fi

Expand Down
49 changes: 29 additions & 20 deletions examples/app-with-rbac/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,46 @@ export default defineConfig({
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'auth',
name: 'adminUserAuthenticates',
testDir: pluginE2eAuth,
testMatch: [/.*\.js/],
},
{
name: 'run-tests',
name: 'run-tests-for-admin',
testDir: './tests/admin',
use: {
...devices['Desktop Chrome'],
// @grafana/plugin-e2e writes the auth state to this file,
// the path should not be modified
storageState: 'playwright/.auth/admin.json',
},
dependencies: ['auth'],
dependencies: ['adminUserAuthenticates'],
},
{
name: 'createViewerUserAndAuthenticate',
testDir: pluginE2eAuth,
testMatch: [/.*\.js/],
use: {
user: {
user: 'viewer',
password: 'password',
role: 'Viewer',
},
},
},
{
name: 'run-tests-for-viewer',
testDir: './tests/viewer',
use: {
...devices['Desktop Chrome'],
// @grafana/plugin-e2e writes the auth state to this file,
// the path should not be modified
storageState: 'playwright/.auth/viewer.json',
},
dependencies: ['createViewerUserAndAuthenticate'],
},
// {
// name: 'createAdminUserAndAuthenticate',
// testDir: pluginE2eAuth,
// testMatch: [/.*\.js/],
// },
// {
// name: 'run-tests-for-admin',
// testDir: './tests',
// use: {
// ...devices['Desktop Chrome'],
// // @grafana/plugin-e2e writes the auth state to this file,
// // the path should not be modified
// storageState: 'playwright/.auth/admin.json',
// },
// dependencies: ['createAdminUserAndAuthenticate'],
// },
],
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { test, expect } from './fixtures';
import { ROUTES } from '../src/constants';
import { test, expect } from '../fixtures';
import { ROUTES } from '../../src/constants';

test.describe('navigating app', () => {
test('Page patents should be visible for admin', async ({ gotoPage, page }) => {
// wait for page to successfully render
await gotoPage('/hello');
await expect(page).toHaveURL(/.*patents/);
await expect(page.getByText('Welcome')).toBeVisible();
await gotoPage(`/${ROUTES.Patents}`);
await expect(page.getByText('Normally restricted to Administrators')).toBeVisible();
});
test('Page research docs should be visible for admin', async ({ gotoPage, page }) => {
// wait for page to successfully render
await gotoPage(`/${ROUTES.ResearchDocs}`);
await expect(page).toHaveURL(/.*research/);
await expect(page.getByText('Welcome')).toBeVisible();
await expect(page.getByText('Normally accessible to anyone')).toBeVisible();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test, expect } from '../fixtures';
import { ROUTES } from '../../src/constants';

test.describe('navigating app for Viewer', () => {
test('Page patents should not be visible for viewer', async ({ gotoPage, page }) => {
// wait for page to successfully render
await gotoPage(`/${ROUTES.Patents}`);
await expect(page.getByText('Normally restricted to Administrators')).not.toBeVisible();
});
test('Page research docs should be visible for viewer', async ({ gotoPage, page }) => {
// wait for page to successfully render
await gotoPage(`/${ROUTES.ResearchDocs}`);
await expect(page.getByText('Normally accessible to anyone')).toBeVisible();
});
});
14 changes: 7 additions & 7 deletions examples/app-with-service-account/.config/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ENV DEV "${development}"
# Do NOT enable these settings in a public facing / production grafana instance
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
ENV GF_AUTH_ANONYMOUS_ENABLED "true"
ENV GF_AUTH_BASIC_ENABLED "false"
ENV GF_AUTH_BASIC_ENABLED "true"
# Set development mode so plugins can be loaded without the need to sign
ENV GF_DEFAULT_APP_MODE "development"

Expand All @@ -29,14 +29,14 @@ USER root
# Installing supervisor and inotify-tools
RUN if [ "${development}" = "true" ]; then \
if grep -i -q alpine /etc/issue; then \
apk add supervisor inotify-tools git; \
apk add supervisor inotify-tools git; \
elif grep -i -q ubuntu /etc/issue; then \
DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -y supervisor inotify-tools git && \
rm -rf /var/lib/apt/lists/*; \
DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -y supervisor inotify-tools git && \
rm -rf /var/lib/apt/lists/*; \
else \
echo 'ERROR: Unsupported base image' && /bin/false; \
echo 'ERROR: Unsupported base image' && /bin/false; \
fi \
fi

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "grafana-testdata-datasource",
"uid": "PD8C576611E62080A"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unitScale": true
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "grafana-testdata-datasource",
"uid": "PD8C576611E62080A"
},
"refId": "A",
"scenarioId": "random_walk",
"seriesCount": 1
}
],
"title": "Panel Title",
"type": "timeseries"
}
],
"refresh": "",
"schemaVersion": 39,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "New dashboard",
"version": 0,
"weekStart": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: 1

providers:
- name: Default
type: file
options:
path: /etc/grafana/provisioning/dashboards
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: 1

datasources:
- name: gdev-testdata
isDefault: true
type: testdata
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ apiVersion: 1

apps:
- type: 'grafana-appwithserviceaccount-app'
org_id: 1
org_name: Main Org.
disabled: false
6 changes: 4 additions & 2 deletions examples/app-with-service-account/src/pages/PageOne.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function PageOne() {
setApiResponse('Loading...');
let params = {};
params = { ...params, method: method };
if (method === 'POST' || method === "PUT") {
if (method === 'POST' || method === 'PUT') {
let parsedBody = JSON.parse(body);
params = { ...params, body: JSON.stringify(parsedBody) };
}
Expand Down Expand Up @@ -98,7 +98,9 @@ export function PageOne() {
<h3>Token used</h3>
<p>{apiToken}</p>
<h3>API Response</h3>
<JSONFormatter json={apiResponse} />
<div data-testid="json-format-response">
<JSONFormatter json={apiResponse} />
</div>
</VerticalGroup>
</div>
);
Expand Down
19 changes: 0 additions & 19 deletions examples/app-with-service-account/tests/appConfig.spec.ts

This file was deleted.

31 changes: 0 additions & 31 deletions examples/app-with-service-account/tests/appNavigation.spec.ts

This file was deleted.

Loading

0 comments on commit ffb3b87

Please sign in to comment.