sign_read_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package tests
  2. import (
  3. "testing"
  4. "golang.org/x/exp/maps"
  5. "notabug.org/Umnik/GoAndroidSDK/v2/components/sdk/buildTools/apksigner"
  6. )
  7. func newSignRead(t *testing.T, funcName string) *apksigner.Apksigner {
  8. t.Helper()
  9. a, err := apksigner.NewApkSignerLastVersion(*newSdk(t, t.Name()))
  10. if !testErr(t, funcName, err) {
  11. return nil
  12. }
  13. return a
  14. }
  15. func verifyInfo(t *testing.T, file string, funcName string) *apksigner.VerifyInfo {
  16. t.Helper()
  17. sr := newSignRead(t, funcName)
  18. b, err := sr.DumpSignatureInfo(file, false)
  19. if !testErr(t, t.Name(), err) {
  20. t.Error(err)
  21. return nil
  22. }
  23. res := apksigner.ParseDumpSignatureInfoFromBytes(b)
  24. return &res
  25. }
  26. func TestVirifyInfo1(t *testing.T) {
  27. t.Parallel()
  28. vi := verifyInfo(t, emptyValFile, t.Name())
  29. if !maps.Equal(vi.SignInfo[0].CertDN, map[string]string{"O": "Ledger SAS", "C": "FR", "L": "Paris"}) {
  30. t.Errorf("Bad signature: %s", vi.SignInfo[0].CertDN)
  31. }
  32. }
  33. func TestVirifyInfo2(t *testing.T) {
  34. t.Parallel()
  35. vi := verifyInfo(t, goodApkFile, t.Name())
  36. if !maps.Equal(vi.SignInfo[0].CertDN, map[string]string{"C": "UK", "CN": "FDroid", "L": "ORG", "O": "fdroid.org", "OU": "FDroid", "ST": "ORG"}) {
  37. t.Errorf("Bad signature: %s", vi.SignInfo[0].CertDN)
  38. }
  39. }
  40. func TestVirifyInfo3(t *testing.T) {
  41. t.Parallel()
  42. vi := verifyInfo(t, splitBaseFile, t.Name())
  43. if !maps.Equal(vi.SignInfo[0].CertDN, map[string]string{"CN": "Empatika LLC", "O": "Empatika LLC"}) {
  44. t.Errorf("Bad signature: %s", vi.SignInfo[0].CertDN)
  45. }
  46. }