@@ -18,20 +18,24 @@ describe("DstackApp", function () {
1818 beforeEach ( async function ( ) {
1919 [ owner , user ] = await ethers . getSigners ( ) ;
2020 appAuth = await deployContract ( hre , "DstackApp" , [
21- owner . address ,
21+ owner . address ,
2222 false , // _disableUpgrades
2323 false , // _requireTcbUpToDate
2424 true , // _allowAnyDevice
2525 ethers . ZeroHash , // initialDeviceId (empty)
2626 ethers . ZeroHash // initialComposeHash (empty)
27- ] , true ) as DstackApp ;
27+ ] , true , "initialize(address,bool,bool,bool,bytes32,bytes32)" ) as DstackApp ;
2828 appId = await appAuth . getAddress ( ) ;
2929 } ) ;
3030
3131 describe ( "Basic functionality" , function ( ) {
3232 it ( "Should set the correct owner" , async function ( ) {
3333 expect ( await appAuth . owner ( ) ) . to . equal ( owner . address ) ;
3434 } ) ;
35+
36+ it ( "Should return version 2" , async function ( ) {
37+ expect ( await appAuth . version ( ) ) . to . equal ( 2 ) ;
38+ } ) ;
3539 } ) ;
3640
3741 describe ( "Compose hash management" , function ( ) {
@@ -62,6 +66,68 @@ describe("DstackApp", function () {
6266 } ) ;
6367 } ) ;
6468
69+ describe ( "TCB requirement via initialize" , function ( ) {
70+ it ( "Should reject outdated TCB when initialized with requireTcbUpToDate=true" , async function ( ) {
71+ const tcbApp = await deployContract ( hre , "DstackApp" , [
72+ owner . address ,
73+ false , // _disableUpgrades
74+ true , // _requireTcbUpToDate
75+ true , // _allowAnyDevice
76+ ethers . ZeroHash ,
77+ ethers . ZeroHash
78+ ] , true , "initialize(address,bool,bool,bool,bytes32,bytes32)" ) as DstackApp ;
79+
80+ const composeHash = ethers . randomBytes ( 32 ) ;
81+ await tcbApp . addComposeHash ( composeHash ) ;
82+
83+ const bootInfo = {
84+ appId : await tcbApp . getAddress ( ) ,
85+ composeHash,
86+ instanceId : ethers . Wallet . createRandom ( ) . address ,
87+ deviceId : ethers . randomBytes ( 32 ) ,
88+ mrAggregated : ethers . randomBytes ( 32 ) ,
89+ mrSystem : ethers . randomBytes ( 32 ) ,
90+ osImageHash : ethers . randomBytes ( 32 ) ,
91+ tcbStatus : "OutOfDate" ,
92+ advisoryIds : [ ]
93+ } ;
94+
95+ const [ isAllowed , reason ] = await tcbApp . isAppAllowed ( bootInfo ) ;
96+ expect ( isAllowed ) . to . be . false ;
97+ expect ( reason ) . to . equal ( "TCB status is not up to date" ) ;
98+ } ) ;
99+
100+ it ( "Should allow UpToDate TCB when initialized with requireTcbUpToDate=true" , async function ( ) {
101+ const tcbApp = await deployContract ( hre , "DstackApp" , [
102+ owner . address ,
103+ false ,
104+ true , // _requireTcbUpToDate
105+ true , // _allowAnyDevice
106+ ethers . ZeroHash ,
107+ ethers . ZeroHash
108+ ] , true , "initialize(address,bool,bool,bool,bytes32,bytes32)" ) as DstackApp ;
109+
110+ const composeHash = ethers . randomBytes ( 32 ) ;
111+ await tcbApp . addComposeHash ( composeHash ) ;
112+
113+ const bootInfo = {
114+ appId : await tcbApp . getAddress ( ) ,
115+ composeHash,
116+ instanceId : ethers . Wallet . createRandom ( ) . address ,
117+ deviceId : ethers . randomBytes ( 32 ) ,
118+ mrAggregated : ethers . randomBytes ( 32 ) ,
119+ mrSystem : ethers . randomBytes ( 32 ) ,
120+ osImageHash : ethers . randomBytes ( 32 ) ,
121+ tcbStatus : "UpToDate" ,
122+ advisoryIds : [ ]
123+ } ;
124+
125+ const [ isAllowed , reason ] = await tcbApp . isAppAllowed ( bootInfo ) ;
126+ expect ( isAllowed ) . to . be . true ;
127+ expect ( reason ) . to . equal ( "" ) ;
128+ } ) ;
129+ } ) ;
130+
65131 describe ( "isAppAllowed" , function ( ) {
66132 const composeHash = ethers . randomBytes ( 32 ) ;
67133 const deviceId = ethers . randomBytes ( 32 ) ;
@@ -160,8 +226,9 @@ describe("DstackApp", function () {
160226 appAuthWithData = await hre . upgrades . deployProxy (
161227 contractFactory ,
162228 [ owner . address , false , false , false , testDevice , testHash ] ,
163- {
164- kind : 'uups'
229+ {
230+ kind : 'uups' ,
231+ initializer : 'initialize(address,bool,bool,bool,bytes32,bytes32)'
165232 }
166233 ) as DstackApp ;
167234
@@ -260,7 +327,8 @@ describe("DstackApp", function () {
260327 contractFactory ,
261328 [ owner . address , false , false , false , ethers . ZeroHash , ethers . ZeroHash ] ,
262329 {
263- kind : 'uups'
330+ kind : 'uups' ,
331+ initializer : 'initialize(address,bool,bool,bool,bytes32,bytes32)'
264332 }
265333 ) as DstackApp ;
266334
0 commit comments