Skip to content

Commit

Permalink
tests: Test that spoofing on the web is good enough
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie committed Oct 13, 2024
1 parent 776cdb8 commit 0038ba4
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
5 changes: 5 additions & 0 deletions web/packages/selfhosted/test/polyfill/spoofing/expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ruffle-object
data="/test_assets/example.swf"
width="500"
height="500"
></ruffle-object>
17 changes: 17 additions & 0 deletions web/packages/selfhosted/test/polyfill/spoofing/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Spoofing Test</title>
</head>

<body>
<div id="test-container">
<object
data="/test_assets/example.swf"
width="500"
height="500"
></object>
</div>
</body>
</html>
62 changes: 62 additions & 0 deletions web/packages/selfhosted/test/polyfill/spoofing/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { openTest, injectRuffleAndWait } from "../../utils.js";
import { expect, use } from "chai";
import chaiHtml from "chai-html";
import fs from "fs";

use(chaiHtml);

describe("Spoofing is not easily detectable", () => {
it("loads the test", async () => {
await openTest(browser, `polyfill/spoofing`);
});

it("Polyfills", async () => {
await injectRuffleAndWait(browser);
await browser.$("<ruffle-object />").waitForExist();

const actual = await browser.$("#test-container").getHTML(false);
const expected = fs.readFileSync(
`${import.meta.dirname}/expected.html`,
"utf8",
);
expect(actual).html.to.equal(expected);
});

it("Spoofs navigator.plugins", async () => {
let names = await browser.execute(() => {

Check failure on line 26 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / ubuntu-24.04

'names' is never reassigned. Use 'const' instead

Check failure on line 26 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / windows-latest

'names' is never reassigned. Use 'const' instead

Check failure on line 26 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / ubuntu-24.04

'names' is never reassigned. Use 'const' instead

Check failure on line 26 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / windows-latest

'names' is never reassigned. Use 'const' instead
let names = [];

Check failure on line 27 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / ubuntu-24.04

'names' is never reassigned. Use 'const' instead

Check failure on line 27 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / windows-latest

'names' is never reassigned. Use 'const' instead

Check failure on line 27 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / ubuntu-24.04

'names' is never reassigned. Use 'const' instead

Check failure on line 27 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / windows-latest

'names' is never reassigned. Use 'const' instead
for (let i = 0; i < navigator.plugins.length; i++) {
names.push(navigator.plugins[i]!.name);
}
return names;
});
expect(names).to.include("Shockwave Flash");

let instance = await browser.execute(() => {

Check failure on line 35 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / ubuntu-24.04

'instance' is never reassigned. Use 'const' instead

Check failure on line 35 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / windows-latest

'instance' is never reassigned. Use 'const' instead

Check failure on line 35 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / ubuntu-24.04

'instance' is never reassigned. Use 'const' instead

Check failure on line 35 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / windows-latest

'instance' is never reassigned. Use 'const' instead
return navigator.plugins instanceof PluginArray

Check failure on line 36 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / ubuntu-24.04

Insert `;`

Check failure on line 36 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / windows-latest

Insert `;`

Check failure on line 36 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / ubuntu-24.04

Insert `;`

Check failure on line 36 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / windows-latest

Insert `;`
})

Check failure on line 37 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / ubuntu-24.04

Insert `;`

Check failure on line 37 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / windows-latest

Insert `;`

Check failure on line 37 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / ubuntu-24.04

Insert `;`

Check failure on line 37 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / windows-latest

Insert `;`
expect(instance).be.true;

Check failure on line 38 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / ubuntu-24.04

Expected an assignment or function call and instead saw an expression

Check failure on line 38 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / windows-latest

Expected an assignment or function call and instead saw an expression

Check failure on line 38 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / ubuntu-24.04

Expected an assignment or function call and instead saw an expression

Check failure on line 38 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / windows-latest

Expected an assignment or function call and instead saw an expression
});

it("Spoofs navigator.mimeTypes", async () => {
let types = await browser.execute(() => {

Check failure on line 42 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / ubuntu-24.04

'types' is never reassigned. Use 'const' instead

Check failure on line 42 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / windows-latest

'types' is never reassigned. Use 'const' instead

Check failure on line 42 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / ubuntu-24.04

'types' is never reassigned. Use 'const' instead

Check failure on line 42 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / windows-latest

'types' is never reassigned. Use 'const' instead
let types = [];

Check failure on line 43 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / ubuntu-24.04

'types' is never reassigned. Use 'const' instead

Check failure on line 43 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / windows-latest

'types' is never reassigned. Use 'const' instead

Check failure on line 43 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / ubuntu-24.04

'types' is never reassigned. Use 'const' instead

Check failure on line 43 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / windows-latest

'types' is never reassigned. Use 'const' instead
for (let i = 0; i < navigator.mimeTypes.length; i++) {
types.push(navigator.mimeTypes[i]!.type);
}
return types;
});
expect(types).to.include("application/x-shockwave-flash");

let instance = await browser.execute(() => {

Check failure on line 51 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / ubuntu-24.04

'instance' is never reassigned. Use 'const' instead

Check failure on line 51 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / windows-latest

'instance' is never reassigned. Use 'const' instead

Check failure on line 51 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / ubuntu-24.04

'instance' is never reassigned. Use 'const' instead

Check failure on line 51 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / windows-latest

'instance' is never reassigned. Use 'const' instead
for (let i = 0; i < navigator.mimeTypes.length; i++) {
if (!(navigator.mimeTypes[i] instanceof MimeType)) {
return false;
}
}
return navigator.mimeTypes instanceof MimeTypeArray;
})

Check failure on line 58 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / ubuntu-24.04

Insert `;`

Check failure on line 58 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 20 / windows-latest

Insert `;`

Check failure on line 58 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / ubuntu-24.04

Insert `;`

Check failure on line 58 in web/packages/selfhosted/test/polyfill/spoofing/test.ts

View workflow job for this annotation

GitHub Actions / Test Node.js 22 / windows-latest

Insert `;`
expect(instance).be.true;
});

});

0 comments on commit 0038ba4

Please sign in to comment.