提交 b99c8880 编写于 作者: Q qiaozzzh

XTS Failure Case Maintenance

Signed-off-by: Nqiaozzzh <qiaozhang@huawei.com>
Change-Id: Id784febd928e2812aa499eb66bb3e2367a7d2a66
上级 dffe1b26
...@@ -13,16 +13,16 @@ ...@@ -13,16 +13,16 @@
* limitations under the License. * limitations under the License.
*/ */
import SymmetricCryptographyJsunit from "./SymmetricCryptography.test"; import SymmetricCryptographyJsunit from './SymmetricCryptography.test';
import AsymmetricCryptographyJsunit from "./AsymmetricCryptography.test"; import AsymmetricCryptographyJsunit from './AsymmetricCryptography.test';
import AsymmetricCryptographyJsSecondunit from "./AsymmetricCryptographySecond.test"; import AsymmetricCryptographyJsSecondunit from './AsymmetricCryptographySecond.test';
import DigestAlgorithmJsunit from "./DigestAlgorithm.test"; import DigestAlgorithmJsunit from './DigestAlgorithm.test';
import SecurityRandomJsunit from "./SecurityRandom.test"; import SecurityRandomJsunit from './SecurityRandom.test';
export default function testsuite() { export default function testsuite() {
SymmetricCryptographyJsunit(); SymmetricCryptographyJsunit();
AsymmetricCryptographyJsunit(); AsymmetricCryptographyJsunit();
AsymmetricCryptographyJsSecondunit(); AsymmetricCryptographyJsSecondunit();
DigestAlgorithmJsunit(); DigestAlgorithmJsunit();
SecurityRandomJsunit(); SecurityRandomJsunit();
} }
...@@ -16,126 +16,124 @@ ...@@ -16,126 +16,124 @@
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium"; import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import { testSecurityRandomPromise } from "./utils/securityrandom/publicSecurityRandomPromise"; import { testSecurityRandomPromise } from "./utils/securityrandom/publicSecurityRandomPromise";
import { import { testSecurityRandomCallback } from "./utils/securityrandom/publicSecurityRandomCallback";
testSecurityRandomCallback,
testSecurityRandomLengthCallback,
testSecurityRandomCallbackSeed,
} from "./utils/securityrandom/publicSecurityRandomCallback";
import { testSecurityRandomEnumCommon } from "./utils/securityrandom/publicSecurityRandomCommon"; import { testSecurityRandomEnumCommon } from "./utils/securityrandom/publicSecurityRandomCommon";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function SecurityRandomJsunit() { export default function SecurityRandomJsunit() {
describe("SecurityRandomJsunit", function () { describe("SecurityRandomJsunit", function () {
console.info("##########start SecurityRandomJsunit##########"); console.info("##########start SecurityRandomJsunit##########");
beforeAll(function () {}); beforeAll(function () {
afterEach(function () {});
/**
* @tc.number Security_crypto_framework_Random_0100
* @tc.name support security random and set random seed
* @tc.desc the length of random is 32, use promise style of interface
*/
it("Security_crypto_framework_Random_0100", 0, async function (done) {
await testSecurityRandomPromise(32)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
}); });
done(); afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_Random_0200
* @tc.name Support setting random number seed and restart encryption and decryption framework
* @tc.desc the length of random is 32, use callback style of interface
*/
it("Security_crypto_framework_Random_0200", 0, async function (done) {
await testSecurityRandomCallback(32)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
}); });
done();
});
/** /**
* @tc.number Security_crypto_framework_Random_0300 * @tc.number Security_crypto_framework_Random_0100
* @tc.name Support generating safe random numbers and setting the length of random numbers * @tc.name support security random and set random seed
* @tc.desc use callback style of interface * @tc.desc the length of random is 32, use promise style of interface
*/ */
it("Security_crypto_framework_Random_0300", 0, async function (done) { it("Security_crypto_framework_Random_0100", 0, async function (done) {
await testSecurityRandomLengthCallback(0) await testSecurityRandomPromise(32)
.then((data) => { .then((data) => {
expect(data == null).assertTrue(); expect(data == null).assertTrue();
}) })
.catch((err) => { .catch((err) => {
expect(null).assertFail(); expect(null).assertFail();
}); });
await testSecurityRandomLengthCallback(null) done();
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await testSecurityRandomLengthCallback(-1)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
}); });
await testSecurityRandomLengthCallback(2147483647)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/** /**
* @tc.number Security_crypto_framework_Random_0400 * @tc.number Security_crypto_framework_Random_0200
* @tc.name Support generating safe random numbers and setting random number seed exceptions * @tc.name Support setting random number seed and restart encryption and decryption framework
* @tc.desc use callback style of interface * @tc.desc the length of random is 32, use callback style of interface
*/ */
it("Security_crypto_framework_Random_0400", 0, async function (done) { it("Security_crypto_framework_Random_0200", 0, async function (done) {
await testSecurityRandomCallbackSeed(null) await testSecurityRandomCallback(32)
.then((data) => { .then((data) => {
expect(data == null).assertTrue(); expect(data == null).assertTrue();
}) })
.catch((err) => { .catch((err) => {
expect(null).assertFail(); expect(null).assertFail();
});
done();
}); });
await testSecurityRandomCallbackSeed(0)
.then((data) => { /**
expect(data == null).assertTrue(); * @tc.number Security_crypto_framework_Random_0300
}) * @tc.name Test generateRandom with invalid input
.catch((err) => { * @tc.desc First input 0, Second input null, Third input -1, Fourth input 2147483648
expect(null).assertFail(); */
it("Security_crypto_framework_Random_0300", 0, async function (done) {
let randomGenerator = cryptoFramework.createRandom();
try {
await new Promise((resolve, reject) => {
randomGenerator.generateRandom(0, (err, dataBlob) => {
if (err) {
reject(err);
} else {
resolve(dataBlob);
}
})
})
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await randomGenerator.generateRandom(null);
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await new Promise((resolve, reject) => {
randomGenerator.generateRandom(-1, (err, dataBlob) => {
if (err) {
reject(err);
} else {
resolve(dataBlob);
}
})
})
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await randomGenerator.generateRandom(2147483648);
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}); });
await testSecurityRandomCallbackSeed(2147483647)
.then((data) => { /**
expect(data == null).assertTrue(); * @tc.number Security_crypto_framework_Random_0400
}) * @tc.name Test setSeed with invalid input
.catch((err) => { * @tc.desc First input null, Second input 0
expect(null).assertFail(); */
it("Security_crypto_framework_Random_0400", 0, async function (done) {
let randomGenerator = cryptoFramework.createRandom();
try {
randomGenerator.setSeed(null);
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
randomGenerator.setSeed(0);
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}); });
done();
});
/** /**
* @tc.number Security_crypto_framework_Random_0500 * @tc.number Security_crypto_framework_Random_0500
* @tc.name test enumerated values * @tc.name test enumerated values
* @tc.desc cover 100% Enumerated values * @tc.desc cover 100% Enumerated values
*/ */
it("Security_crypto_framework_Random_0500", 0, async function (done) { it("Security_crypto_framework_Random_0500", 0, async function (done) {
testSecurityRandomEnumCommon(); testSecurityRandomEnumCommon();
done(); done();
});
}); });
});
} }
...@@ -387,17 +387,6 @@ async function convertKeyEncryptAndDecryptProcess(asyAlgoName) { ...@@ -387,17 +387,6 @@ async function convertKeyEncryptAndDecryptProcess(asyAlgoName) {
}); });
} }
async function createAsyKeyAgreementFail(ECDHAlgoName) {
return new Promise((resolve, reject) => {
var globalECDHData = createAsyKeyAgreement(ECDHAlgoName);
resolve(globalECDHData);
expect(globalECDHData == "TypeError: Cannot read property algName of undefined").assertTrue();
if (globalECDHData != "TypeError: Cannot read property algName of undefined"){
reject();
}
});
}
async function keyAgreementProcess(ECDHAlgoName) { async function keyAgreementProcess(ECDHAlgoName) {
var globalRsaKeyPair; var globalRsaKeyPair;
...@@ -425,98 +414,6 @@ async function keyAgreementProcess(ECDHAlgoName) { ...@@ -425,98 +414,6 @@ async function keyAgreementProcess(ECDHAlgoName) {
}); });
} }
async function keyAgreementProcessFail(ECDHAlgoName, ECDHAlgoName1) {
var globalRsaKeyPair;
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName);
expect(rsaGenerator != null).assertTrue();
var globalECDHData = createAsyKeyAgreement(ECDHAlgoName1);
expect(globalECDHData != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, globalRsaKeyPair.priKey, globalRsaKeyPair.pubKey);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
reject();
})
.catch((err) => {
console.error("[Callback] keyAgreementProcess catch err:" + err);
resolve(err);
});
});
}
async function keyAgreementProcessParameterException(ECDHAlgoName) {
var globalRsaKeyPair;
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName);
expect(rsaGenerator != null).assertTrue();
var globalECDHData = createAsyKeyAgreement(ECDHAlgoName);
expect(globalECDHData != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, null, null);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
})
.catch((err) => {
expect(err == "Error: [PriKey]: param unwarp error.").assertTrue();
});
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, globalRsaKeyPair.pubKey, null);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
})
.catch((err) => {
expect(err == "Error: [PubKey]: param unwarp error.").assertTrue();
});
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, null, globalRsaKeyPair.priKey);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
reject();
})
.catch((err) => {
expect(err == "Error: [PriKey]: param unwarp error.").assertTrue();
resolve(err);
});
});
}
async function createAsyKeyGeneratorFail(asyAlgoName) {
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
resolve(rsaGenerator);
expect(rsaGenerator == "TypeError: Cannot read property algName of null").assertTrue();
if (rsaGenerator != "TypeError: Cannot read property algName of null") {
reject();
}
});
}
async function encryptAndDecryptNormalProcessSuperdata(asyAlgoName, cipherAlgoName, globalTextLen) { async function encryptAndDecryptNormalProcessSuperdata(asyAlgoName, cipherAlgoName, globalTextLen) {
var globalCipherText; var globalCipherText;
var globalRsaKeyPair; var globalRsaKeyPair;
...@@ -714,7 +611,6 @@ async function encryptAndDecryptNormalProcessNull(asyAlgoName, cipherAlgoName) { ...@@ -714,7 +611,6 @@ async function encryptAndDecryptNormalProcessNull(asyAlgoName, cipherAlgoName) {
); );
} }
let decryptData = uInt8ArrayToString(finalOutput.data); let decryptData = uInt8ArrayToString(finalOutput.data);
expect(decryptData == globalText).assertTrue();
reject(); reject();
}) })
.catch((err) => { .catch((err) => {
...@@ -730,11 +626,7 @@ export { ...@@ -730,11 +626,7 @@ export {
signAndVerifyNormalProcess, signAndVerifyNormalProcess,
convertKeyEncryptAndDecryptProcess, convertKeyEncryptAndDecryptProcess,
keyAgreementProcess, keyAgreementProcess,
createAsyKeyAgreementFail,
keyAgreementProcessFail,
keyAgreementProcessParameterException,
createAsyKeyGeneratorFail,
encryptAndDecryptNormalProcessSuperdata, encryptAndDecryptNormalProcessSuperdata,
signAndVerifyNormalProcessSuperdata, signAndVerifyNormalProcessSuperdata,
encryptAndDecryptNormalProcessNull, encryptAndDecryptNormalProcessNull
}; };
...@@ -58,67 +58,6 @@ async function testSecurityRandomCallback(length) { ...@@ -58,67 +58,6 @@ async function testSecurityRandomCallback(length) {
}); });
} }
async function testSecurityRandomLengthCallback(length) {
var rand;
return new Promise((resolve, reject) => {
rand = cryptoFramework.createRandom();
expect(rand != null).assertTrue();
if (length != null) {
rand.generateRandom(length, (err, randData) => {
if (err) {
console.error(
"[callback]generateRandom catch error:" +
err +
"[callback]: error code: " +
err.code
);
expect(err.code == 401).assertTrue();
resolve();
} else {
expect(randData != null).assertTrue();
reject();
}
});
} else {
try {
rand.generateRandom(length);
reject();
} catch (error) {
console.error(
"[callback]generateRandom catch err1:" +
error +
"[callback]: error code: " +
error.code
);
resolve();
}
}
});
}
async function testSecurityRandomCallbackSeed(data) {
var rand;
return new Promise((resolve, reject) => {
rand = cryptoFramework.createRandom();
expect(rand != null).assertTrue();
try {
rand.setSeed(data);
reject();
} catch (error) {
console.error(
"[callback]setSeed catch err:" +
error +
"[callback]: error code: " +
error.code
);
expect(error.code == 401).assertTrue();
resolve();
}
});
}
export { export {
testSecurityRandomCallback, testSecurityRandomCallback,
testSecurityRandomLengthCallback,
testSecurityRandomCallbackSeed,
}; };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册