309 lines
18 KiB
Python
309 lines
18 KiB
Python
"""Verify candidate store content with the release UI files and Lua 5.1."""
|
|
import argparse
|
|
import hashlib
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import xml.etree.ElementTree as ET
|
|
|
|
import store
|
|
|
|
|
|
EXPORT = store.PREFIX + "blizzard_accountsaveui/blizzard_accountsaveui.lua"
|
|
EXPORT_SHA = "bafce7e9d7fcf84a275eb728bfd9265bd971025949a5bbab7512a684ccb4b295"
|
|
|
|
|
|
def method(text, name):
|
|
pattern = r"^function " + re.escape(name) + r"\([^\n]*\)\n.*?^end\b"
|
|
matches = re.findall(pattern, text, re.MULTILINE | re.DOTALL)
|
|
assert len(matches) == 1, name
|
|
return matches[0]
|
|
|
|
|
|
def check_lua(program):
|
|
result = subprocess.run(["lua5.1", "-"], input=program, capture_output=True, text=True)
|
|
if result.returncode:
|
|
lines = program.splitlines()
|
|
context = re.search(r"stdin:(\d+):", result.stderr)
|
|
location = lines[int(context[1]) - 1] if context else ""
|
|
raise AssertionError(f"Lua 5.1: {result.stderr}\n{location}")
|
|
|
|
|
|
def verify(original, candidate):
|
|
def src(path, source=candidate):
|
|
return source[store.PREFIX + path].decode().replace("\r\n", "\n")
|
|
|
|
def methods(path, *names):
|
|
return "\n".join(method(src(path), name) for name in names) + "\n"
|
|
|
|
def xml(path):
|
|
root = ET.fromstring(src(path))
|
|
for node in root.iter():
|
|
node.tag = node.tag.rsplit("}", 1)[-1]
|
|
return root
|
|
|
|
for path in store.PINS:
|
|
assert candidate[path] != original[path], path
|
|
if path.endswith(".lua"):
|
|
result = subprocess.run(["luac5.1", "-p", "-"], input=candidate[path], capture_output=True)
|
|
assert not result.returncode, (path, result.stderr)
|
|
else:
|
|
root = ET.fromstring(candidate[path])
|
|
# Compile actual inline frame bodies as vararg Lua 5.1 handlers.
|
|
handlers = []
|
|
for node in root.iter():
|
|
if node.tag.rsplit("}", 1)[-1].startswith("On") and (node.text or "").strip():
|
|
handlers.append("function(...)\n" + node.text + "\nend")
|
|
check_lua("local handlers = {\n" + ",\n".join(handlers) + "\n}")
|
|
|
|
old = src(store.STORE + "storeuisecure.lua", original)
|
|
new = src(store.STORE + "storeuisecure.lua")
|
|
for name in ("StoreFrame_BeginPurchase", "StoreConfirmationFinalBuy_OnClick",
|
|
"StoreConfirmationFrame_Cancel", "SourceStore_BeginPurchase", "SourceStore_FinalBuy",
|
|
"SourceStore_CancelConfirmation", "StoreFrameErrorAcceptButton_OnClick"):
|
|
assert method(old, name) == method(new, name), name
|
|
assert old[old.index("-- Appended inside the original"):]==new[new.index("-- Appended inside the original"):]
|
|
for s in ("self.LicenseAcceptButton:SetChecked(false);", "self.BuyButton:Disable();"):
|
|
assert s in new
|
|
assert "C_StoreSecure.PurchaseProductConfirm(false)" in new
|
|
assert method(src(store.CATALOG + ".lua", original), "CatalogShopMixin:PurchaseProduct") == method(src(store.CATALOG + ".lua"), "CatalogShopMixin:PurchaseProduct")
|
|
assert "C_CatalogShop.OnLegalDisclaimerClicked" not in src(store.CATALOG + ".lua") + src(store.CATALOG + "_details.lua")
|
|
assert "GetURLIndexAndLoadURL" not in src(store.STORE + "productcardtemplates.lua")
|
|
assert "BLIZZARD_STORE_CLICK_TO_OPEN_FAQ" not in src(store.STORE + "productcardtemplates.lua")
|
|
assert "LoadURLIndex" not in new
|
|
assert "FRAME_ACTION_BATTLE_NET" not in src(store.CATALOG + "_gamepad.lua")
|
|
assert "C_CatalogShop.OnLegalPersonalizedOptOutClicked" not in src(store.CATALOG + "_productcards.lua")
|
|
assert "C_StoreSecure.OpenNydusLink" not in src(store.STORE + "productcardbuybuttonmixin.lua")
|
|
|
|
for path in (store.CATALOG + ".xml", store.CATALOG + "_elements.xml"):
|
|
page = xml(path)
|
|
assert page.find(".//FontString[@parentKey='LegalDisclaimerText']").get("text") == "Certain restrictions apply."
|
|
assert page.find(".//Frame[@parentKey='ProductsHeader']") is None or path == store.CATALOG + "_elements.xml"
|
|
owner = "CatalogShopDetailsFrame" if path == store.CATALOG + ".xml" else "ProductsHeader"
|
|
assert page.find(f".//Frame[@parentKey='{owner}']").get("hyperlinksEnabled") == "false"
|
|
page = xml(store.STORE + "storeui.xml")
|
|
for key in ("Notice", "LicenseAcceptText", "Disclaimer", "ProductInstructions", "ValidationDescription"):
|
|
assert page.find(f".//SimpleHTML[@parentKey='{key}']") is not None
|
|
assert page.find(f".//SimpleHTML[@parentKey='{key}']//OnHyperlinkClick") is None
|
|
assert page.find(".//CheckButton[@parentKey='LicenseAcceptButton']") is not None
|
|
assert xml(store.STORE + "productcardtemplates.xml").find(".//Button[@parentKey='NydusLinkButton']").get("hidden") == "true"
|
|
bullet = xml(store.STORE + "storeuitemplates.xml").find(".//Frame[@name='StoreBulletPointTemplate']")
|
|
assert bullet.get("hyperlinksEnabled") == "false" and bullet.find(".//OnHyperlinkClick") is None
|
|
promo = xml("blizzard_gluexml/promotionframe.xml").find(".//Frame[@name='PromotionFrame']")
|
|
assert promo.get("hidden") == "true" and promo.find(".//Button[@parentKey='UpgradeButton']") is None
|
|
assert promo.find(".//Button[@parentKey='PlayButton']") is not None
|
|
lobby = xml(store.LOBBY + ".xml")
|
|
assert lobby.find(".//Button[@parentKey='SuscribeButton']") is None
|
|
assert lobby.find(".//FontString[@parentKey='SubRequiredText']") is not None
|
|
checkout = xml(store.CHECKOUT + ".xml")
|
|
assert checkout.find(".//OnExternalLink") is None and checkout.find(".//OnHide") is not None
|
|
|
|
# All forbidden functions are deliberately absent from the Lua environment.
|
|
# Calls to them fail immediately. Use released method bodies, including the
|
|
# retained normal dispatch and layout methods.
|
|
prelude = '''
|
|
local function noop() end
|
|
local function widget()
|
|
return {shown=false, n=0,
|
|
Show=function(s) s.shown=true end, Hide=function(s) s.shown=false end,
|
|
SetShown=function(s,x) s.shown=x end, GetHeight=function() return 7 end,
|
|
SetHeight=function(s,x) s.height=x end, ClearAllPoints=noop,
|
|
SetPoint=function(s,p) s.point=p end, SetText=function(s,x) s.text=x end}
|
|
end
|
|
function PlaySound() end
|
|
SOUNDKIT={}
|
|
'''
|
|
sub_methods = methods(store.SUB, "SubscriptionInterstitialFrameMixin:OnEvent",
|
|
"SubscriptionInterstitialSubscribeButtonBaseMixin:OnClick")
|
|
check_lua(prelude + src(store.UTIL) + '''
|
|
SubscriptionInterstitialFrameMixin={}; SubscriptionInterstitialSubscribeButtonBaseMixin={}
|
|
Enum={SubscriptionInterstitialResponseType={Closed=1,Clicked=2,WebRedirect=3}}
|
|
local answers, displays, hides, toggles = {},0,0,0
|
|
function SendSubscriptionInterstitialResponse(r) table.insert(answers,r) end
|
|
function ShowUIPanel() displays=displays+1 end
|
|
function HideUIPanel() hides=hides+1 end
|
|
function ToggleStoreUI() toggles=toggles+1 end
|
|
local new, products, selected=false,{},nil
|
|
WOW_SUBSCRIPTION_CATEGORY_ID=1; WOW_GAME_TIME_CATEGORY_ID=2
|
|
C_CatalogShop={IsShop2Enabled=function() return new end}
|
|
C_StorePublic={DoesGroupHavePurchaseableProducts=function(id) return products[id] end}
|
|
function StoreFrame_SelectSubscriptionProduct() selected="sub" end
|
|
function StoreFrame_SelectGameTimeProduct() selected="time" end
|
|
CatalogShopInboundInterface={SelectSubscriptionProduct=function() selected="catalog" end}
|
|
''' + sub_methods + '''
|
|
local frame={SetInterstitialType=function(s,t) s.product=t end}
|
|
local event=SubscriptionInterstitialFrameMixin.OnEvent
|
|
local click=SubscriptionInterstitialSubscribeButtonBaseMixin.OnClick
|
|
event(frame,"unrelated"); assert(#answers==0)
|
|
event(frame,"SHOW_SUBSCRIPTION_INTERSTITIAL",4); assert(answers[1]==1 and displays==0)
|
|
assert(not StoreInterfaceUtil.OpenToSubscriptionProduct() and toggles==0)
|
|
products[2]=true; event(frame,"SHOW_SUBSCRIPTION_INTERSTITIAL",4)
|
|
assert(frame.product==4 and displays==1)
|
|
local button={GetParent=function() return frame end}
|
|
click(button); assert(answers[2]==2 and selected=="time" and toggles==1)
|
|
products[1]=true; assert(StoreInterfaceUtil.OpenToSubscriptionProduct() and selected=="sub")
|
|
new=true; assert(StoreInterfaceUtil.OpenToSubscriptionProduct() and selected=="catalog")
|
|
products={}; new=false; click(button); assert(answers[3]==1 and hides==2 and toggles==3)
|
|
''')
|
|
|
|
check_lua(prelude + src(store.PROMO) + '''
|
|
PromotionFrame=widget(); PromotionAwaitingFrame=widget(); StarterEditionPopUp=widget()
|
|
PromotionFrame_OnLoad(PromotionFrame)
|
|
PromotionFrame_OnEvent(PromotionFrame,"DISPLAY_PROMOTION",true,2)
|
|
PromotionFrame_OnEvent(PromotionFrame,"ACCOUNT_DATA_INITIALIZED")
|
|
PromotionAwaitingFrame:Show(); PromotionFrame.receivingMsg=true
|
|
PromotionFrame_AwaitingPromotion(); assert(not PromotionAwaitingFrame.shown and not PromotionFrame.receivingMsg)
|
|
PromotionFrame_ReceivePromotion(PromotionFrame,true,7)
|
|
PromotionFrame_LaunchUpgradeURL(); assert(not PromotionFrame.shown and not StarterEditionPopUp.shown)
|
|
WoWLabsSubscribeButtonMixin={}
|
|
''' + methods(store.LOBBY + ".lua", "WoWLabsSubscribeButtonMixin:OnClick") + "WoWLabsSubscribeButtonMixin:OnClick()")
|
|
|
|
check_lua(prelude + src(store.CHECKOUT + ".lua") + '''
|
|
local frame={declines=0,resizes=0,closes=0,events={},
|
|
RegisterEvent=function(s,e) s.events[e]=true end,UnregisterEvent=function(s,e) s.events[e]=nil end,
|
|
CancelOpenCheckout=function(s) s.declines=s.declines+1 end,CalculateDesiredSize=noop,
|
|
RecalculateSize=function(s) s.resizes=s.resizes+1 end,SetAttribute=noop,
|
|
CloseCheckout=function(s) s.closes=s.closes+1 end}
|
|
SimpleCheckoutOutbound={GetAppropriateTopLevelParent=noop}
|
|
FrameUtil={SetParentMaintainRenderLayering=noop}
|
|
SimpleCheckoutMixin.OnLoad(frame)
|
|
for _,e in ipairs({"STORE_OPEN_SIMPLE_CHECKOUT","CATALOG_SHOP_OPEN_SIMPLE_CHECKOUT"}) do
|
|
assert(frame.events[e]); SimpleCheckoutMixin.OnEvent(frame,e,"id")
|
|
end
|
|
SimpleCheckoutMixin.OnExternalLink(frame)
|
|
SimpleCheckoutMixin.OnEvent(frame,"DISPLAY_SIZE_CHANGED");SimpleCheckoutMixin.OnHide(frame)
|
|
assert(frame.declines==2 and frame.resizes==1 and frame.closes==1)
|
|
''')
|
|
|
|
check_lua(prelude + "StoreBulletPointMixin={}\n" +
|
|
methods(store.STORE + "storeuitemplates.lua", "StoreFrame_WebText", "StoreBulletPointMixin:SetContent") + '''
|
|
local label="before |HurlIndex:14|h|cff71d5ffTerms of Sale|r|h and |HurlIndex:15|hPrivacy|h."
|
|
assert(StoreFrame_WebText(label)=="before Terms of Sale and Privacy.")
|
|
assert(StoreFrame_WebText('<html><p>Read <a href="urlIndex:7">FAQ</a></p></html>')=="<html><p>Read FAQ</p></html>")
|
|
assert(StoreFrame_WebText("|Hitem:123|hItem|h")=="|Hitem:123|hItem|h")
|
|
assert(StoreFrame_WebText(nil)==nil)
|
|
BulletPointWithTextureMixin={SetContent=function(s,x) s.label=x end}
|
|
local b={}; StoreBulletPointMixin.SetContent(b,label); assert(b.label=="before Terms of Sale and Privacy.")
|
|
StoreCardMixin={}; StoreNydusLinkButtonMixin={}
|
|
''' + methods(store.STORE + "productcardtemplates.lua", "StoreCardMixin:OnClick", "StoreCardMixin:GetTooltipDescription") +
|
|
methods(store.STORE + "productcardbuybuttonmixin.lua", "StoreNydusLinkButtonMixin:OnClick") + '''
|
|
local owned=true
|
|
function SourceStore_IsActive() return owned end
|
|
function SourceStore_CardClick(card) return card.marker end
|
|
local card={marker=27,GetEntryInfo=function() return {sharedData={description="ordinary"}} end,
|
|
GetID=function() return 33 end,CanBuyHere=function() return true end,
|
|
AppendBundleInformationToTooltipDescription=function(s,e,d)return d end,
|
|
ShouldAddDiscountInformationToTooltip=function() return false end}
|
|
assert(StoreCardMixin.OnClick(card)==27)
|
|
owned=false; local selected
|
|
StoreProductCard_CheckShowStorePreviewOnClick=function() return false end
|
|
StoreFrame_SetSelectedEntryID=function(i) selected=i end
|
|
StoreProductCard_UpdateAllStates=noop; StoreFrame_UpdateBuyButton=noop
|
|
StoreCardMixin.OnClick(card); assert(selected==33)
|
|
strtrim=function(t) return t end
|
|
assert(StoreCardMixin.GetTooltipDescription(card)=="ordinary")
|
|
StoreNydusLinkButtonMixin:OnClick()
|
|
''')
|
|
check_lua(prelude + "CatalogShopErrorFrameMixin={}; CatalogShopMixin={};\n" +
|
|
methods(store.STORE + "storeuisecure.lua", "StoreFrame_ShowError", "StoreFrameErrorWebsiteButton_OnClick",
|
|
"StoreFrame_BeginPurchase", "StoreConfirmationFinalBuy_OnClick", "StoreConfirmationFrame_Cancel") +
|
|
methods(store.CATALOG + "_elements.lua", "CatalogShopErrorFrameMixin:ShowError") +
|
|
methods(store.CATALOG + ".lua", "CatalogShopMixin:PurchaseProduct") + '''
|
|
local function errFrame()
|
|
local f=widget()
|
|
for _,name in ipairs({"Title","Description","AcceptButton","WebsiteButton","WebsiteWarning"}) do f[name]=widget() end
|
|
f.WebsiteButton:Show(); f.WebsiteWarning:Show(); return f
|
|
end
|
|
OKAY="OK"
|
|
for _,index in ipairs({false,11}) do
|
|
local f=errFrame(); StoreFrame_ShowError({ErrorFrame=f},"title","details",index,true)
|
|
assert(f.Title.text=="title" and f.Description.text=="details" and f.shown and f.height==194)
|
|
assert(f.AcceptButton.point=="BOTTOM" and not f.WebsiteButton.shown and not f.WebsiteWarning.shown)
|
|
f=errFrame(); CatalogShopErrorFrameMixin.ShowError(f,"title","details",index,true)
|
|
assert(f.shown and f.ErrorNeedsAck and f.ActiveURLIndex==nil and f.Description.text=="details")
|
|
assert(f.AcceptButton.point=="BOTTOM" and not f.WebsiteButton.shown and not f.WebsiteWarning.shown)
|
|
end
|
|
StoreFrameErrorWebsiteButton_OnClick()
|
|
SourceStore_IsActive=function() return true end
|
|
SourceStore_BeginPurchase=function(id) return id end
|
|
SourceStore_FinalBuy=function() return "confirmed" end
|
|
SourceStore_CancelConfirmation=function() return "cancelled" end
|
|
assert(StoreFrame_BeginPurchase(14)==14)
|
|
assert(StoreConfirmationFinalBuy_OnClick()=="confirmed" and StoreConfirmationFrame_Cancel()=="cancelled")
|
|
local selected={catalogShopProductID=98}; local routed
|
|
C_CatalogShop={ConfirmHousingPurchase=function(ids) assert(ids[1]==98);routed="housing" end,
|
|
PurchaseProduct=function(id) assert(id==98);routed="product" end}
|
|
local f={GetSelectedProductInfo=function() return selected end}
|
|
CatalogShopMixin.PurchaseProduct(f);assert(routed=="product")
|
|
selected.isVCProduct=true; CatalogShopMixin.PurchaseProduct(f);assert(routed=="housing")
|
|
''')
|
|
|
|
check_lua(prelude + "CatalogShopSectionHeaderOptOutLinkMixin={}; DetailsProductContainerFrameMixin={}\n" +
|
|
methods(store.CATALOG + "_productcards.lua", "CatalogShopSectionHeaderOptOutLinkMixin:OnLoad",
|
|
"CatalogShopSectionHeaderOptOutLinkMixin:OnInfoButton_OnClick",
|
|
"CatalogShopSectionHeaderOptOutLinkMixin:SetHeaderText") +
|
|
methods(store.CATALOG + "_details.lua", "DetailsProductContainerFrameMixin:UpdateProductInfo") + '''
|
|
local f={Help=widget(),headerText=widget()};f.Help:Show()
|
|
C_CatalogShop={GetCategorySectionInfo=function()return {displayName="Names"} end,
|
|
GetCatalogShopProductDisplayInfo=function() return {} end,
|
|
GetProductIDsForBundle=function()return {3,4} end}
|
|
CatalogShopSectionHeaderOptOutLinkMixin.OnLoad(f); assert(not f.Help.shown)
|
|
CatalogShopSectionHeaderOptOutLinkMixin.SetHeaderText(f,{categoryID=1,sectionID=2});assert(f.headerText.text=="Names")
|
|
CatalogShopSectionHeaderOptOutLinkMixin.OnInfoButton_OnClick(f)
|
|
CatalogShopUtil={GetDescriptionText=function()return "desc" end,GetTypeText=function()return "type" end}
|
|
local d={ProductsHeader=widget(),ShadowLayer=widget(),ProductsScrollBoxContainer=widget(),AllDataRefresh=noop}
|
|
d.ProductsHeader.Layout=noop;d.ProductsHeader.Init=function(s,h) s.info=h end
|
|
d.ProductsScrollBoxContainer.ScrollBox={Update=noop}
|
|
for _,bundle in ipairs({false,true}) do
|
|
DetailsProductContainerFrameMixin.UpdateProductInfo(d,{name="Name",isBundle=bundle,catalogShopProductID=3})
|
|
assert(d.ProductsHeader.info.showLegal and d.ProductsHeader.info.Description=="desc" and d.ShadowLayer.shown==bundle)
|
|
end
|
|
''')
|
|
# Run the full gamepad setup with real binding IDs, footer membership and
|
|
# purchase button action. No gamepad or storefront is opened.
|
|
check_lua(prelude + src(store.CATALOG + "_gamepad.lua") + '''
|
|
local bindings,footers={},{}
|
|
for _,name in ipairs({"GAMEPAD_FACE_TOP","GAMEPAD_FACE_BOTTOM","GAMEPAD_FACE_RIGHT","GAMEPAD_SHOULDER_LEFT",
|
|
"GAMEPAD_SHOULDER_RIGHT","GAMEPAD_MENU_LEFT","GAMEPAD_STICK_LEFT","CONTEXT_ACTION_LABEL_DETAILS",
|
|
"CONTEXT_ACTION_LABEL_BUY","FRAME_ACTION_CLOSE","FRAME_ACTION_BATTLE_NET"}) do _G[name]=name end
|
|
GamepadMode={CreateBindingGroup=function() return {AddAxisBinding=noop} end,AddGamepadIconToButton=noop}
|
|
PromptedBindingMixin={VISIBILITY_TYPE={ONLY_IF_USABLE=1}}
|
|
GamepadSharedUtility={CreatePromptedBinding=function(id,act,label)
|
|
local binding={id=id,act=act,label=label,AddCondition=noop,SetVisibilityType=noop,SetCustomPromptFrame=noop}
|
|
bindings[#bindings+1]=binding;return binding end,
|
|
CreatePromptedBindingFooter=function()
|
|
local f={list={},AddPromptedBinding=function(s,b) table.insert(s.list,b) end,Finalize=noop}
|
|
table.insert(footers,f);return f end}
|
|
local hit=false
|
|
local frame={HeaderFrame={CatalogShopNavBar={}},ModelSceneContainerFrame={MainModelScene={}},ProductDetailsContainerFrame={BackButton={}},
|
|
CatalogShopDetailsFrame={ButtonContainer={PurchaseButton={Click=function() hit=true end},GamepadPurchaseButton={},DetailsButton={}}}}
|
|
CatalogShopSetupGamepad(frame)
|
|
assert(#footers==2 and #footers[1].list==7 and #footers[2].list==5)
|
|
for _,b in ipairs(bindings) do assert(b.label~=FRAME_ACTION_BATTLE_NET); if b.label==CONTEXT_ACTION_LABEL_BUY then b.act() end end
|
|
assert(hit)
|
|
''')
|
|
if EXPORT in original:
|
|
assert hashlib.sha256(original[EXPORT]).hexdigest() == EXPORT_SHA
|
|
assert candidate.get(EXPORT, original[EXPORT]) == original[EXPORT]
|
|
assert EXPORT not in store.PINS
|
|
print(f"PASS {len(store.PINS)} pinned file changes, Lua 5.1 behavior, XML bindings and syntax")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("decoded", type=Path)
|
|
args = parser.parse_args()
|
|
files = {path: (args.decoded / path).read_bytes() for path in (*store.PINS, EXPORT)}
|
|
candidate = store.transform(files)
|
|
assert EXPORT not in candidate
|
|
assert candidate == store.transform(files)
|
|
bad = dict(files)
|
|
bad[next(iter(store.PINS))] += b" "
|
|
try:
|
|
store.transform(bad)
|
|
except ValueError as error:
|
|
assert "Unexpected 6838" in str(error)
|
|
else:
|
|
raise AssertionError("Unreviewed bytes accepted")
|
|
verify(files, candidate)
|