blob: 79b1d89d16dbfa613fdc43cd0d4f2e56c28ad4e4 [file] [log] [blame]
Rupert Shuttlewortheb8c85a2021-07-27 07:10:32 -04001// Copyright 2021 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package bp2build
16
17import (
18 "android/soong/android"
19 "android/soong/apex"
20
21 "testing"
22)
23
Sam Delmerico3177a6e2022-06-21 19:28:33 +000024func runApexKeyTestCase(t *testing.T, tc Bp2buildTestCase) {
Rupert Shuttlewortheb8c85a2021-07-27 07:10:32 -040025 t.Helper()
Sam Delmerico3177a6e2022-06-21 19:28:33 +000026 RunBp2BuildTestCase(t, registerApexKeyModuleTypes, tc)
Rupert Shuttlewortheb8c85a2021-07-27 07:10:32 -040027}
28
29func registerApexKeyModuleTypes(ctx android.RegistrationContext) {
Jingwen Chen1d873332022-10-05 06:15:15 +000030 ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
Rupert Shuttlewortheb8c85a2021-07-27 07:10:32 -040031}
32
Jingwen Chen1d873332022-10-05 06:15:15 +000033func TestApexKeySimple_KeysAreSrcFiles(t *testing.T) {
Sam Delmerico3177a6e2022-06-21 19:28:33 +000034 runApexKeyTestCase(t, Bp2buildTestCase{
Jingwen Chen1d873332022-10-05 06:15:15 +000035 Description: "apex key - keys are src files, use key_name attributes",
Sam Delmerico3177a6e2022-06-21 19:28:33 +000036 ModuleTypeUnderTest: "apex_key",
37 ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
38 Filesystem: map[string]string{},
39 Blueprint: `
Rupert Shuttlewortheb8c85a2021-07-27 07:10:32 -040040apex_key {
41 name: "com.android.apogee.key",
42 public_key: "com.android.apogee.avbpubkey",
43 private_key: "com.android.apogee.pem",
44}
45`,
Sam Delmerico3177a6e2022-06-21 19:28:33 +000046 ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
Jingwen Chen1d873332022-10-05 06:15:15 +000047 "private_key_name": `"com.android.apogee.pem"`,
48 "public_key_name": `"com.android.apogee.avbpubkey"`,
49 }),
50 }})
51}
52
53func TestApexKey_KeysAreModules(t *testing.T) {
54 runApexKeyTestCase(t, Bp2buildTestCase{
55 Description: "apex key - keys are modules, use key attributes",
56 ModuleTypeUnderTest: "apex_key",
57 ModuleTypeUnderTestFactory: apex.ApexKeyFactory,
58 Filesystem: map[string]string{},
59 Blueprint: `
60apex_key {
61 name: "com.android.apogee.key",
62 public_key: ":com.android.apogee.avbpubkey",
63 private_key: ":com.android.apogee.pem",
64}
65` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee.avbpubkey") +
66 simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee.pem"),
67 ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{
68 "private_key": `":com.android.apogee.pem"`,
69 "public_key": `":com.android.apogee.avbpubkey"`,
Liz Kammer78cfdaa2021-11-08 12:56:31 -050070 }),
71 }})
Rupert Shuttlewortheb8c85a2021-07-27 07:10:32 -040072}