33 lines
2.9 KiB
JavaScript
33 lines
2.9 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {createRequire} from 'node:module';
|
|
const {settingsState,sectionAllowed,featureAllowed,requireSection,validateAppearance}=createRequire(import.meta.url)('../apps/browser/managed-settings.cjs');
|
|
const policy=(settings={})=>({expiresAt:new Date(Date.now()+60000).toISOString(),browser:{settings}});
|
|
test('managed settings reject direct access before enrollment, while paused and after policy expiry',()=>{
|
|
for(const context of [{ready:true},{policy:policy(),ready:false},{policy:{...policy(),expiresAt:new Date(0).toISOString()},ready:true}]){
|
|
const state=settingsState(context);assert.equal(state.visible,false);assert.throws(()=>requireSection(state,'appearance'));
|
|
}
|
|
});
|
|
test('hidden and locked sections deny operations while other sections remain available',()=>{
|
|
const state=settingsState({ready:true,policy:policy({hiddenSections:['passwords'],lockedSections:['documentScan']})});
|
|
assert.throws(()=>requireSection(state,'passwords'));assert.throws(()=>requireSection(state,'documentScan'));assert.equal(sectionAllowed(state,'ai'),true);assert.equal(sectionAllowed(state,'invented'),false);
|
|
});
|
|
test('global hidden settings reject every direct section operation',()=>{
|
|
const state=settingsState({ready:true,policy:policy({visible:false})});
|
|
for(const section of ['appearance','library','ai','passwords','documentScan','agents'])assert.throws(()=>requireSection(state,section));
|
|
});
|
|
test('signed appearance replaces local overrides immediately when locked or hidden',()=>{
|
|
const appearance={mode:'dark',accent:'violet',tabMode:'compact'},preferences={mode:'light',accent:'blue',tabMode:'separate'};
|
|
for(const constraints of [{visible:false},{hiddenSections:['appearance']},{lockedSections:['appearance']}])assert.deepEqual(settingsState({ready:true,policy:policy({...constraints,appearance}),preferences}).appearance,appearance);
|
|
assert.deepEqual(settingsState({ready:true,policy:policy({appearance}),preferences}).appearance,preferences);
|
|
});
|
|
test('appearance updates reject malformed values, unknown fields and prototype-shaped payloads',()=>{
|
|
for(const value of [null,[],{},'dark',{mode:'auto'},{accent:'red'},{tabMode:'unknown'},{security:false},{__proto__:{mode:'dark'}}])assert.throws(()=>validateAppearance(value));
|
|
assert.deepEqual(validateAppearance({mode:'system',accent:'teal'}),{mode:'system',accent:'teal'});
|
|
});
|
|
|
|
test('hiding settings preserves approved feature use but explicit hidden or locked features deny access',()=>{
|
|
const state=settingsState({ready:true,policy:policy({visible:false,hiddenSections:['passwords'],lockedSections:['agents']})});
|
|
assert.equal(featureAllowed(state,'ai'),true);assert.equal(featureAllowed(state,'documentScan'),true);assert.equal(featureAllowed(state,'passwords'),false);assert.equal(featureAllowed(state,'agents'),false);assert.equal(sectionAllowed(state,'appearance'),false);
|
|
});
|