diff --git a/packages/bruno-tests/collection/scripting/api/bru/cookies/Redirect Cookie Save.bru b/packages/bruno-tests/collection/scripting/api/bru/cookies/Redirect Cookie Save.bru index f120acdfb..aeaa53684 100644 --- a/packages/bruno-tests/collection/scripting/api/bru/cookies/Redirect Cookie Save.bru +++ b/packages/bruno-tests/collection/scripting/api/bru/cookies/Redirect Cookie Save.bru @@ -5,16 +5,22 @@ meta { } get { - url: https://httpbun.com/mix/s=302/c=foo:bar/r=https%3A%2F%2Fhttpbun.org%2Fget + url: http://localhost:8081/api/mix?s=302&c=foo:bar&r=http://127.0.0.1:8081/query body: none auth: inherit } +params:query { + s: 302 + c: foo:bar + r: http://127.0.0.1:8081/query +} + tests { const jar = bru.cookies.jar() const cookieData = await jar.getCookie( - "https://httpbun.com", + "http://localhost:8081", "foo" ); diff --git a/packages/bruno-tests/src/index.js b/packages/bruno-tests/src/index.js index e65c60661..aa63bcbc0 100644 --- a/packages/bruno-tests/src/index.js +++ b/packages/bruno-tests/src/index.js @@ -7,6 +7,7 @@ const echoRouter = require('./echo'); const xmlParser = require('./utils/xmlParser'); const multipartRouter = require('./multipart'); const redirectRouter = require('./redirect'); +const mixRouter = require('./mix'); const wsRouter = require('./ws'); const app = new express(); @@ -31,6 +32,7 @@ app.use('/api/auth', authRouter); app.use('/api/echo', echoRouter); app.use('/api/multipart', multipartRouter); app.use('/api/redirect', redirectRouter); +app.use('/api/mix', mixRouter); app.get('/ping', function (req, res) { return res.send('pong'); diff --git a/packages/bruno-tests/src/mix/index.js b/packages/bruno-tests/src/mix/index.js new file mode 100644 index 000000000..955775ccd --- /dev/null +++ b/packages/bruno-tests/src/mix/index.js @@ -0,0 +1,33 @@ +const express = require('express'); +const router = express.Router(); + +router.get('/', function (req, res) { + // Parse query parameters similar to http bun's /mix endpoint + // s=status code, c=cookie (name:value), r=redirect URL + const statusCode = parseInt(req.query.s, 10) || 302; + const cookie = req.query.c; // format: name:value + const redirectUrl = req.query.r; + + // Set cookie if provided + if (cookie) { + const [cookieName, cookieValue] = cookie.split(':'); + if (cookieName && cookieValue) { + res.setHeader('Set-Cookie', `${cookieName}=${cookieValue}; Path=/`); + } + } + + // Redirect to the specified URL, even if it's not on our domain + if (redirectUrl) { + res.status(statusCode) + .set('Location', redirectUrl) + .send(` +
You should be redirected automatically to target URL: ${redirectUrl}. If not click the link.
+ `); + } else { + res.status(400).json({ error: 'Missing redirect URL parameter (r)' }); + } +}); + +module.exports = router; diff --git a/packages/bruno-tests/src/redirect/index.js b/packages/bruno-tests/src/redirect/index.js index b49e5593b..f9dac57c8 100644 --- a/packages/bruno-tests/src/redirect/index.js +++ b/packages/bruno-tests/src/redirect/index.js @@ -106,6 +106,11 @@ router.get('/anything', function (req, res) { router.get('/:count', function (req, res) { const count = parseInt(req.params.count, 10); + // Validate that count is a valid number to prevent infinite redirect loops + if (isNaN(count)) { + return res.status(404).json({ error: 'Invalid redirect count. Must be a number.' }); + } + if (count > 1) { // Redirect to the next redirect in the chain const nextCount = count - 1; diff --git a/tests/request/settings/collection/timeout.bru b/tests/request/settings/collection/timeout.bru index ee40d4cae..a8f18797f 100644 --- a/tests/request/settings/collection/timeout.bru +++ b/tests/request/settings/collection/timeout.bru @@ -5,7 +5,7 @@ meta { } get { - url: https://httpbun.com/redirect/2 + url: https://testbench-sanity.usebruno.com/redirect-to-ping body: none auth: inherit }