訂判斷及所需輸入
SYNTHETIC_ONLY 只是測試標記,不是憑證。本例只容伺服器使用;錯生成器把它直接寫進客戶端源碼,畫面仍 Demo。更正省略該客戶端設定,Demo 照留。
| 情況 | 輸入 JSON |
|---|---|
| 原例測試 | {"syntheticToken":"SYNTHETIC_ONLY","serverOnly":true} |
跑所附比較
固定生成源碼真正本地執行,再核位元組。藏畫面欄不會移除已內嵌字面值;沒有真憑證或供應商設定。
| 路徑 | 輸出 JSON |
|---|---|
| 錯誤路徑 | {"clientContainsToken":true,"publicLabel":"Demo"} |
| 所需路徑 | {"clientContainsToken":false,"publicLabel":"Demo"} |
import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
if(typeof i.syntheticToken!=='string'||!i.syntheticToken||typeof i.serverOnly!=='boolean')return {held:true};
const clientConfig=corrected&&i.serverOnly?{}:{token:i.syntheticToken};
const clientSource='return '+JSON.stringify({label:'Demo',config:clientConfig})+';';
const rendered=Function(clientSource)();
return {clientContainsToken:Buffer.from(clientSource).includes(Buffer.from(i.syntheticToken)),publicLabel:rendered.label};
};
const cases=[{"input":{"syntheticToken":"SYNTHETIC_ONLY","serverOnly":true},"corrected":false,"expected":{"clientContainsToken":true,"publicLabel":"Demo"}},{"input":{"syntheticToken":"SYNTHETIC_ONLY","serverOnly":true},"corrected":true,"expected":{"clientContainsToken":false,"publicLabel":"Demo"}},{"input":{"syntheticToken":"PUBLIC_LABEL","serverOnly":false},"corrected":true,"expected":{"clientContainsToken":true,"publicLabel":"Demo"}},{"input":{"syntheticToken":null,"serverOnly":true},"corrected":true,"expected":{"held":true}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
按邊界依據作判斷
明訂公開標記可出現;標記欠缺便停,空字串配對不能確立有意思的排除。
- 核設定可到哪一層
- 生成客戶端內容
- 核位元組及公開結果
只用無害標記,不貼真實憑證。
| 條件 | 輸入 JSON | 預期輸出 JSON |
|---|---|---|
| 設定明訂可公開 | {"syntheticToken":"PUBLIC_LABEL","serverOnly":false} | {"clientContainsToken":true,"publicLabel":"Demo"} |
| 測試設定欠缺 | {"syntheticToken":null,"serverOnly":true} | {"held":true} |
原例更正後示範了甚麼?
查看參考答案
這些客戶端位元組沒有伺服器專用標記,Demo 仍顯示;未確認所有可能帶秘密的輸出。