1717package com .iexec .resultproxy .authorization ;
1818
1919import com .iexec .common .result .ResultModel ;
20- import com .iexec .commons .poco .chain .ChainDeal ;
2120import com .iexec .commons .poco .chain .ChainTask ;
2221import com .iexec .commons .poco .chain .WorkerpoolAuthorization ;
22+ import com .iexec .commons .poco .order .OrderTag ;
2323import com .iexec .commons .poco .security .Signature ;
2424import com .iexec .commons .poco .utils .BytesUtils ;
2525import com .iexec .commons .poco .utils .HashUtils ;
2828import org .junit .jupiter .api .BeforeEach ;
2929import org .junit .jupiter .api .Test ;
3030import org .junit .jupiter .api .extension .ExtendWith ;
31+ import org .junit .jupiter .params .ParameterizedTest ;
32+ import org .junit .jupiter .params .provider .EnumSource ;
3133import org .mockito .Mock ;
3234import org .mockito .junit .jupiter .MockitoExtension ;
3335import org .springframework .beans .factory .annotation .Autowired ;
6365@ ExtendWith (MockitoExtension .class )
6466class AuthorizationServiceTests {
6567
66- private static final String RESULT_DIGEST = "0x3210" ;
67-
6868 @ Container
6969 private static final MongoDBContainer mongoDBContainer = new MongoDBContainer (DockerImageName .parse (System .getProperty ("mongo.image" )));
7070
@@ -93,13 +93,12 @@ void beforeEach() throws GeneralSecurityException {
9393 }
9494
9595 // region isAuthorizedOnExecutionWithDetailedIssue
96- @ Test
97- void shouldBeAuthorizedOnExecutionOfTeeTaskWithDetails () {
98- final ChainDeal chainDeal = getChainDeal ();
99- final ChainTask chainTask = getChainTask (ACTIVE );
96+ @ ParameterizedTest
97+ @ EnumSource (value = OrderTag .class , names = "STANDARD" , mode = EnumSource .Mode .EXCLUDE )
98+ void shouldBeAuthorizedOnExecutionOfTeeTaskWithDetails (final OrderTag tag ) {
10099 final WorkerpoolAuthorization auth = getWorkerpoolAuthorization (true );
101- when (iexecHubService .getChainTask (auth .getChainTaskId ())).thenReturn (Optional . of ( chainTask ));
102- when (iexecHubService .getChainDeal (chainTask . getDealid ())) .thenReturn (Optional . of ( chainDeal ));
100+ when (iexecHubService .getChainTask (auth .getChainTaskId ())).thenReturn (getChainTask ( ACTIVE ));
101+ when (iexecHubService .getChainDeal (CHAIN_DEAL_ID )) .thenReturn (getChainDeal ( tag ));
103102
104103 final Optional <AuthorizationError > isAuth = authorizationService .isAuthorizedOnExecutionWithDetailedIssue (auth );
105104 assertThat (isAuth ).isEmpty ();
@@ -118,17 +117,16 @@ void shouldNotBeAuthorizedOnExecutionOfTeeTaskWithEmptyAuthorizationWithDetails(
118117 assertThat (isAuth ).isEqualTo (Optional .of (EMPTY_PARAMS_UNAUTHORIZED ));
119118 }
120119
121- @ Test
122- void shouldNotBeAuthorizedOnExecutionOfTeeTaskWhenTaskTypeNotMatchedOnchainWithDetails () {
123- final ChainDeal chainDeal = getChainDeal ();
124- final ChainTask chainTask = getChainTask (ACTIVE );
120+ @ ParameterizedTest
121+ @ EnumSource (value = OrderTag .class , names = "STANDARD" , mode = EnumSource .Mode .EXCLUDE )
122+ void shouldNotBeAuthorizedOnExecutionOfTeeTaskWhenTaskTypeNotMatchedOnchainWithDetails (final OrderTag tag ) {
125123 final WorkerpoolAuthorization auth = WorkerpoolAuthorization .builder ()
126124 .chainTaskId ("0x1111111111111111111111111111111111111111111111111111111111111111" )
127125 .workerWallet ("0x87ae2b87b5db23830572988fb1f51242fbc471ce" )
128126 .enclaveChallenge (BytesUtils .EMPTY_ADDRESS )
129127 .build ();
130- when (iexecHubService .getChainTask (auth .getChainTaskId ())).thenReturn (Optional . of ( chainTask ));
131- when (iexecHubService .getChainDeal (chainTask . getDealid ())) .thenReturn (Optional . of ( chainDeal ));
128+ when (iexecHubService .getChainTask (auth .getChainTaskId ())).thenReturn (getChainTask ( ACTIVE ));
129+ when (iexecHubService .getChainDeal (CHAIN_DEAL_ID )) .thenReturn (getChainDeal ( tag ));
132130
133131 final Optional <AuthorizationError > isAuth = authorizationService .isAuthorizedOnExecutionWithDetailedIssue (auth );
134132 assertThat (isAuth ).isEqualTo (Optional .of (NO_MATCH_ONCHAIN_TYPE ));
@@ -158,26 +156,24 @@ void shouldNotBeAuthorizedOnExecutionOfTeeTaskWhenFinalDeadlineReached() {
158156
159157 @ Test
160158 void shouldNotBeAuthorizedOnExecutionOfTeeTaskWhenGetDealFailedWithDetails () {
161- final ChainTask chainTask = getChainTask (ACTIVE );
162159 final Signature wrongSignature = new Signature (POOL_WRONG_SIGNATURE );
163160 final WorkerpoolAuthorization auth = getWorkerpoolAuthorizationWithWrongSignature (wrongSignature );
164161
165- when (iexecHubService .getChainTask (auth . getChainTaskId ())) .thenReturn (Optional . of ( chainTask ));
166- when (iexecHubService .getChainDeal (chainTask . getDealid () )).thenReturn (Optional .empty ());
162+ when (iexecHubService .getChainTask (CHAIN_TASK_ID )) .thenReturn (getChainTask ( ACTIVE ));
163+ when (iexecHubService .getChainDeal (CHAIN_DEAL_ID )).thenReturn (Optional .empty ());
167164
168165 final Optional <AuthorizationError > isAuth = authorizationService .isAuthorizedOnExecutionWithDetailedIssue (auth );
169166 assertThat (isAuth ).isEqualTo (Optional .of (GET_CHAIN_DEAL_FAILED ));
170167 }
171168
172- @ Test
173- void shouldNotBeAuthorizedOnExecutionOfTeeTaskWhenPoolSignatureIsNotValidWithDetails () {
174- final ChainDeal chainDeal = getChainDeal ();
175- final ChainTask chainTask = getChainTask (ACTIVE );
169+ @ ParameterizedTest
170+ @ EnumSource (value = OrderTag .class , names = "STANDARD" , mode = EnumSource .Mode .EXCLUDE )
171+ void shouldNotBeAuthorizedOnExecutionOfTeeTaskWhenPoolSignatureIsNotValidWithDetails (final OrderTag tag ) {
176172 final Signature wrongSignature = new Signature (POOL_WRONG_SIGNATURE );
177173 final WorkerpoolAuthorization auth = getWorkerpoolAuthorizationWithWrongSignature (wrongSignature );
178174
179- when (iexecHubService .getChainTask (auth .getChainTaskId ())).thenReturn (Optional . of ( chainTask ));
180- when (iexecHubService .getChainDeal (chainTask . getDealid ())) .thenReturn (Optional . of ( chainDeal ));
175+ when (iexecHubService .getChainTask (auth .getChainTaskId ())).thenReturn (getChainTask ( ACTIVE ));
176+ when (iexecHubService .getChainDeal (CHAIN_DEAL_ID )) .thenReturn (getChainDeal ( tag ));
181177
182178 final Optional <AuthorizationError > isAuth = authorizationService .isAuthorizedOnExecutionWithDetailedIssue (auth );
183179 assertThat (isAuth ).isEqualTo (Optional .of (INVALID_SIGNATURE ));
@@ -277,7 +273,7 @@ void shouldNotAddAuthorizationTwiceInCollection() {
277273 // endregion
278274
279275 // region utils
280- String getEnclaveSignature (final ECKeyPair ecKeyPair ) {
276+ private String getEnclaveSignature (final ECKeyPair ecKeyPair ) {
281277 final String resultHash = HashUtils .concatenateAndHash (CHAIN_TASK_ID , RESULT_DIGEST );
282278 final String resultSeal = HashUtils .concatenateAndHash (workerCreds .getAddress (), CHAIN_TASK_ID , RESULT_DIGEST );
283279 final String messageHash = HashUtils .concatenateAndHash (resultHash , resultSeal );
0 commit comments