Skip to content

Commit 50a1e54

Browse files
authored
Fix Sinf patch when app contains a Watch App (#140)
* Fix Sinf patch * Add test case for Downloading with Watch App * Update pkg/appstore/appstore_download_test.go
1 parent 094ff93 commit 50a1e54

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

pkg/appstore/appstore_download.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ func (a *appstore) replicateZip(src *zip.ReadCloser, dst *zip.Writer, info *byte
377377
return "", errors.Wrap(err, ErrDecompressInfoFile.Error())
378378
}
379379

380-
appBundle = filepath.Base(strings.TrimSuffix(file.Name, ".app/Info.plist"))
380+
if !strings.Contains(file.Name, "/Watch/") {
381+
appBundle = filepath.Base(strings.TrimSuffix(file.Name, ".app/Info.plist"))
382+
}
381383

382384
_, err = io.Copy(info, srcFileD)
383385
if err != nil {

pkg/appstore/appstore_download_test.go

+63-1
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ var _ = Describe("AppStore (Download)", func() {
773773
})
774774
})
775775

776-
When("app uses modern FiarPlay protection", func() {
776+
When("app uses modern FairPlay protection", func() {
777777
BeforeEach(func() {
778778
zipFile = zip.NewWriter(tmpFile)
779779
w, err := zipFile.Create("Payload/Test.app/SC_Info/Manifest.plist")
@@ -810,6 +810,68 @@ var _ = Describe("AppStore (Download)", func() {
810810
Expect(err).ToNot(HaveOccurred())
811811
})
812812
})
813+
814+
When("app uses modern FairPlay protection and has Watch app", func() {
815+
BeforeEach(func() {
816+
zipFile = zip.NewWriter(tmpFile)
817+
w, err := zipFile.Create("Payload/Test.app/SC_Info/Manifest.plist")
818+
Expect(err).ToNot(HaveOccurred())
819+
820+
manifest, err := plist.Marshal(PackageManifest{
821+
SinfPaths: []string{
822+
"SC_Info/TestApp.sinf",
823+
},
824+
}, plist.BinaryFormat)
825+
Expect(err).ToNot(HaveOccurred())
826+
827+
_, err = w.Write(manifest)
828+
Expect(err).ToNot(HaveOccurred())
829+
830+
w, err = zipFile.Create("Payload/Test.app/Info.plist")
831+
Expect(err).ToNot(HaveOccurred())
832+
833+
info, err := plist.Marshal(map[string]interface{}{
834+
"CFBundleExecutable": "Test",
835+
}, plist.BinaryFormat)
836+
Expect(err).ToNot(HaveOccurred())
837+
838+
_, err = w.Write(info)
839+
Expect(err).ToNot(HaveOccurred())
840+
841+
w, err = zipFile.Create("Payload/Test.app/Watch/Test Watch App.app/Info.plist")
842+
Expect(err).ToNot(HaveOccurred())
843+
844+
watchInfo, err := plist.Marshal(map[string]interface{}{
845+
"WKWatchKitApp": true,
846+
}, plist.BinaryFormat)
847+
Expect(err).ToNot(HaveOccurred())
848+
849+
_, err = w.Write(watchInfo)
850+
Expect(err).ToNot(HaveOccurred())
851+
852+
err = zipFile.Close()
853+
Expect(err).ToNot(HaveOccurred())
854+
})
855+
856+
It("sinf is in the correct path", func() {
857+
outputPath := strings.TrimSuffix(tmpFile.Name(), ".tmp")
858+
err := as.Download("", outputPath, true)
859+
Expect(err).ToNot(HaveOccurred())
860+
861+
r, err := zip.OpenReader(outputPath)
862+
Expect(err).ToNot(HaveOccurred())
863+
defer r.Close()
864+
865+
found := false
866+
for _, f := range r.File {
867+
if f.Name == "Payload/Test Watch App.app/SC_Info/TestApp.sinf" {
868+
found = true
869+
break
870+
}
871+
}
872+
Expect(found).To(BeFalse())
873+
})
874+
})
813875
})
814876
})
815877
})

0 commit comments

Comments
 (0)