11/*
2- * Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+ * Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package com .iexec .commons .poco .tee ;
1818
19- import org .junit .jupiter .api .Assertions ;
2019import org .junit .jupiter .api .Test ;
2120import org .junit .jupiter .params .ParameterizedTest ;
2221import org .junit .jupiter .params .provider .Arguments ;
2726import java .util .stream .Stream ;
2827
2928import static com .iexec .commons .poco .utils .BytesUtils .toByte32HexString ;
29+ import static org .assertj .core .api .Assertions .assertThat ;
3030
3131class TeeUtilsTests {
3232
3333 @ Test
3434 void areValidFields () {
35- Assertions .assertEquals (0b0011, TeeUtils .TEE_SCONE_BITS );
36- Assertions .assertEquals (0b0101, TeeUtils .TEE_GRAMINE_BITS );
37- Assertions .assertEquals ("0x0000000000000000000000000000000000000000000000000000000000000003" ,
38- TeeUtils .TEE_SCONE_ONLY_TAG );
39- Assertions .assertEquals ("0x0000000000000000000000000000000000000000000000000000000000000005" ,
40- TeeUtils .TEE_GRAMINE_ONLY_TAG );
35+ assertThat (TeeUtils .TEE_SCONE_BITS ).isEqualTo (0b0011);
36+ assertThat (TeeUtils .TEE_GRAMINE_BITS ).isEqualTo (0b0101);
37+ assertThat (TeeUtils .TEE_TDX_BITS ).isEqualTo (0b1001);
38+ assertThat (TeeUtils .TEE_SCONE_ONLY_TAG )
39+ .isEqualTo ("0x0000000000000000000000000000000000000000000000000000000000000003" );
40+ assertThat (TeeUtils .TEE_GRAMINE_ONLY_TAG )
41+ .isEqualTo ("0x0000000000000000000000000000000000000000000000000000000000000005" );
42+ assertThat (TeeUtils .TEE_TDX_ONLY_TAG )
43+ .isEqualTo ("0x0000000000000000000000000000000000000000000000000000000000000009" );
4144 }
4245
4346 @ ParameterizedTest
44- @ ValueSource (ints = {
45- 0b0011, // 0x3: Scone
46- 0b0101, // : 0x5: Gramine
47- 0b11110011, // 0xf3: any (above TEE runtime framework mask) + Scone
48- })
47+ @ ValueSource (ints = {0x3 , 0x5 , 0x9 , 0xf3 , 0xf5 , 0xf9 })
4948 void isTeeTag (int tag ) {
50- Assertions . assertTrue (TeeUtils .isTeeTag (toByte32HexString (tag )));
49+ assertThat (TeeUtils .isTeeTag (toByte32HexString (tag ))). isTrue ( );
5150 }
5251
5352 @ ParameterizedTest
5453 @ ValueSource (ints = {
55- 0b0000, // 0x0: empty
56- 0b0001, // 0x1: missing TEE runtime framework
57- 0b1001, // 0x9: no third TEE runtime framework existing for now ({Scone, Gramine, ?})
54+ 0b0000, 0b0001, 0b0010,
55+ 0b0100, 0b0110, 0b0111,
56+ 0b1000, 0b1010, 0b1011,
57+ 0b1100, 0b1101, 0b1110, 0b1111
5858 })
5959 void isNotTeeTag (int tag ) {
60- Assertions . assertFalse (TeeUtils .isTeeTag (toByte32HexString (tag )));
60+ assertThat (TeeUtils .isTeeTag (toByte32HexString (tag ))). isFalse ( );
6161 }
6262
6363 @ ParameterizedTest
64- @ ValueSource (ints = {
65- 0b0011, // 0x3: Scone
66- 0b11110011, // 0xf3: any (above TEE runtime framework mask) + Scone
67- })
68- void hasTeeSconeInTag (int tag ) {
69- Assertions .assertTrue (TeeUtils .hasTeeSconeInTag (toByte32HexString (tag )));
64+ @ ValueSource (ints = {0x3 , 0xf3 })
65+ void hasTeeSconeInTag (final int tag ) {
66+ assertThat (TeeUtils .hasTeeSconeInTag (toByte32HexString (tag ))).isTrue ();
7067 }
7168
72- @ Test
73- void hasNotTeeSconeInTag () {
74- Assertions .assertFalse (TeeUtils .hasTeeSconeInTag (toByte32HexString (0b0101))); // 0x5: Gramine
69+ @ ParameterizedTest
70+ @ ValueSource (ints = {0x5 , 0x9 , 0xf5 , 0xf9 })
71+ void hasNotTeeSconeInTag (final int tag ) {
72+ assertThat (TeeUtils .hasTeeSconeInTag (toByte32HexString (tag ))).isFalse ();
7573 }
7674
7775 @ ParameterizedTest
78- @ ValueSource (ints = {
79- 0b0101, // 0x5: Gramine
80- 0b11110101, // 0xf5: any (above TEE runtime framework mask) + Gramine
81- })
82- void hasTeeGramineInTag (int tag ) {
83- Assertions .assertTrue (TeeUtils .hasTeeGramineInTag (toByte32HexString (tag )));
76+ @ ValueSource (ints = {0x5 , 0xf5 })
77+ void hasTeeGramineInTag (final int tag ) {
78+ assertThat (TeeUtils .hasTeeGramineInTag (toByte32HexString (tag ))).isTrue ();
8479 }
8580
86- @ Test
87- void hasNotTeeGramineInTag () {
88- Assertions .assertFalse (TeeUtils .hasTeeGramineInTag (toByte32HexString (0b0011))); // 0x3: Scone
81+ @ ParameterizedTest
82+ @ ValueSource (ints = {0x3 , 0x9 , 0xf3 , 0xf9 })
83+ void hasNotTeeGramineInTag (final int tag ) {
84+ assertThat (TeeUtils .hasTeeGramineInTag (toByte32HexString (tag ))).isFalse ();
85+ }
86+
87+ @ ParameterizedTest
88+ @ ValueSource (ints = {0x9 , 0xf9 })
89+ void hasTeeTdxInTag (final int tag ) {
90+ assertThat (TeeUtils .hasTeeTdxInTag (toByte32HexString (tag ))).isTrue ();
91+ }
92+
93+ @ ParameterizedTest
94+ @ ValueSource (ints = {0x3 , 0x5 , 0xf3 , 0xf5 })
95+ void hasNotTeeTdxInTag (final int tag ) {
96+ assertThat (TeeUtils .hasTeeTdxInTag (toByte32HexString (tag ))).isFalse ();
8997 }
9098
9199 // ensures some bits are present within TEE runtime framework mask
@@ -101,20 +109,17 @@ static Stream<Arguments> validData() {
101109
102110 @ ParameterizedTest
103111 @ MethodSource ("validData" )
104- void hasTeeRuntimeFrameworkBitsInTag (int expectedBits , int tag ) {
105- Assertions .assertTrue (TeeUtils .hasTeeRuntimeFrameworkBitsInTag (expectedBits ,
106- toByte32HexString (tag )));
112+ void hasTeeRuntimeFrameworkBitsInTag (final int expectedBits , final int tag ) {
113+ assertThat (TeeUtils .hasTeeRuntimeFrameworkBitsInTag (expectedBits , toByte32HexString (tag ))).isTrue ();
107114 }
108115
109116 @ ParameterizedTest
110117 @ NullSource
111118 @ ValueSource (strings = {
112- "abc" , // missing prefix
119+ "abc" , // after mask, 0xc -> 0b1100 does not match expected 0b1010
113120 "0x1" , // no match
114121 })
115122 void hasNotTeeRuntimeFrameworkBitsInTag (String tag ) {
116- int anyBits = 0b1010;
117- Assertions .assertFalse (TeeUtils .hasTeeRuntimeFrameworkBitsInTag (anyBits ,
118- tag ));
123+ assertThat (TeeUtils .hasTeeRuntimeFrameworkBitsInTag (0b1010, tag )).isFalse ();
119124 }
120- }
125+ }
0 commit comments