diff --git a/build.gradle.kts b/build.gradle.kts index e73d80f..325ff5d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,6 +52,8 @@ tasks { useJUnitPlatform() testLogging { exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL } } + + compileTestKotlin { compilerOptions { javaParameters = true } } } val generatedSourcesDir = layout.buildDirectory.dir("generated") diff --git a/src/test/kotlin/ExtensionTest.kt b/src/test/kotlin/ExtensionTest.kt index eb9dda4..3b5efb8 100644 --- a/src/test/kotlin/ExtensionTest.kt +++ b/src/test/kotlin/ExtensionTest.kt @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.android.keyattestation.verifier import com.android.keyattestation.verifier.testing.Chains @@ -27,10 +26,15 @@ import com.google.common.truth.Truth.assertThat import com.google.protobuf.ByteString import com.google.testing.junit.testparameterinjector.TestParameter import com.google.testing.junit.testparameterinjector.TestParameterInjector +import com.google.testing.junit.testparameterinjector.TestParameters +import com.google.testing.junit.testparameterinjector.TestParameters.TestParametersValues +import com.google.testing.junit.testparameterinjector.TestParametersValuesProvider import java.time.YearMonth import kotlin.io.path.Path import kotlin.io.path.inputStream +import kotlin.io.path.isDirectory import kotlin.io.path.listDirectoryEntries +import kotlin.io.path.name import kotlin.io.path.nameWithoutExtension import kotlin.io.path.readText import kotlin.io.path.reader @@ -54,23 +58,46 @@ class ExtensionTest { } @Test - fun parseFrom_success(@TestParameter testCase: TestCase) { - val path = testData.resolve("${testCase.model}/sdk${testCase.sdk}") + @TestParameters(valuesProvider = TestCaseProvider::class) + fun parseFrom_success(model: String, sdk: Int) { + val path = testData.resolve("${model}/sdk${sdk}") val chainMap = path.listDirectoryEntries("*.pem").map { Pair(it, Path("${it.parent}/${it.nameWithoutExtension}.json")) } - for ((pemPath, jsonPath) in chainMap) { assertThat(KeyDescription.parseFrom(readCertPath(pemPath.reader()).leafCert())) .isEqualTo(jsonPath.readText().toKeyDescription()) } } - enum class TestCase(val model: String, val sdk: Int) { - PIXEL_SDK29("marlin", 29), - PIXEL_3_SDK28("blueline", 28), - PIXEL_8A_SDK34("akita", 34), + class TestCaseProvider : TestParametersValuesProvider() { + override fun provideValues(context: Context): List { + val root = Path("testdata") + val parameters = + root + .listDirectoryEntries() + .filter { it.isDirectory() } + .flatMap { modelDir -> + modelDir + .listDirectoryEntries("sdk*") + .filter { it.isDirectory() } + .mapNotNull { sdkDir -> + val sdkVersion = sdkDir.name.removePrefix("sdk").toIntOrNull() + if (sdkVersion == null) { + null + } else { + TestParametersValues.builder() + .name("${modelDir.name}_sdk$sdkVersion") + .addParameter("model", modelDir.name) + .addParameter("sdk", sdkVersion) + .build() + } + } + } + assertThat(parameters).isNotEmpty() + return parameters + } } @Test diff --git a/testdata/README.md b/testdata/README.md deleted file mode 100644 index 46267b9..0000000 --- a/testdata/README.md +++ /dev/null @@ -1,12 +0,0 @@ -## Installing TestDPC - -```shell -$ bash third_party/java_src/testdpc/build-and-install.sh -$ adb -s localhost:45681 shell dpm set-device-owner com.afwsamples.testdpc/.DeviceAdminReceiver -``` - -# Running the Attestation Collector app - -```shell -$ blaze run //java/com/google/wireless/android/security/attestationverifier:RegenerateTestData -``` diff --git a/testdata/tegu/sdk36/TEE_EC_2026_ROOT.json b/testdata/tegu/sdk36/TEE_EC_2026_ROOT.json index 9c36b87..7c61ee9 100644 --- a/testdata/tegu/sdk36/TEE_EC_2026_ROOT.json +++ b/testdata/tegu/sdk36/TEE_EC_2026_ROOT.json @@ -1,3 +1,4 @@ +// Test data from a preproduction Pixel 9a { "attestationVersion": "400", "attestationSecurityLevel": "TRUSTED_ENVIRONMENT", @@ -6,14 +7,15 @@ "attestationChallenge": "NjQxN2Y5MmMtZGFlZi00Y2MxLTg4MjgtNWJiMzkzMzhmZmQ1", "uniqueId": "", "softwareEnforced": { - "creationDateTime": "1758900680964", + "creationDateTime": "1771894563060", "attestationApplicationId": { "packages": [ { "name": "com.google.android.attestation", "version": "0" } ], "signatures": ["EDk47kU35Z6O55L2VFBPuDRvxrNG0LvEQV/DOfz8jsE="] }, - "moduleHash": "9LgYqeXS71yyjWDapgmLq8vfI/9ugHeO+C1+Qe9Ill4=" + "moduleHash": "9LgYqeXS71yyjWDapgmLq8vfI/9ugHeO+C1+Qe9Ill4=", + "areTagsOrdered": true }, "hardwareEnforced": { "purposes": ["2", "3"], @@ -31,12 +33,10 @@ }, "osVersion": "160000", "osPatchLevel": "202602", - "attestationIdBrand": "google", - "attestationIdDevice": "tegu", - "attestationIdProduct": "tegu", - "attestationIdManufacturer": "Google", - "attestationIdModel": "Pixel 9a", "vendorPatchLevel": "20260205", - "bootPatchLevel": "20260205" + "bootPatchLevel": "20260205", + // Not all device fields are populated, as a pre-production test + // device was used. This device was not fully provisioned. + "areTagsOrdered": true } }