Add test for missing certificate with AllowMissingDependencies

Add a test that verifies that that missing certificate path inserted
when AllowMissingDependencies is set uses a well formed extension
that won't trip up sign_target_files_apks.

Fixes: 259861670
Test: TestCertificates
Change-Id: I00656809698aed5f9d3aaadaecda9848d2882223
This commit is contained in:
Colin Cross 2022-12-12 15:11:46 -08:00
parent c576383336
commit 5caad2b138

View file

@ -1490,6 +1490,7 @@ func TestCertificates(t *testing.T) {
testCases := []struct {
name string
bp string
allowMissingDependencies bool
certificateOverride string
expectedCertSigningFlags string
expectedCertificate string
@ -1505,7 +1506,7 @@ func TestCertificates(t *testing.T) {
`,
certificateOverride: "",
expectedCertSigningFlags: "",
expectedCertificate: "build/make/target/product/security/testkey.x509.pem build/make/target/product/security/testkey.pk8",
expectedCertificate: "build/make/target/product/security/testkey",
},
{
name: "module certificate property",
@ -1524,7 +1525,7 @@ func TestCertificates(t *testing.T) {
`,
certificateOverride: "",
expectedCertSigningFlags: "",
expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8",
expectedCertificate: "cert/new_cert",
},
{
name: "path certificate property",
@ -1538,7 +1539,7 @@ func TestCertificates(t *testing.T) {
`,
certificateOverride: "",
expectedCertSigningFlags: "",
expectedCertificate: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
expectedCertificate: "build/make/target/product/security/expiredkey",
},
{
name: "certificate overrides",
@ -1557,7 +1558,7 @@ func TestCertificates(t *testing.T) {
`,
certificateOverride: "foo:new_certificate",
expectedCertSigningFlags: "",
expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8",
expectedCertificate: "cert/new_cert",
},
{
name: "certificate signing flags",
@ -1578,7 +1579,7 @@ func TestCertificates(t *testing.T) {
`,
certificateOverride: "",
expectedCertSigningFlags: "--lineage lineage.bin --rotation-min-sdk-version 32",
expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8",
expectedCertificate: "cert/new_cert",
},
{
name: "cert signing flags from filegroup",
@ -1604,7 +1605,20 @@ func TestCertificates(t *testing.T) {
`,
certificateOverride: "",
expectedCertSigningFlags: "--lineage lineage.bin --rotation-min-sdk-version 32",
expectedCertificate: "cert/new_cert.x509.pem cert/new_cert.pk8",
expectedCertificate: "cert/new_cert",
},
{
name: "missing with AllowMissingDependencies",
bp: `
android_app {
name: "foo",
srcs: ["a.java"],
certificate: ":new_certificate",
sdk_version: "current",
}
`,
expectedCertificate: "out/soong/.intermediates/foo/android_common/missing",
allowMissingDependencies: true,
},
}
@ -1616,17 +1630,32 @@ func TestCertificates(t *testing.T) {
if test.certificateOverride != "" {
variables.CertificateOverrides = []string{test.certificateOverride}
}
if test.allowMissingDependencies {
variables.Allow_missing_dependencies = proptools.BoolPtr(true)
}
}),
android.FixtureModifyContext(func(ctx *android.TestContext) {
ctx.SetAllowMissingDependencies(test.allowMissingDependencies)
}),
).RunTestWithBp(t, test.bp)
foo := result.ModuleForTests("foo", "android_common")
signapk := foo.Output("foo.apk")
signCertificateFlags := signapk.Args["certificates"]
android.AssertStringEquals(t, "certificates flags", test.expectedCertificate, signCertificateFlags)
certificate := foo.Module().(*AndroidApp).certificate
android.AssertPathRelativeToTopEquals(t, "certificates key", test.expectedCertificate+".pk8", certificate.Key)
// The sign_target_files_apks and check_target_files_signatures
// tools require that certificates have a .x509.pem extension.
android.AssertPathRelativeToTopEquals(t, "certificates pem", test.expectedCertificate+".x509.pem", certificate.Pem)
certSigningFlags := signapk.Args["flags"]
android.AssertStringEquals(t, "cert signing flags", test.expectedCertSigningFlags, certSigningFlags)
signapk := foo.Output("foo.apk")
if signapk.Rule != android.ErrorRule {
signCertificateFlags := signapk.Args["certificates"]
expectedFlags := certificate.Pem.String() + " " + certificate.Key.String()
android.AssertStringEquals(t, "certificates flags", expectedFlags, signCertificateFlags)
certSigningFlags := signapk.Args["flags"]
android.AssertStringEquals(t, "cert signing flags", test.expectedCertSigningFlags, certSigningFlags)
}
})
}
}