883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
63 lines
4.3 KiB
Python
63 lines
4.3 KiB
Python
"""Owned-file rollback and read-only Lua capabilities; no actual client input."""
|
|
from pathlib import Path
|
|
import json,subprocess,sys,tempfile
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
import native_glue_addon_probe as probe
|
|
|
|
def rejects(action):
|
|
try:action()
|
|
except RuntimeError:return
|
|
raise AssertionError('Unsafe or unrelated probe operation accepted')
|
|
with tempfile.TemporaryDirectory(prefix='gateway-glue-probe-') as tmp:
|
|
root=Path(tmp);probe.ROOT=root;probe.TARGET=root/'runtime/native-client/_classic_beta_/Interface/AddOns'/probe.ADDON;probe.JOURNAL=root/'runtime/install.json'
|
|
stage=root/'runtime/stage';staged=probe.stage(stage)
|
|
assert staged['load_verified'] is False and not probe.TARGET.exists()
|
|
assert probe.stage(stage)==staged
|
|
rejects(lambda:probe.stage(root/'runtime/native-client/unsafe-stage'))
|
|
def live():raise RuntimeError('Mock active client')
|
|
probe.closed_client=live
|
|
rejects(lambda:probe.install(stage));assert not probe.TARGET.exists() and not probe.JOURNAL.exists()
|
|
probe.closed_client=lambda:None
|
|
installed=probe.install(stage);assert probe.tree(probe.TARGET)==staged['files']
|
|
# Changed user content must survive a rejected rollback.
|
|
lua=probe.TARGET/'GlueProbe.lua';original=lua.read_bytes();lua.write_bytes(original+b'-- unrelated edit\n')
|
|
rejects(probe.restore);assert lua.read_bytes().endswith(b'-- unrelated edit\n')
|
|
lua.write_bytes(original);restored=probe.restore()
|
|
assert restored['files']=={} and not probe.TARGET.exists() and (root/installed['recovery']/'removed-addon').is_dir()
|
|
assert probe.restore()==restored
|
|
# A third-party folder at the name is never overwritten.
|
|
probe.TARGET.mkdir();(probe.TARGET/'third-party.txt').write_text('keep')
|
|
rejects(lambda:probe.install(stage));assert (probe.TARGET/'third-party.txt').read_text()=='keep'
|
|
(probe.TARGET/'third-party.txt').unlink();probe.TARGET.rmdir()
|
|
installed=probe.install(stage)
|
|
# Simulate a previous hash-owned revision and verify its exact restoration.
|
|
previous=original+b'-- owned previous revision\n';lua.write_bytes(previous)
|
|
owned=json.loads(probe.JOURNAL.read_text());owned['files']=probe.tree(probe.TARGET);probe.write_json(probe.JOURNAL,owned)
|
|
replacement=probe.install(stage)
|
|
assert (root/replacement['recovery']/'previous-addon/GlueProbe.lua').read_bytes()==previous
|
|
probe.restore();assert lua.read_bytes()==previous
|
|
# Staged marker syntax/purpose remains independent of install machinery.
|
|
source=stage/probe.ADDON/'GlueProbe.lua'
|
|
mock=r'''
|
|
local logs,events={},{};
|
|
C_Log={LogMessage=function(v)logs[#logs+1]=v end};
|
|
function CreateFrame()local f={};function f:RegisterEvent(e)events[e]=true end;function f:SetScript(_,cb)self.callback=cb;observer=self end;return f end
|
|
function SetCVar()error('No state mutation allowed')end
|
|
function hooksecurefunc()error('No hooks allowed')end
|
|
if arg[2]=='glue' then
|
|
GlueParentMixin={};GlueParent={};AccountLogin={UI={AccountEditBox={GetText=function()error('No credential read')end}}};
|
|
C_Login={GetState=function()return {connectedToWoW=true,hasRealmList=true,superDistrictChoicePending=false,waitingForRuleSets=false,password='SENSITIVE_SENTINEL'}end,Login=function()error('No authentication action')end};
|
|
C_RealmList={GetAvailableCategories=function()return {1,2}end,GetRealmsInCategory=function(c)return c==1 and {10,11} or {12}end};
|
|
end
|
|
dofile(arg[1]);assert(#logs==1 and logs[1]:find('GW_GLUE_ADDON_PROBE revision=1',1,true));
|
|
assert(events.FRAMES_LOADED and events.LOGIN_STATE_CHANGED and events.REALM_LIST_UPDATED);
|
|
if arg[2]=='glue' then
|
|
assert(logs[1]:find('context=glue-model-present',1,true));assert(logs[1]:find('categories=2 realms=3',1,true));
|
|
else assert(logs[1]:find('context=game-or-other',1,true));end
|
|
for _,s in ipairs(logs)do assert(not s:find('SENSITIVE_SENTINEL',1,true))end
|
|
for i=1,40 do observer.callback(observer,'LOGIN_STATE_CHANGED')end
|
|
assert(#logs==2); -- repeated unchanged state is de-duplicated
|
|
'''
|
|
for mode in ('glue','game'):subprocess.run(['lua','-',str(source),mode],input=mock.encode(),check=True)
|
|
print('Probe staging leaves client untouched; live/foreign/changed files reject, owned rollback preserves previous bytes, and actual Lua logs bounded public Glue-vs-game context without hooks/actions/credentials. Real Glue discovery remains unverified.')
|