This repository has been archived by the owner on Sep 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #95: ByteArrayApkFile close input when read zip entry
- Loading branch information
Showing
9 changed files
with
109 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package net.dongliu.apk.parser; | ||
|
||
import net.dongliu.apk.parser.bean.ApkMeta; | ||
import net.dongliu.apk.parser.bean.ApkSigner; | ||
import net.dongliu.apk.parser.bean.CertificateMeta; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.security.cert.CertificateException; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import static junit.framework.TestCase.assertEquals; | ||
|
||
public class ApkFileTest { | ||
|
||
@Test | ||
public void testParserMeta() throws IOException { | ||
String path = getClass().getClassLoader().getResource("apks/Twitter_v7.93.2.apk").getPath(); | ||
try (ApkFile apkFile = new ApkFile(path)) { | ||
apkFile.setPreferredLocale(Locale.ENGLISH); | ||
ApkMeta apkMeta = apkFile.getApkMeta(); | ||
assertEquals("Twitter", apkMeta.getLabel()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetSignature() throws IOException, CertificateException { | ||
String path = getClass().getClassLoader().getResource("apks/Twitter_v7.93.2.apk").getPath(); | ||
try (ApkFile apkFile = new ApkFile(path)) { | ||
List<ApkSigner> apkSingers = apkFile.getApkSingers(); | ||
assertEquals(1, apkSingers.size()); | ||
ApkSigner apkSigner = apkSingers.get(0); | ||
assertEquals("META-INF/CERT.RSA", apkSigner.getPath()); | ||
List<CertificateMeta> certificateMetas = apkSigner.getCertificateMetas(); | ||
assertEquals(1, certificateMetas.size()); | ||
CertificateMeta certificateMeta = certificateMetas.get(0); | ||
assertEquals("69ee076cc84f4d94802d61907b07525f", certificateMeta.getCertMd5()); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/test/java/net/dongliu/apk/parser/ByteArrayApkFileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.dongliu.apk.parser; | ||
|
||
import net.dongliu.apk.parser.bean.ApkMeta; | ||
import net.dongliu.apk.parser.bean.ApkSigner; | ||
import net.dongliu.apk.parser.bean.ApkV2Signer; | ||
import net.dongliu.apk.parser.bean.CertificateMeta; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.security.cert.CertificateException; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import static junit.framework.TestCase.assertEquals; | ||
|
||
public class ByteArrayApkFileTest { | ||
|
||
@Test | ||
public void testParserMeta() throws IOException { | ||
String path = getClass().getClassLoader().getResource("apks/Twitter_v7.93.2.apk").getPath(); | ||
byte[] bytes = Files.readAllBytes(Paths.get(path)); | ||
try (ByteArrayApkFile apkFile = new ByteArrayApkFile(bytes)) { | ||
apkFile.setPreferredLocale(Locale.ENGLISH); | ||
ApkMeta apkMeta = apkFile.getApkMeta(); | ||
assertEquals("Twitter", apkMeta.getLabel()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetSignature() throws IOException, CertificateException { | ||
String path = getClass().getClassLoader().getResource("apks/Twitter_v7.93.2.apk").getPath(); | ||
byte[] bytes = Files.readAllBytes(Paths.get(path)); | ||
try (ByteArrayApkFile apkFile = new ByteArrayApkFile(bytes)) { | ||
List<ApkSigner> apkSingers = apkFile.getApkSingers(); | ||
assertEquals(1, apkSingers.size()); | ||
ApkSigner apkSigner = apkSingers.get(0); | ||
assertEquals("META-INF/CERT.RSA", apkSigner.getPath()); | ||
List<CertificateMeta> certificateMetas = apkSigner.getCertificateMetas(); | ||
assertEquals(1, certificateMetas.size()); | ||
CertificateMeta certificateMeta = certificateMetas.get(0); | ||
assertEquals("69ee076cc84f4d94802d61907b07525f", certificateMeta.getCertMd5()); | ||
|
||
List<ApkV2Signer> apkV2Singers = apkFile.getApkV2Singers(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.