Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
/* Any copyright is dedicated to the Public Domain.
"use strict";
const { ObliviousHTTP } = ChromeUtils.importESModule(
"resource://gre/modules/ObliviousHTTP.sys.mjs"
);
const { sinon } = ChromeUtils.importESModule(
);
/**
* Test that host validation is properly integrated with channel loading.
*/
add_task(async function test_channel_loading_with_host_validation() {
const sandbox = sinon.createSandbox();
// Set up valid OHTTP preferences
Services.prefs.setCharPref(
"browser.newtabpage.activity-stream.discoverystream.ohttp.configURL",
);
Services.prefs.setCharPref(
"browser.newtabpage.activity-stream.discoverystream.ohttp.relayURL",
);
// Stub OHTTP methods
sandbox
.stub(ObliviousHTTP, "getOHTTPConfig")
.resolves(new Uint8Array([1, 2, 3, 4]));
MockOHTTPService.reset();
try {
// Test valid newtab-image host
const validTestURI = createTestOHTTPResourceURI(validImageURL);
const validChannel = createTestChannel(validTestURI);
let validLoadCompleted = false;
await new Promise(resolve => {
const listener = createCompletionListener(success => {
validLoadCompleted = success;
resolve();
});
validChannel.asyncOpen(listener);
});
Assert.ok(
validLoadCompleted,
"Should successfully load with valid newtab-image host"
);
Assert.ok(
MockOHTTPService.channelCreated,
"Should call OHTTP service for valid host"
);
// Reset mock for next test
MockOHTTPService.reset();
// Test invalid host
const invalidHostURL =
const invalidChannel = createTestChannel(invalidHostURL);
let invalidLoadFailed = false;
await new Promise(resolve => {
const listener = createCompletionListener(success => {
invalidLoadFailed = !success;
resolve();
});
invalidChannel.asyncOpen(listener);
});
Assert.ok(invalidLoadFailed, "Should fail to load with invalid host");
Assert.ok(
!MockOHTTPService.channelCreated,
"Should not call OHTTP service for invalid host"
);
} finally {
sandbox.restore();
Services.prefs.clearUserPref(
"browser.newtabpage.activity-stream.discoverystream.ohttp.configURL"
);
Services.prefs.clearUserPref(
"browser.newtabpage.activity-stream.discoverystream.ohttp.relayURL"
);
}
});