1616
1717package com .iexec .worker .tee .scone ;
1818
19+ import com .iexec .common .replicate .ReplicateStatusCause ;
1920import com .iexec .commons .poco .task .TaskDescription ;
2021import com .iexec .commons .poco .tee .TeeEnclaveConfiguration ;
2122import com .iexec .sms .api .SmsClient ;
2526import com .iexec .sms .api .config .TeeAppProperties ;
2627import com .iexec .worker .sgx .SgxService ;
2728import com .iexec .worker .sms .SmsService ;
28- import com .iexec .worker .tee .TeeServicesPropertiesCreationException ;
2929import com .iexec .worker .tee .TeeServicesPropertiesService ;
3030import com .iexec .worker .workflow .WorkflowError ;
3131import org .junit .jupiter .api .Test ;
3232import org .junit .jupiter .api .extension .ExtendWith ;
33+ import org .junit .jupiter .params .ParameterizedTest ;
34+ import org .junit .jupiter .params .provider .EnumSource ;
3335import org .mockito .InjectMocks ;
3436import org .mockito .Mock ;
3537import org .mockito .junit .jupiter .MockitoExtension ;
@@ -99,7 +101,7 @@ void shouldTeeNotBeEnabled() {
99101 void shouldTeePrerequisiteMetForTask () {
100102 when (sgxService .isSgxEnabled ()).thenReturn (true );
101103 when (smsService .getSmsClient (CHAIN_TASK_ID )).thenReturn (smsClient );
102- when (teeServicesPropertiesService .getTeeServicesProperties (CHAIN_TASK_ID )).thenReturn (null );
104+ when (teeServicesPropertiesService .retrieveTeeServicesProperties (CHAIN_TASK_ID )).thenReturn (List . of () );
103105 when (lasServicesManager .startLasService (CHAIN_TASK_ID )).thenReturn (true );
104106
105107 final List <WorkflowError > teePrerequisitesIssue =
@@ -109,7 +111,7 @@ void shouldTeePrerequisiteMetForTask() {
109111
110112 verify (sgxService , times (2 )).isSgxEnabled ();
111113 verify (smsService ).getSmsClient (CHAIN_TASK_ID );
112- verify (teeServicesPropertiesService ).getTeeServicesProperties (CHAIN_TASK_ID );
114+ verify (teeServicesPropertiesService ).retrieveTeeServicesProperties (CHAIN_TASK_ID );
113115 verify (lasServicesManager ).startLasService (CHAIN_TASK_ID );
114116 }
115117
@@ -143,47 +145,31 @@ void shouldTeePrerequisiteNotMetForTaskSinceSmsClientCantBeLoaded() {
143145 verifyNoInteractions (teeServicesPropertiesService , lasServicesManager );
144146 }
145147
146- @ Test
147- void shouldTeePrerequisiteNotMetForTaskSinceTeeWorkflowConfigurationCantBeLoaded () {
148+ @ ParameterizedTest
149+ @ EnumSource (value = ReplicateStatusCause .class , names = {"PRE_COMPUTE_MISSING_ENCLAVE_CONFIGURATION" , "GET_TEE_SERVICES_CONFIGURATION_FAILED" })
150+ void shouldTeePrerequisiteNotMetForTaskSinceTeeWorkflowConfigurationCantBeLoaded (final ReplicateStatusCause cause ) {
148151 when (sgxService .isSgxEnabled ()).thenReturn (true );
149152 when (smsService .getSmsClient (CHAIN_TASK_ID )).thenReturn (smsClient );
150- when (teeServicesPropertiesService .getTeeServicesProperties (CHAIN_TASK_ID ))
151- .thenThrow ( TeeServicesPropertiesCreationException . class );
153+ when (teeServicesPropertiesService .retrieveTeeServicesProperties (CHAIN_TASK_ID ))
154+ .thenReturn ( List . of ( new WorkflowError ( cause )) );
152155
153156 final List <WorkflowError > teePrerequisitesIssue =
154157 teeSconeService .areTeePrerequisitesMetForTask (CHAIN_TASK_ID );
155158
156159 assertThat (teePrerequisitesIssue )
157- .containsExactly (new WorkflowError (GET_TEE_SERVICES_CONFIGURATION_FAILED ));
160+ .containsExactly (new WorkflowError (cause ));
158161
159162 verify (sgxService , times (2 )).isSgxEnabled ();
160163 verify (smsService ).getSmsClient (CHAIN_TASK_ID );
161- verify (teeServicesPropertiesService ).getTeeServicesProperties (CHAIN_TASK_ID );
162- verifyNoInteractions (lasServicesManager );
163- }
164-
165- @ Test
166- void shouldTeePrerequisitesNotBeMetSinceTeeEnclaveConfigurationIsNull () {
167- when (sgxService .isSgxEnabled ()).thenReturn (true );
168- when (smsService .getSmsClient (CHAIN_TASK_ID )).thenReturn (smsClient );
169- when (teeServicesPropertiesService .getTeeServicesProperties (CHAIN_TASK_ID ))
170- .thenThrow (NullPointerException .class );
171-
172- final List <WorkflowError > teePrerequisitesIssue =
173- teeSconeService .areTeePrerequisitesMetForTask (CHAIN_TASK_ID );
174- assertThat (teePrerequisitesIssue )
175- .containsExactly (new WorkflowError (PRE_COMPUTE_MISSING_ENCLAVE_CONFIGURATION ));
176- verify (sgxService , times (2 )).isSgxEnabled ();
177- verify (smsService ).getSmsClient (CHAIN_TASK_ID );
178- verify (teeServicesPropertiesService ).getTeeServicesProperties (CHAIN_TASK_ID );
164+ verify (teeServicesPropertiesService ).retrieveTeeServicesProperties (CHAIN_TASK_ID );
179165 verifyNoInteractions (lasServicesManager );
180166 }
181167
182168 @ Test
183169 void shouldTeePrerequisiteNotMetForTaskSinceCantPrepareTee () {
184170 when (sgxService .isSgxEnabled ()).thenReturn (true );
185171 when (smsService .getSmsClient (CHAIN_TASK_ID )).thenReturn (smsClient );
186- when (teeServicesPropertiesService .getTeeServicesProperties (CHAIN_TASK_ID )).thenReturn (null );
172+ when (teeServicesPropertiesService .retrieveTeeServicesProperties (CHAIN_TASK_ID )).thenReturn (List . of () );
187173 when (lasServicesManager .startLasService (CHAIN_TASK_ID )).thenReturn (false );
188174
189175 final List <WorkflowError > teePrerequisitesIssue =
@@ -194,7 +180,7 @@ void shouldTeePrerequisiteNotMetForTaskSinceCantPrepareTee() {
194180
195181 verify (sgxService , times (2 )).isSgxEnabled ();
196182 verify (smsService ).getSmsClient (CHAIN_TASK_ID );
197- verify (teeServicesPropertiesService ).getTeeServicesProperties (CHAIN_TASK_ID );
183+ verify (teeServicesPropertiesService ).retrieveTeeServicesProperties (CHAIN_TASK_ID );
198184 verify (lasServicesManager ).startLasService (CHAIN_TASK_ID );
199185 }
200186 // endregion
0 commit comments