| Rupert Shuttleworth | eb8c85a | 2021-07-27 07:10:32 -0400 | [diff] [blame] | 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 |  | 
|  | 15 | package bp2build | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "android/soong/android" | 
|  | 19 | "android/soong/apex" | 
|  | 20 |  | 
|  | 21 | "testing" | 
|  | 22 | ) | 
|  | 23 |  | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 24 | func runApexKeyTestCase(t *testing.T, tc Bp2buildTestCase) { | 
| Rupert Shuttleworth | eb8c85a | 2021-07-27 07:10:32 -0400 | [diff] [blame] | 25 | t.Helper() | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 26 | RunBp2BuildTestCase(t, registerApexKeyModuleTypes, tc) | 
| Rupert Shuttleworth | eb8c85a | 2021-07-27 07:10:32 -0400 | [diff] [blame] | 27 | } | 
|  | 28 |  | 
|  | 29 | func registerApexKeyModuleTypes(ctx android.RegistrationContext) { | 
| Jingwen Chen | 1d87333 | 2022-10-05 06:15:15 +0000 | [diff] [blame] | 30 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) | 
| Rupert Shuttleworth | eb8c85a | 2021-07-27 07:10:32 -0400 | [diff] [blame] | 31 | } | 
|  | 32 |  | 
| Jingwen Chen | 6817bbb | 2022-10-14 09:56:07 +0000 | [diff] [blame] | 33 | func TestApexKeySimple_KeysAreSrcFilesInSameDir(t *testing.T) { | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 34 | runApexKeyTestCase(t, Bp2buildTestCase{ | 
| Jingwen Chen | 6817bbb | 2022-10-14 09:56:07 +0000 | [diff] [blame] | 35 | Description:                "apex key - keys are src files, use key attributes", | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 36 | ModuleTypeUnderTest:        "apex_key", | 
|  | 37 | ModuleTypeUnderTestFactory: apex.ApexKeyFactory, | 
| Jingwen Chen | 6817bbb | 2022-10-14 09:56:07 +0000 | [diff] [blame] | 38 | Filesystem: map[string]string{ | 
|  | 39 | "com.android.apogee.avbpubkey": "", | 
|  | 40 | "com.android.apogee.pem":       "", | 
|  | 41 | }, | 
|  | 42 | Blueprint: ` | 
|  | 43 | apex_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{ | 
| Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 50 | "private_key":            `"com.android.apogee.pem"`, | 
|  | 51 | "public_key":             `"com.android.apogee.avbpubkey"`, | 
| Jingwen Chen | 9c2e3ee | 2023-10-11 10:51:28 +0000 | [diff] [blame] | 52 | "target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`, | 
| Jingwen Chen | 6817bbb | 2022-10-14 09:56:07 +0000 | [diff] [blame] | 53 | }), | 
|  | 54 | }}) | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | func TestApexKeySimple_KeysAreSrcFilesNotInDir(t *testing.T) { | 
|  | 58 | runApexKeyTestCase(t, Bp2buildTestCase{ | 
|  | 59 | Description:                "apex key - keys are not src or module, use key_name attributes", | 
|  | 60 | ModuleTypeUnderTest:        "apex_key", | 
|  | 61 | ModuleTypeUnderTestFactory: apex.ApexKeyFactory, | 
|  | 62 | Filesystem:                 map[string]string{ | 
|  | 63 | // deliberately left empty | 
|  | 64 | }, | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 65 | Blueprint: ` | 
| Rupert Shuttleworth | eb8c85a | 2021-07-27 07:10:32 -0400 | [diff] [blame] | 66 | apex_key { | 
|  | 67 | name: "com.android.apogee.key", | 
|  | 68 | public_key: "com.android.apogee.avbpubkey", | 
|  | 69 | private_key: "com.android.apogee.pem", | 
|  | 70 | } | 
|  | 71 | `, | 
| Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 72 | ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{ | 
| Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 73 | "private_key_name":       `"com.android.apogee.pem"`, | 
|  | 74 | "public_key_name":        `"com.android.apogee.avbpubkey"`, | 
| Jingwen Chen | 9c2e3ee | 2023-10-11 10:51:28 +0000 | [diff] [blame] | 75 | "target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`, | 
| Jingwen Chen | 1d87333 | 2022-10-05 06:15:15 +0000 | [diff] [blame] | 76 | }), | 
|  | 77 | }}) | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | func TestApexKey_KeysAreModules(t *testing.T) { | 
|  | 81 | runApexKeyTestCase(t, Bp2buildTestCase{ | 
|  | 82 | Description:                "apex key - keys are modules, use key attributes", | 
|  | 83 | ModuleTypeUnderTest:        "apex_key", | 
|  | 84 | ModuleTypeUnderTestFactory: apex.ApexKeyFactory, | 
|  | 85 | Filesystem:                 map[string]string{}, | 
| Chris Parsons | cd20903 | 2023-09-19 01:12:48 +0000 | [diff] [blame] | 86 | StubbedBuildDefinitions:    []string{"com.android.apogee.avbpubkey", "com.android.apogee.pem"}, | 
| Jingwen Chen | 1d87333 | 2022-10-05 06:15:15 +0000 | [diff] [blame] | 87 | Blueprint: ` | 
|  | 88 | apex_key { | 
|  | 89 | name: "com.android.apogee.key", | 
|  | 90 | public_key: ":com.android.apogee.avbpubkey", | 
|  | 91 | private_key: ":com.android.apogee.pem", | 
|  | 92 | } | 
| Chris Parsons | cd20903 | 2023-09-19 01:12:48 +0000 | [diff] [blame] | 93 | ` + simpleModule("filegroup", "com.android.apogee.avbpubkey") + | 
|  | 94 | simpleModule("filegroup", "com.android.apogee.pem"), | 
| Jingwen Chen | 1d87333 | 2022-10-05 06:15:15 +0000 | [diff] [blame] | 95 | ExpectedBazelTargets: []string{MakeBazelTargetNoRestrictions("apex_key", "com.android.apogee.key", AttrNameToString{ | 
| Jooyung Han | 8d4a1f0 | 2023-08-23 13:54:08 +0900 | [diff] [blame] | 96 | "private_key":            `":com.android.apogee.pem"`, | 
|  | 97 | "public_key":             `":com.android.apogee.avbpubkey"`, | 
| Jingwen Chen | 9c2e3ee | 2023-10-11 10:51:28 +0000 | [diff] [blame] | 98 | "target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`, | 
| Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 99 | }), | 
|  | 100 | }}) | 
| Rupert Shuttleworth | eb8c85a | 2021-07-27 07:10:32 -0400 | [diff] [blame] | 101 | } |