Skip to content

Commit 652a7cc

Browse files
shakyShaneShane Osbourne
andauthored
add test covering insecure context (#1264)
Co-authored-by: Shane Osbourne <[email protected]>
1 parent 2b90f9d commit 652a7cc

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"log": {
3+
"version": "1.2",
4+
"creator": {
5+
"name": "Playwright",
6+
"version": "1.48.2"
7+
},
8+
"browser": {
9+
"name": "chromium",
10+
"version": "130.0.6723.31"
11+
},
12+
"entries": [
13+
{
14+
"startedDateTime": "2024-11-24T21:07:22.404Z",
15+
"time": 1.384,
16+
"request": {
17+
"method": "GET",
18+
"url": "http://example.com/",
19+
"httpVersion": "HTTP/1.1",
20+
"cookies": [],
21+
"headers": [
22+
{ "name": "Accept", "value": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7" },
23+
{ "name": "Accept-Encoding", "value": "gzip, deflate" },
24+
{ "name": "Accept-Language", "value": "en-US,en;q=0.9" },
25+
{ "name": "Connection", "value": "keep-alive" },
26+
{ "name": "Host", "value": "example.com" },
27+
{ "name": "Upgrade-Insecure-Requests", "value": "1" },
28+
{ "name": "User-Agent", "value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" }
29+
],
30+
"queryString": [],
31+
"headersSize": -1,
32+
"bodySize": -1
33+
},
34+
"response": {
35+
"status": 200,
36+
"statusText": "OK",
37+
"httpVersion": "HTTP/1.1",
38+
"cookies": [],
39+
"headers": [
40+
{ "name": "Accept-Ranges", "value": "bytes" },
41+
{ "name": "Age", "value": "491759" },
42+
{ "name": "Cache-Control", "value": "max-age=604800" },
43+
{ "name": "Content-Encoding", "value": "gzip" },
44+
{ "name": "Content-Length", "value": "648" },
45+
{ "name": "Content-Type", "value": "text/html; charset=UTF-8" },
46+
{ "name": "Date", "value": "Sun, 24 Nov 2024 21:07:22 GMT" },
47+
{ "name": "Etag", "value": "\"3147526947+gzip\"" },
48+
{ "name": "Expires", "value": "Sun, 01 Dec 2024 21:07:22 GMT" },
49+
{ "name": "Last-Modified", "value": "Thu, 17 Oct 2019 07:18:26 GMT" },
50+
{ "name": "Server", "value": "ECAcc (dcd/7D28)" },
51+
{ "name": "Vary", "value": "Accept-Encoding" },
52+
{ "name": "X-Cache", "value": "HIT" }
53+
],
54+
"content": {
55+
"size": -1,
56+
"mimeType": "text/html; charset=UTF-8",
57+
"text": "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style type=\"text/css\">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.</p>\n <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n"
58+
},
59+
"headersSize": -1,
60+
"bodySize": -1,
61+
"redirectURL": ""
62+
},
63+
"cache": {},
64+
"timings": { "send": -1, "wait": -1, "receive": 1.384 }
65+
}
66+
]
67+
}
68+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { test, expect } from '@playwright/test';
2+
import { ResultsCollector } from './page-objects/results-collector.js';
3+
4+
const HAR_FILE = 'integration-test/data/har/example.com/example.com.har';
5+
const CONFIG = {
6+
features: {
7+
navigatorInterface: {
8+
state: 'enabled',
9+
exceptions: [],
10+
},
11+
},
12+
unprotectedTemporary: [],
13+
};
14+
15+
test.describe('insecure contexts', () => {
16+
test('should expose navigator.isDuckDuckGo in insecure contexts', async ({ page }, testInfo) => {
17+
const example = ResultsCollector.create(page, testInfo.project.use);
18+
await example.setup({ config: CONFIG, locale: 'en' });
19+
await page.routeFromHAR(HAR_FILE);
20+
await page.goto('http://example.com');
21+
22+
// verify the platform was set
23+
const actual = await page.evaluate('navigator.duckduckgo.platform');
24+
const expected = /** @type {any} */ (testInfo.project.use).platform;
25+
expect(actual).toEqual(expected);
26+
});
27+
});

injected/playwright.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default defineConfig({
2828
name: 'apple',
2929
// prettier-ignore
3030
testMatch: [
31+
'integration-test/navigator-interface-insecure.js',
3132
'integration-test/webcompat.spec.js',
3233
'integration-test/message-bridge-apple.spec.js'
3334
],

0 commit comments

Comments
 (0)