-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
56 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,8 @@ | ||
import { test as setup } from '../'; | ||
import { createAdminClientStorageState } from '../fixtures/grafanaAPIClient'; | ||
import { GrafanaAPIClient } from '../models/GrafanaAPIClient'; | ||
|
||
setup('authenticate', async ({ login, user, grafanaAPICredentials, browser }) => { | ||
const context = await browser.newContext(); | ||
await createAdminClientStorageState(context.request, grafanaAPICredentials); | ||
const adminClient = new GrafanaAPIClient(context.request); | ||
|
||
// there's no need to create the server admin user | ||
setup('authenticate', async ({ login, createUser, user, grafanaAPICredentials }) => { | ||
if (user && (user.user !== grafanaAPICredentials.user || user.password !== grafanaAPICredentials.password)) { | ||
await adminClient.createUser(user); | ||
await createUser(); | ||
} | ||
await login(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ages/plugin-e2e/tests/as-admin-user/permissions/createUserUsingInvalidCredentials.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { expect, test } from '../../../src'; | ||
|
||
test.use({ grafanaAPICredentials: { user: 'test', password: 'test' } }); | ||
test('should throw error when credentials are invalid', async ({ grafanaAPIClient }) => { | ||
await expect(grafanaAPIClient.createUser({ user: 'testuser1', password: 'pass' })).rejects.toThrowError( | ||
/Could not create user 'testuser1'.*/ | ||
); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/plugin-e2e/tests/as-admin-user/permissions/createUserUsingValidCredentials.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { expect, test } from '../../../src'; | ||
|
||
test('should be possible to create user when credentials are valid', async ({ grafanaAPIClient }) => { | ||
await expect(grafanaAPIClient.createUser({ user: 'testuser1', password: 'pass' })).resolves.toBeUndefined(); | ||
await expect(await grafanaAPIClient.getUserIdByUsername('testuser1')).toBeTruthy(); | ||
}); |
8 changes: 8 additions & 0 deletions
8
...ges/plugin-e2e/tests/as-viewer-user/permissions/createUserUsingInvalidCredentials.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { expect, test } from '../../../src'; | ||
|
||
test.use({ grafanaAPICredentials: { user: 'test', password: 'test' } }); | ||
test('should throw error when credentials are invalid', async ({ grafanaAPIClient }) => { | ||
await expect(grafanaAPIClient.createUser({ user: 'testuser1', password: 'pass' })).rejects.toThrowError( | ||
/Could not create user 'testuser1'.*/ | ||
); | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/plugin-e2e/tests/as-viewer-user/permissions/createUserUsingValidCredentials.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expect, test } from '../../../src'; | ||
|
||
test('using grafanaAPIClient should not change storage state for logged in user', async ({ | ||
grafanaAPIClient, | ||
page, | ||
}) => { | ||
// assert one can create user on behalf of the admin credentials | ||
await expect(grafanaAPIClient.createUser({ user: 'testuser1', password: 'pass' })).resolves.toBeUndefined(); | ||
await expect(await grafanaAPIClient.getUserIdByUsername('testuser1')).toBeTruthy(); | ||
|
||
// but logged in user should still only have viewer persmissions | ||
await page.goto('/'); | ||
const homePageTitle = await page.title(); | ||
await page.goto('/datasources', { waitUntil: 'networkidle' }); | ||
expect(await page.title()).toEqual(homePageTitle); | ||
}); |