From dfa552f3201e3fc672bbfcd3b80524f151cf61a6 Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Fri, 19 Jul 2024 17:59:24 +0800 Subject: [PATCH] fix unit test for OIDC --- .github/workflows/maven.yml | 4 +++- .../java/com/aliyuncs/auth/OIDCCredentialsProviderTest.java | 3 ++- .../test/java/com/aliyuncs/utils/EnvironmentUtilsTest.java | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 80534cb68d..d9ce30ca7a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -31,7 +31,9 @@ jobs: distribution: 'zulu' java-version: ${{ matrix.java }} - name: Test with Maven - run: mvn test -B -f ./aliyun-java-sdk-core/pom.xml + run: | + java -version + mvn test -B -f ./aliyun-java-sdk-core/pom.xml - name: Upload Coverage Report uses: codecov/codecov-action@v4 with: diff --git a/aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/OIDCCredentialsProviderTest.java b/aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/OIDCCredentialsProviderTest.java index 6fbda1c7be..bfc8b2d474 100644 --- a/aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/OIDCCredentialsProviderTest.java +++ b/aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/OIDCCredentialsProviderTest.java @@ -66,7 +66,7 @@ public void run() throws Throwable { @Test public void getCredentialsTest() throws ClientException { String filePath = OIDCCredentialsProviderTest.class.getClassLoader().getResource("oidctoken").getPath(); - final AlibabaCloudCredentialsProvider provider = new OIDCCredentialsProvider("roleArn", "providerArn", filePath, null, null); + final AlibabaCloudCredentialsProvider provider = new OIDCCredentialsProvider("roleArn", "providerArn", filePath, null, "us-west-1"); Assert.assertNotNull(provider); ClientException ex = Assert.assertThrows(ClientException.class, new ThrowingRunnable() { @Override @@ -74,6 +74,7 @@ public void run() throws Throwable { provider.getCredentials(); } }); + ex.printStackTrace(); String message = ex.getMessage(); Assert.assertTrue(message.contains("Parameter OIDCProviderArn is not valid")); } diff --git a/aliyun-java-sdk-core/src/test/java/com/aliyuncs/utils/EnvironmentUtilsTest.java b/aliyun-java-sdk-core/src/test/java/com/aliyuncs/utils/EnvironmentUtilsTest.java index 45efa41988..84a6d9ea4e 100644 --- a/aliyun-java-sdk-core/src/test/java/com/aliyuncs/utils/EnvironmentUtilsTest.java +++ b/aliyun-java-sdk-core/src/test/java/com/aliyuncs/utils/EnvironmentUtilsTest.java @@ -15,6 +15,8 @@ public void testGetSetHttpProxy() { Assert.assertNull(EnvironmentUtils.getHttpProxy()); EnvironmentUtils.setHttpProxy("http://www.aliyun.com"); Assert.assertEquals("http://www.aliyun.com", EnvironmentUtils.getHttpProxy()); + // reset http proxy + EnvironmentUtils.setHttpProxy(null); } @Test @@ -22,6 +24,8 @@ public void testGetSetHttpsProxy() { Assert.assertNull(EnvironmentUtils.getHttpsProxy()); EnvironmentUtils.setHttpsProxy("https://www.aliyun.com"); Assert.assertEquals("https://www.aliyun.com", EnvironmentUtils.getHttpsProxy()); + // reset https proxy + EnvironmentUtils.setHttpsProxy(null); } @Test @@ -29,5 +33,7 @@ public void testGetSetNoProxy() { Assert.assertNull(EnvironmentUtils.getNoProxy()); EnvironmentUtils.setNoProxy("https://www.aliyun.com"); Assert.assertEquals("https://www.aliyun.com", EnvironmentUtils.getNoProxy()); + // reset no proxy + EnvironmentUtils.setNoProxy(null); } }