mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 06:28:33 +00:00
fix bru safe mode and add test (#6667)
* fix bru safe mode and add tests * rm: settimeout fix: isSafe mode test (#6844)
This commit is contained in:
@@ -20,6 +20,7 @@ class Bru {
|
|||||||
this.collectionPath = collectionPath;
|
this.collectionPath = collectionPath;
|
||||||
this.collectionName = collectionName;
|
this.collectionName = collectionName;
|
||||||
this.sendRequest = sendRequest;
|
this.sendRequest = sendRequest;
|
||||||
|
this.runtime = runtime;
|
||||||
this.cookies = {
|
this.cookies = {
|
||||||
jar: () => {
|
jar: () => {
|
||||||
const cookieJar = createCookieJar();
|
const cookieJar = createCookieJar();
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
meta {
|
||||||
|
name: isSafeMode
|
||||||
|
type: http
|
||||||
|
seq: 18
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: {{host}}/ping
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
script:pre-request {
|
||||||
|
test("bru.isSafeMode() returns true in safe mode", function() {
|
||||||
|
expect(bru.isSafeMode()).to.be.false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
settings {
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"version": "1",
|
||||||
|
"name": "is-safe-mode-test",
|
||||||
|
"type": "collection",
|
||||||
|
"ignore": [
|
||||||
|
"node_modules",
|
||||||
|
".git"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
meta {
|
||||||
|
name: test-safe-mode-false
|
||||||
|
type: http
|
||||||
|
seq: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: https://echo.usebruno.com
|
||||||
|
body: none
|
||||||
|
auth: none
|
||||||
|
}
|
||||||
|
|
||||||
|
tests {
|
||||||
|
test("bru.isSafeMode() returns false in developer mode", function() {
|
||||||
|
expect(bru.isSafeMode()).to.be.false;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
meta {
|
||||||
|
name: test-safe-mode-true
|
||||||
|
type: http
|
||||||
|
seq: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
get {
|
||||||
|
url: https://echo.usebruno.com
|
||||||
|
body: none
|
||||||
|
auth: none
|
||||||
|
}
|
||||||
|
|
||||||
|
tests {
|
||||||
|
test("bru.isSafeMode() returns true in safe mode", function() {
|
||||||
|
expect(bru.isSafeMode()).to.be.true;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"collections": [
|
||||||
|
{
|
||||||
|
"path": "{{projectRoot}}/tests/scripting/bru-api/isSafeMode/fixtures/collections/is-safe-mode-test",
|
||||||
|
"securityConfig": {
|
||||||
|
"jsSandboxMode": "developer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"maximized": false,
|
||||||
|
"lastOpenedCollections": [
|
||||||
|
"{{projectRoot}}/tests/scripting/bru-api/isSafeMode/fixtures/collections/is-safe-mode-test"
|
||||||
|
]
|
||||||
|
}
|
||||||
42
tests/scripting/bru-api/isSafeMode/isSafeMode.spec.ts
Normal file
42
tests/scripting/bru-api/isSafeMode/isSafeMode.spec.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { test } from '../../../../playwright';
|
||||||
|
import { setSandboxMode, runCollection, validateRunnerResults } from '../../../utils/page';
|
||||||
|
|
||||||
|
test.describe.parallel('bru.isSafeMode() API', () => {
|
||||||
|
test('returns false when running in developer mode', async ({ pageWithUserData: page }) => {
|
||||||
|
// Set up developer mode
|
||||||
|
await setSandboxMode(page, 'is-safe-mode-test', 'developer');
|
||||||
|
|
||||||
|
// Run the collection
|
||||||
|
await runCollection(page, 'is-safe-mode-test');
|
||||||
|
|
||||||
|
// Validate test results
|
||||||
|
// In developer mode:
|
||||||
|
// - test-safe-mode-false should PASS (expects false, gets false)
|
||||||
|
// - test-safe-mode-true should FAIL (expects true, gets false)
|
||||||
|
await validateRunnerResults(page, {
|
||||||
|
totalRequests: 2,
|
||||||
|
passed: 1,
|
||||||
|
failed: 1,
|
||||||
|
skipped: 0
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns true when running in safe mode', async ({ pageWithUserData: page }) => {
|
||||||
|
// Set up safe mode
|
||||||
|
await setSandboxMode(page, 'is-safe-mode-test', 'safe');
|
||||||
|
|
||||||
|
// Run the collection
|
||||||
|
await runCollection(page, 'is-safe-mode-test');
|
||||||
|
|
||||||
|
// Validate test results
|
||||||
|
// In safe mode:
|
||||||
|
// - test-safe-mode-false should FAIL (expects false, gets true)
|
||||||
|
// - test-safe-mode-true should PASS (expects true, gets true)
|
||||||
|
await validateRunnerResults(page, {
|
||||||
|
totalRequests: 2,
|
||||||
|
passed: 1,
|
||||||
|
failed: 1,
|
||||||
|
skipped: 0
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user