未验证 提交 9c3aceab 编写于 作者: O openharmony_ci 提交者: Gitee

!8914 【OpenHarmony 4.0.7.2】【安全子系统】【master】XTS Failure Case Maintenance

Merge pull request !8914 from qiaozzzh/0605_1
......@@ -20,9 +20,9 @@ import DigestAlgorithmJsunit from "./DigestAlgorithm.test";
import SecurityRandomJsunit from "./SecurityRandom.test";
export default function testsuite() {
SymmetricCryptographyJsunit();
AsymmetricCryptographyJsunit();
AsymmetricCryptographyJsSecondunit();
DigestAlgorithmJsunit();
SecurityRandomJsunit();
SymmetricCryptographyJsunit();
AsymmetricCryptographyJsunit();
AsymmetricCryptographyJsSecondunit();
DigestAlgorithmJsunit();
SecurityRandomJsunit();
}
......@@ -16,126 +16,124 @@
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import { testSecurityRandomPromise } from "./utils/securityrandom/publicSecurityRandomPromise";
import {
testSecurityRandomCallback,
testSecurityRandomLengthCallback,
testSecurityRandomCallbackSeed,
} from "./utils/securityrandom/publicSecurityRandomCallback";
import { testSecurityRandomCallback } from "./utils/securityrandom/publicSecurityRandomCallback";
import { testSecurityRandomEnumCommon } from "./utils/securityrandom/publicSecurityRandomCommon";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function SecurityRandomJsunit() {
describe("SecurityRandomJsunit", function () {
console.info("##########start SecurityRandomJsunit##########");
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();
describe("SecurityRandomJsunit", function () {
console.info("##########start SecurityRandomJsunit##########");
beforeAll(function () {
});
done();
});
/**
* @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();
afterEach(function () {
});
done();
});
/**
* @tc.number Security_crypto_framework_Random_0300
* @tc.name Support generating safe random numbers and setting the length of random numbers
* @tc.desc use callback style of interface
*/
it("Security_crypto_framework_Random_0300", 0, async function (done) {
await testSecurityRandomLengthCallback(0)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await testSecurityRandomLengthCallback(null)
.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();
/**
* @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();
});
await testSecurityRandomLengthCallback(2147483647)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/**
* @tc.number Security_crypto_framework_Random_0400
* @tc.name Support generating safe random numbers and setting random number seed exceptions
* @tc.desc use callback style of interface
*/
it("Security_crypto_framework_Random_0400", 0, async function (done) {
await testSecurityRandomCallbackSeed(null)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @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();
});
await testSecurityRandomCallbackSeed(0)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_Random_0300
* @tc.name Test generateRandom with invalid input
* @tc.desc First input 0, Second input null, Third input -1, Fourth input 2147483648
*/
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();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_Random_0400
* @tc.name Test setSeed with invalid input
* @tc.desc First input null, Second input 0
*/
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.name test enumerated values
* @tc.desc cover 100% Enumerated values
*/
it("Security_crypto_framework_Random_0500", 0, async function (done) {
testSecurityRandomEnumCommon();
done();
/**
* @tc.number Security_crypto_framework_Random_0500
* @tc.name test enumerated values
* @tc.desc cover 100% Enumerated values
*/
it("Security_crypto_framework_Random_0500", 0, async function (done) {
testSecurityRandomEnumCommon();
done();
});
});
});
}
......@@ -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) {
var globalRsaKeyPair;
......@@ -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) {
var globalCipherText;
var globalRsaKeyPair;
......@@ -714,7 +611,6 @@ async function encryptAndDecryptNormalProcessNull(asyAlgoName, cipherAlgoName) {
);
}
let decryptData = uInt8ArrayToString(finalOutput.data);
expect(decryptData == globalText).assertTrue();
reject();
})
.catch((err) => {
......@@ -730,11 +626,7 @@ export {
signAndVerifyNormalProcess,
convertKeyEncryptAndDecryptProcess,
keyAgreementProcess,
createAsyKeyAgreementFail,
keyAgreementProcessFail,
keyAgreementProcessParameterException,
createAsyKeyGeneratorFail,
encryptAndDecryptNormalProcessSuperdata,
signAndVerifyNormalProcessSuperdata,
encryptAndDecryptNormalProcessNull,
encryptAndDecryptNormalProcessNull
};
......@@ -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 {
testSecurityRandomCallback,
testSecurityRandomLengthCallback,
testSecurityRandomCallbackSeed,
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册