Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for apk-mitm patch & git repo init. #158

Merged
merged 2 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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