-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first commit * add basic error handler, connect to redux for notification * update * upgrade packages, fix typing * upgrade tweek-management-client api * small chages * remove log * small changes, add tests * add addiotnal test * added validation for acl * small changes * small fixes * first e2e iteration - single test * added all tests * changed error message * bump editor version * cr * CR * CR * CR * CR * prettier all! * small refactor * removed typescript :( * fix unit tests
- Loading branch information
Showing
26 changed files
with
964 additions
and
1,260 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Selector, t, ClientFunction } from 'testcafe'; | ||
|
||
const read = ClientFunction(() => window.monaco.editor.getModels()[0].getValue()); | ||
const update = ClientFunction(() => window.monaco.editor.getModels()[0].setValue(text)); | ||
|
||
export class PolicyEditor { | ||
constructor(container) { | ||
this.container = container; | ||
this.editor = this.container.find('.monaco-editor'); | ||
this.saveButton = this.container.find('button.save-button'); | ||
} | ||
|
||
async read() { | ||
return await read(); | ||
} | ||
|
||
async update(text) { | ||
return await update.with({ | ||
dependencies: { text }, | ||
})(); | ||
} | ||
|
||
hasChanges() { | ||
return this.saveButton.withAttribute('data-state-has-changes', 'true').exists; | ||
} | ||
|
||
isValid() { | ||
return this.saveButton.withAttribute('data-state-is-valid', 'true').exists; | ||
} | ||
|
||
async save() { | ||
return await t | ||
.expect(this.hasChanges()) | ||
.ok() | ||
.click(this.saveButton); | ||
} | ||
} | ||
|
||
export default class PoliciesSection { | ||
container = Selector('.policies-page'); | ||
tab = 'ACL'; | ||
|
||
async currentTab() { | ||
const panel = this.container.find(`[role=tabpanel]`); | ||
await t.expect(panel.visible).ok(); | ||
return new PolicyEditor(panel); | ||
} | ||
|
||
async changeTab(name) { | ||
const tabButton = this.container.find('[role=tab]').withText(name); | ||
const id = await tabButton.getAttribute('id'); | ||
const panel = this.container.find(`[role=tabpanel][aria-labelledby=${id}]`); | ||
|
||
//container | ||
await t | ||
.click(this.container.find('[role=tab]').withText(name)) | ||
.expect(panel.visible) | ||
.ok(); | ||
|
||
return new PolicyEditor(panel); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { expect } from 'chai'; | ||
import { Selector } from 'testcafe'; | ||
import { credentials, login } from '../../utils/auth-utils'; | ||
import { editorUrl } from '../../utils/constants'; | ||
import { waitFor } from '../../utils/assertion-utils'; | ||
import SettingsPage from '../../pages/Settings'; | ||
import { tweekManagementClient } from '../../clients/tweek-clients'; | ||
|
||
const settingsPage = new SettingsPage(); | ||
|
||
let policies; | ||
let jwtPolicy; | ||
const reset = () => { | ||
tweekManagementClient.savePolicies(policies); | ||
tweekManagementClient.saveJWTExtractionPolicy(jwtPolicy); | ||
}; | ||
|
||
fixture`Edit Policies`.page`${editorUrl}/settings` | ||
.httpAuth(credentials) | ||
.beforeEach(login) | ||
.before(async () => { | ||
policies = await tweekManagementClient.getPolicies(); | ||
jwtPolicy = await tweekManagementClient.getJWTExtractionPolicy(); | ||
}) | ||
.after(reset); | ||
|
||
test('Edit acl policies and save', async (t) => { | ||
const policiesPage = await settingsPage.openPoliciesPage(); | ||
|
||
const editor = await policiesPage.currentTab(); | ||
const data = await editor.read(); | ||
expect(JSON.stringify(policies, null, 4)).eql(data); | ||
const newData = JSON.stringify( | ||
[ | ||
...policies, | ||
{ | ||
group: 'dummy', | ||
user: 'dummy', | ||
contexts: {}, | ||
object: 'values/*', | ||
action: '*', | ||
effect: 'allow', | ||
}, | ||
], | ||
null, | ||
4, | ||
); | ||
|
||
await editor.update(newData); | ||
|
||
await editor.save(); | ||
|
||
await waitFor(async () => | ||
expect(JSON.stringify(await tweekManagementClient.getPolicies(), null, 4)).eql(newData), | ||
); | ||
}).before(async (t) => { | ||
reset(); | ||
await login(t); | ||
}); | ||
|
||
test('invalid acl policies, save disabled', async (t) => { | ||
const policiesPage = await settingsPage.openPoliciesPage(); | ||
|
||
const editor = await policiesPage.currentTab(); | ||
const newData = JSON.stringify( | ||
[ | ||
...policies, | ||
{ | ||
group: 'dummy', | ||
user: 'dummy', | ||
contexts: {}, | ||
object: 'val/*', | ||
action: '*', | ||
effect: 'allow', | ||
}, | ||
], | ||
null, | ||
4, | ||
); | ||
|
||
await editor.update(newData); | ||
|
||
await t.expect(editor.hasChanges()).eql(true); | ||
await t.expect(editor.isValid()).eql(false); | ||
}); | ||
|
||
test('updated JWT policy and save', async (t) => { | ||
const policiesPage = await settingsPage.openPoliciesPage(); | ||
|
||
const editor = await policiesPage.changeTab('JWT Extraction'); | ||
const newData = jwtPolicy.replace('input.sub', 'input.upn'); | ||
|
||
await editor.update(newData); | ||
|
||
await editor.save(); | ||
|
||
await waitFor(async () => | ||
expect(await tweekManagementClient.getJWTExtractionPolicy()).eql(newData), | ||
); | ||
}).before(async (t) => { | ||
reset(); | ||
await login(t); | ||
}); | ||
|
||
test('Attempt to save JWT policy, show error', async (t) => { | ||
const policiesPage = await settingsPage.openPoliciesPage(); | ||
|
||
const editor = await policiesPage.changeTab('JWT Extraction'); | ||
const newData = jwtPolicy.replace('input.sub', 'inpu"t.upn'); | ||
|
||
await editor.update(newData); | ||
|
||
await editor.save(); | ||
|
||
await t | ||
.expect( | ||
Selector('.notifications-br .notification-error .notification-title').withExactText( | ||
'Error saving jwt-policy', | ||
).visible, | ||
) | ||
.ok(); | ||
}).before(async (t) => { | ||
reset(); | ||
await login(t); | ||
}); |
Oops, something went wrong.