Skip to content

Commit

Permalink
FIX(SM): SM tool tests failed on Windows
Browse files Browse the repository at this point in the history
--bug=119826443
  • Loading branch information
johnshajiang authored and shiyuexw committed Apr 18, 2024
1 parent 528fa6e commit b007135
Show file tree
Hide file tree
Showing 20 changed files with 236 additions and 250 deletions.
15 changes: 1 addition & 14 deletions jdk/test/sm/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2023, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -18,7 +18,6 @@
*/

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -41,7 +40,6 @@
import java.security.spec.SM2PublicKeySpec;
import java.util.Arrays;
import java.util.Base64;
import java.util.Comparator;
import java.util.List;

/**
Expand Down Expand Up @@ -200,16 +198,5 @@ private static ECPrivateKey ecPrivateKeyAsStr(String pkcs8KeyPEM)
return (ECPrivateKey) keyFactory.generatePrivate(privateKeySpec);
}

public static void deleteDirIfExists(Path dir) throws IOException {
if (!Files.exists(dir)) {
return;
}

Files.walk(dir)
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
}

private Utils() {}
}
15 changes: 8 additions & 7 deletions jdk/test/sm/cert/CertPathBuilderTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -17,6 +17,13 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* @test
* @summary Test CertPathBuilder on SM certificate.
* @compile ../Utils.java
* @run testng CertPathBuilderTest
*/

import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.cert.CertPath;
Expand All @@ -37,12 +44,6 @@

import static org.testng.Assert.assertEquals;

/*
* @test
* @summary Test CertPathBuilder on SM certificate.
* @compile ../Utils.java
* @run testng CertPathBuilderTest
*/
public class CertPathBuilderTest {

private static final String TEST_BASE = System.getProperty("test.src");
Expand Down
15 changes: 8 additions & 7 deletions jdk/test/sm/cert/CertPathValidatorTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -17,6 +17,13 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* @test
* @summary Test CertPathValidator on SM certificate.
* @compile ../Utils.java
* @run testng/othervm CertPathValidatorTest
*/

import java.math.BigInteger;
import java.net.InetAddress;
import java.nio.file.Path;
Expand Down Expand Up @@ -46,12 +53,6 @@
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

/*
* @test
* @summary Test CertPathValidator on SM certificate.
* @compile ../Utils.java
* @run testng/othervm CertPathValidatorTest
*/
public class CertPathValidatorTest {

private static final String TEST_BASE = System.getProperty("test.src");
Expand Down
15 changes: 8 additions & 7 deletions jdk/test/sm/cert/CertStoreTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -17,6 +17,13 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* @test
* @summary Test CertStore on SM certificate.
* @compile ../Utils.java
* @run testng CertStoreTest
*/

import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.cert.CertStore;
Expand All @@ -31,12 +38,6 @@

import static org.testng.Assert.assertEquals;

/*
* @test
* @summary Test CertStore on SM certificate.
* @compile ../Utils.java
* @run testng CertStoreTest
*/
public class CertStoreTest {

private static final String TEST_BASE = System.getProperty("test.src");
Expand Down
15 changes: 8 additions & 7 deletions jdk/test/sm/cert/CertificateFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -17,6 +17,13 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* @test
* @summary Test CertificateFactory on SM certificate.
* @compile ../Utils.java
* @run testng CertificateFactoryTest
*/

import java.io.ByteArrayInputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -37,12 +44,6 @@

import static org.testng.Assert.assertEquals;

/*
* @test
* @summary Test CertificateFactory on SM certificate.
* @compile ../Utils.java
* @run testng CertificateFactoryTest
*/
public class CertificateFactoryTest {

private static final String TEST_BASE = System.getProperty("test.src");
Expand Down
15 changes: 8 additions & 7 deletions jdk/test/sm/cert/KeyFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -17,6 +17,13 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* @test
* @summary Test KeyFactory on SM certificate.
* @compile ../Utils.java
* @run testng KeyFactoryTest
*/

import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyFactory;
Expand All @@ -35,12 +42,6 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

/*
* @test
* @summary Test KeyFactory on SM certificate.
* @compile ../Utils.java
* @run testng KeyFactoryTest
*/
public class KeyFactoryTest {

private static final String TEST_BASE = System.getProperty("test.src");
Expand Down
15 changes: 8 additions & 7 deletions jdk/test/sm/cert/KeyStoreTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -17,6 +17,13 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* @test
* @summary Test KeyStore on SM certificate.
* @compile ../Utils.java
* @run testng KeyStoreTest
*/

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
Expand All @@ -33,12 +40,6 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

/*
* @test
* @summary Test KeyStore on SM certificate.
* @compile ../Utils.java
* @run testng KeyStoreTest
*/
public class KeyStoreTest {

private static final String TEST_BASE = System.getProperty("test.src");
Expand Down
15 changes: 8 additions & 7 deletions jdk/test/sm/crypto/SM2/ECKeyPairGeneratorTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2023, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -17,6 +17,13 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* @test
* @summary Test EC key pair generation on SM2 curve.
* @compile ../../Utils.java
* @run testng ECKeyPairGeneratorTest
*/

import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
Expand All @@ -37,12 +44,6 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

/*
* @test
* @summary Test EC key pair generation on SM2 curve.
* @compile ../../Utils.java
* @run testng ECKeyPairGeneratorTest
*/
public class ECKeyPairGeneratorTest {

private final static byte[] MESSAGE
Expand Down
15 changes: 8 additions & 7 deletions jdk/test/sm/crypto/SM2/SM2CipherTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -17,6 +17,13 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* @test
* @summary Test SM2 cipher.
* @compile ../../Utils.java
* @run testng SM2CipherTest
*/

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import java.math.BigInteger;
Expand All @@ -37,12 +44,6 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.expectThrows;

/*
* @test
* @summary Test SM2 cipher.
* @compile ../../Utils.java
* @run testng SM2CipherTest
*/
public class SM2CipherTest {

private static final byte[] EMPTY = new byte[0];
Expand Down
15 changes: 8 additions & 7 deletions jdk/test/sm/crypto/SM2/SM2KeyAgreementTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2023, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -17,6 +17,13 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* @test
* @summary Test SM2 key agreement.
* @compile ../../Utils.java
* @run testng SM2KeyAgreementTest
*/

import javax.crypto.KeyAgreement;
import javax.crypto.SecretKey;
import java.math.BigInteger;
Expand All @@ -37,12 +44,6 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.expectThrows;

/*
* @test
* @summary Test SM2 key agreement.
* @compile ../../Utils.java
* @run testng SM2KeyAgreementTest
*/
public class SM2KeyAgreementTest {

private final static String PUB_KEY
Expand Down
15 changes: 8 additions & 7 deletions jdk/test/sm/crypto/SM2/SM2KeyFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -17,6 +17,13 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* @test
* @summary Test SM2 key factory.
* @compile ../../Utils.java
* @run testng SM2KeyFactoryTest
*/

import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.KeyPair;
Expand All @@ -38,12 +45,6 @@
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.expectThrows;

/*
* @test
* @summary Test SM2 key factory.
* @compile ../../Utils.java
* @run testng SM2KeyFactoryTest
*/
public class SM2KeyFactoryTest {

// starts with 0x05
Expand Down
Loading

0 comments on commit b007135

Please sign in to comment.