apex_key_conversion_test.go 3.3 KB

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