mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-24 16:20:39 -04:00
feat: support to set cookie hostOnly property (#8677)
This commit is contained in:
@@ -59,6 +59,33 @@ test.describe('Cookie editor', () => {
|
||||
await expect.soft(page.getByText('foo2=bar2')).toBeVisible();
|
||||
});
|
||||
|
||||
test('support __Host- prefix', async ({ page }) => {
|
||||
// Open cookie editor
|
||||
await page.click('button:has-text("Cookies")');
|
||||
|
||||
// Create a new cookie
|
||||
await page.getByRole('button', { name: 'Add Cookie' }).click();
|
||||
|
||||
// Edit the new cookie
|
||||
await page.getByRole('button', { name: 'Edit' }).first().click();
|
||||
await page.getByText('HostOnly').click();
|
||||
await expect.soft(page.locator('input[name="hostOnly"]')).toBeChecked();
|
||||
await page.getByRole('tab', { name: 'Raw' }).click();
|
||||
await page
|
||||
.locator('text=Raw Cookie String >> input[type="text"]')
|
||||
.fill('__Host-foo=bar; Expires=Tue, 19 Jan 2038 03:14:07 GMT; Secure; Domain=localhost; Path=/');
|
||||
await page.locator('text=Done').nth(1).click();
|
||||
await page.click('text=Done');
|
||||
|
||||
// Send request
|
||||
await page.getByLabel('Request Collection').getByTestId('example http').press('Enter');
|
||||
await page.click('[data-testid="request-pane"] button:has-text("Send")');
|
||||
|
||||
// Check in the timeline that the cookie was sent
|
||||
await page.getByRole('tab', { name: 'Console' }).click();
|
||||
await expect.soft(page.getByText('__Host-foo=bar')).toBeVisible();
|
||||
});
|
||||
|
||||
test('cookie list should update when cookie is updated', async ({ page }) => {
|
||||
// Open cookie editor
|
||||
await page.click('button:has-text("Cookies")');
|
||||
|
||||
@@ -525,7 +525,19 @@ const CookieModifyModal = ({ cookie, isOpen, setIsOpen, onUpdateCookie }: Cookie
|
||||
defaultChecked={editCookie.httpOnly || false}
|
||||
onChange={event => setEditCookie({ ...editCookie, httpOnly: event.target.checked })}
|
||||
/>
|
||||
httpOnly
|
||||
HttpOnly
|
||||
</label>
|
||||
</div>
|
||||
<div className="grid w-full grid-cols-2 gap-2">
|
||||
<label className="flex items-center gap-1">
|
||||
<input
|
||||
className="space-left"
|
||||
type="checkbox"
|
||||
name="hostOnly"
|
||||
defaultChecked={editCookie.hostOnly || false}
|
||||
onChange={event => setEditCookie({ ...editCookie, hostOnly: event.target.checked })}
|
||||
/>
|
||||
HostOnly
|
||||
</label>
|
||||
</div>
|
||||
</TabPanel>
|
||||
@@ -540,8 +552,9 @@ const CookieModifyModal = ({ cookie, isOpen, setIsOpen, onUpdateCookie }: Cookie
|
||||
// NOTE: Perform toJSON so we have a plain JS object instead of Cookie instance
|
||||
const parsed = ToughCookie.parse(event.target.value, { loose: true })?.toJSON();
|
||||
if (parsed) {
|
||||
// Make sure cookie has an id
|
||||
// Make sure cookie has an id and keep its host-only-flag
|
||||
parsed.id = editCookie.id;
|
||||
parsed.hostOnly = editCookie.hostOnly;
|
||||
setEditCookie(parsed as Cookie);
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user