From 764858246d5de4c3a554afccff428430df4e01b7 Mon Sep 17 00:00:00 2001 From: Ezio Li Date: Mon, 27 Nov 2023 13:57:41 +0800 Subject: [PATCH] Add unit test for AndroidInsecureFileModeEnabled config (#932) * Add unit test for AndroidInsecureFileModeEnabled config * Update --- test/common/configurationHelper.test.ts | 29 +++++++++++++++++++ .../disableFileModeConfig.xml | 11 +++++++ .../enableFileModeConfig.xml | 12 ++++++++ 3 files changed, 52 insertions(+) create mode 100644 test/common/configurationHelper.test.ts create mode 100644 test/resources/testAndroidFileModeProject/disableFileModeConfig.xml create mode 100644 test/resources/testAndroidFileModeProject/enableFileModeConfig.xml diff --git a/test/common/configurationHelper.test.ts b/test/common/configurationHelper.test.ts new file mode 100644 index 0000000..a18099f --- /dev/null +++ b/test/common/configurationHelper.test.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +import * as assert from "assert"; +import * as fs from "fs"; +import * as path from "path"; +import { ConfigurationHelper } from "../../src/common/configurationHelper"; + +suite("configurationHelper", function () { + test("should get AndroidInsecureFileMode value correctly", (done: Mocha.Done) => { + const disableXmlContentPath = path.resolve( + __dirname, + "../resources/testAndroidFileModeProject/disableFileModeConfig.xml", + ); + const disableXmlContent = fs.readFileSync(disableXmlContentPath, "utf-8"); + const disableStatus = + ConfigurationHelper.getAndroidInsecureFileModeStatus(disableXmlContent); + assert.strictEqual(disableStatus, true); + + const enableXmlContentPath = path.resolve( + __dirname, + "../resources/testAndroidFileModeProject/enableFileModeConfig.xml", + ); + const enableXmlContent = fs.readFileSync(enableXmlContentPath, "utf-8"); + const enableStatus = ConfigurationHelper.getAndroidInsecureFileModeStatus(enableXmlContent); + assert.strictEqual(enableStatus, false); + done(); + }); +}); diff --git a/test/resources/testAndroidFileModeProject/disableFileModeConfig.xml b/test/resources/testAndroidFileModeProject/disableFileModeConfig.xml new file mode 100644 index 0000000..ef82a10 --- /dev/null +++ b/test/resources/testAndroidFileModeProject/disableFileModeConfig.xml @@ -0,0 +1,11 @@ + + +HelloCordova +Sample Apache Cordova App + + Apache Cordova Team + + + + + diff --git a/test/resources/testAndroidFileModeProject/enableFileModeConfig.xml b/test/resources/testAndroidFileModeProject/enableFileModeConfig.xml new file mode 100644 index 0000000..7a27531 --- /dev/null +++ b/test/resources/testAndroidFileModeProject/enableFileModeConfig.xml @@ -0,0 +1,12 @@ + + +HelloCordova +Sample Apache Cordova App + + Apache Cordova Team + + + + + +