Skip to content

Commit

Permalink
test: add tests for apk-mitm patch & git repo init. (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
Surendrajat committed Feb 5, 2022
1 parent ef6ea22 commit d307609
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
58 changes: 58 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { checkAndInstallTools } from "../../utils/updater";
import { Quark } from "../../tools/quark-engine";
import { apktool } from "../../tools/apktool";
import { jadx } from "../../tools/jadx";
import { git } from "../../tools/git";
import { apkMitm } from "../../tools/apk-mitm";

describe("Extension Test Suite", function () {
this.timeout(600000);
Expand Down Expand Up @@ -164,4 +166,60 @@ describe("Extension Test Suite", function () {
);
}
});

// test apk-mitm patch (uses apk-mitm)
it("Patch for HTTPS inspection(apk-mitm)", async function () {
const testApkPath = path.resolve(simpleKeyboardDir, "test.apk");
const projectDir = path.resolve(simpleKeyboardDir, "test");

console.log(`Decoding ${testApkPath}...`);
await apktool.decodeAPK(testApkPath, projectDir, []);
const apktoolYmlPath = path.resolve(projectDir, "apktool.yml");

console.log(`Patching app with apk-mitm...`);
await apkMitm.applyMitmPatches(apktoolYmlPath);

console.log("Checking for network security config file...");
const nscFile = path.join(projectDir, "res", "xml", "nsc_mitm.xml");
if (!fs.existsSync(nscFile)) {
assert.fail(`NSC File ${nscFile} not found!`);
}
});

// test the git init thingy (uses git)
it("git init in project dir", async function () {
const testApkPath = path.resolve(simpleKeyboardDir, "test.apk");
const projectDir = path.resolve(simpleKeyboardDir, "test");

console.log(`Decoding ${testApkPath}...`);
await apktool.decodeAPK(testApkPath, projectDir, []);

console.log(`git init in ${projectDir}...`);
await git.initGitDir(projectDir, "initial commit 0abcd1234");

console.log("Validating .gitignore file...");
const gitignoreFile = path.join(projectDir, ".gitignore");
if (!fs.existsSync(gitignoreFile)) {
assert.fail(`.gitignore file ${gitignoreFile} not found!`);
}
const gitignoreData = fs.readFileSync(gitignoreFile, "utf-8");
if (gitignoreData !== "/build\n/dist\n")
assert.fail(`${gitignoreFile} doesn't contain ${gitignoreData}`);

console.log("Validating .git dir...");
const gitDir = path.join(projectDir, ".git");
if (
!fs.existsSync(gitDir) ||
!fs.existsSync(path.join(gitDir, "HEAD")) ||
!fs.existsSync(path.join(gitDir, "config"))
) {
assert.fail(`.git/ dir ${gitDir} not valid!`);
}
console.log("Validating git config file...");
const gitConfigFile = path.join(gitDir, "config");
const gitConfigData = fs.readFileSync(gitConfigFile, "utf-8");
if (!gitConfigData.includes("safecrlf = false")) {
assert.fail(`git config file ${gitConfigFile} not valid!`);
}
});
});
8 changes: 5 additions & 3 deletions src/tools/apk-mitm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ export namespace apkMitm {
outputChannel.appendLine(report);
outputChannel.appendLine("-".repeat(report.length));

outputChannel.appendLine(
`Using apk-mitm v${APK_MITM_VERSION} (https://github.com/shroudedcode/apk-mitm)\n`
);
if (!process.env["TEST"]) {
outputChannel.appendLine(
`Using apk-mitm v${APK_MITM_VERSION} (https://github.com/shroudedcode/apk-mitm)\n`
);
}

const projectDir = path.dirname(apktoolYmlPath);

Expand Down

0 comments on commit d307609

Please sign in to comment.