1// 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 24func runApexKeyTestCase(t *testing.T, tc Bp2buildTestCase) { 25 t.Helper() 26 RunBp2BuildTestCase(t, registerApexKeyModuleTypes, tc) 27} 28 29func registerApexKeyModuleTypes(ctx android.RegistrationContext) { 30 ctx.RegisterModuleType("filegroup", android.FileGroupFactory) 31} 32 33func TestApexKeySimple_KeysAreSrcFilesInSameDir(t *testing.T) { 34 runApexKeyTestCase(t, Bp2buildTestCase{ 35 Description: "apex key - keys are src files, use key attributes", 36 ModuleTypeUnderTest: "apex_key", 37 ModuleTypeUnderTestFactory: apex.ApexKeyFactory, 38 Filesystem: map[string]string{ 39 "com.android.apogee.avbpubkey": "", 40 "com.android.apogee.pem": "", 41 }, 42 Blueprint: ` 43apex_key { 44 name: "com.android.apogee.key", 45 public_key: "com.android.apogee.avbpubkey", 46 private_key: "com.android.apogee.pem", 47} 48`, 49 ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{ 50 "private_key": `"com.android.apogee.pem"`, 51 "public_key": `"com.android.apogee.avbpubkey"`, 52 }), 53 }}) 54} 55 56func TestApexKeySimple_KeysAreSrcFilesNotInDir(t *testing.T) { 57 runApexKeyTestCase(t, Bp2buildTestCase{ 58 Description: "apex key - keys are not src or module, use key_name attributes", 59 ModuleTypeUnderTest: "apex_key", 60 ModuleTypeUnderTestFactory: apex.ApexKeyFactory, 61 Filesystem: map[string]string{ 62 // deliberately left empty 63 }, 64 Blueprint: ` 65apex_key { 66 name: "com.android.apogee.key", 67 public_key: "com.android.apogee.avbpubkey", 68 private_key: "com.android.apogee.pem", 69} 70`, 71 ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{ 72 "private_key_name": `"com.android.apogee.pem"`, 73 "public_key_name": `"com.android.apogee.avbpubkey"`, 74 }), 75 }}) 76} 77 78func TestApexKey_KeysAreModules(t *testing.T) { 79 runApexKeyTestCase(t, Bp2buildTestCase{ 80 Description: "apex key - keys are modules, use key attributes", 81 ModuleTypeUnderTest: "apex_key", 82 ModuleTypeUnderTestFactory: apex.ApexKeyFactory, 83 Filesystem: map[string]string{}, 84 Blueprint: ` 85apex_key { 86 name: "com.android.apogee.key", 87 public_key: ":com.android.apogee.avbpubkey", 88 private_key: ":com.android.apogee.pem", 89} 90` + simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee.avbpubkey") + 91 simpleModuleDoNotConvertBp2build("filegroup", "com.android.apogee.pem"), 92 ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{ 93 "private_key": `":com.android.apogee.pem"`, 94 "public_key": `":com.android.apogee.avbpubkey"`, 95 }), 96 }}) 97} 98