Skip to content

Commit 8f8a110

Browse files
committed
fix comments
1 parent a86bafd commit 8f8a110

File tree

7 files changed

+22
-12
lines changed

7 files changed

+22
-12
lines changed

src/main/java/com/aliyun/oss/common/auth/CredentialsProviderFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static DefaultCredentialProvider newDefaultCredentialProvider(String acce
5555
*/
5656
public DefaultCredentialProvider newDefaultCredentialProvider(String accessKeyId, String secretAccessKey,
5757
String securityToken) {
58-
return new DefaultCredentialProvider(accessKeyId, secretAccessKey, null);
58+
return new DefaultCredentialProvider(accessKeyId, secretAccessKey, securityToken);
5959
}
6060

6161
/**

src/main/java/com/aliyun/oss/common/auth/ProfileConfigFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ public void refresh() {
122122
String secretAccessKey = StringUtils.trim(profileProperties.get(AuthUtils.OSS_SECRET_ACCESS_KEY));
123123
String sessionToken = StringUtils.trim(profileProperties.get(AuthUtils.OSS_SESSION_TOKEN));
124124

125-
if (accessKeyId == null || accessKeyId.equals("")) {
125+
if (StringUtils.isNullOrEmpty(accessKeyId)) {
126126
throw new InvalidCredentialsException("Access key id should not be null or empty.");
127127
}
128-
if (secretAccessKey == null || secretAccessKey.equals("")) {
128+
if (StringUtils.isNullOrEmpty(secretAccessKey)) {
129129
throw new InvalidCredentialsException("Secret access key should not be null or empty.");
130130
}
131131

src/main/java/com/aliyun/oss/common/utils/IniEditor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,15 @@ public void load(String filename) throws IOException {
577577
* at an I/O problem
578578
*/
579579
public void load(File file) throws IOException {
580-
InputStream in = new FileInputStream(file);
581-
load(in);
582-
in.close();
580+
InputStream in = null;
581+
try {
582+
in = new FileInputStream(file);
583+
load(in);
584+
} finally {
585+
if (in != null) {
586+
in.close();
587+
}
588+
}
583589
}
584590

585591
/**

src/test/java/com/aliyun/oss/common/provider/InstanceProfileCredentialsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testWillSoonExpire() {
6464
public void testExpiredFactor() {
6565
try {
6666
InstanceProfileCredentials credentials = new InstanceProfileCredentials(ACCESS_KEY_ID, ACCESS_KEY_SECRET, null,
67-
"2020-11-11T11:11:11Z").withExpiredFactor(10000000.0);
67+
"2010-11-11T11:11:11Z").withExpiredFactor(10.0);
6868
Thread.sleep(1000);
6969
Assert.assertTrue(credentials.willSoonExpire());
7070

src/test/java/com/aliyun/oss/common/provider/ProfilesConfigFileTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ public void testGetCredentialsWithLoader() {
124124
@Test
125125
public void testGetFreshCredentials() {
126126
try {
127+
new File(AuthUtils.DEFAULT_PROFILE_PATH).delete();
128+
Thread.sleep(1000);
129+
127130
Map<String, String> options = new HashMap<String, String>();
128131
options.put(AuthUtils.OSS_ACCESS_KEY_ID, TEST_ACCESS_KEY_ID);
129132
options.put(AuthUtils.OSS_SECRET_ACCESS_KEY, TEST_ACCESS_KEY_SECRET);
@@ -137,6 +140,9 @@ public void testGetFreshCredentials() {
137140
Assert.assertEquals(TEST_ACCESS_KEY_SECRET, credentials.getSecretAccessKey());
138141
Assert.assertNull(credentials.getSecurityToken());
139142
Assert.assertFalse(credentials.useSecurityToken());
143+
144+
new File(AuthUtils.DEFAULT_PROFILE_PATH).delete();
145+
Thread.sleep(1000);
140146

141147
// Fresh
142148
options = new HashMap<String, String>();
@@ -152,8 +158,6 @@ public void testGetFreshCredentials() {
152158
Assert.assertEquals(TEST_ACCESS_KEY_SECRET, credentials.getSecretAccessKey());
153159
Assert.assertEquals(TEST_SECURITY_TOKEN, credentials.getSecurityToken());
154160
Assert.assertTrue(credentials.useSecurityToken());
155-
156-
new File(AuthUtils.DEFAULT_PROFILE_PATH).delete();
157161
} catch (Exception e) {
158162
e.printStackTrace();
159163
Assert.fail(e.getMessage());

src/test/java/com/aliyun/oss/common/provider/STSAssumeRoleSessionCredentialsProviderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public void testStsAssumeRoleCredentialsProvider() {
4444
Assert.assertFalse(credentials.willSoonExpire());
4545
Assert.assertTrue(credentials.getAccessKeyId().startsWith("STS."));
4646
Assert.assertEquals(credentials.getAccessKeyId().length(), 29);
47-
Assert.assertEquals(credentials.getSecretAccessKey().length(), 44);
48-
Assert.assertEquals(credentials.getSecurityToken().length(), 544);
47+
Assert.assertTrue(credentials.getSecretAccessKey().length() > 0);
48+
Assert.assertTrue(credentials.getSecurityToken().length() > 0);
4949
} catch (Exception e) {
5050
e.printStackTrace();
5151
Assert.fail(e.getMessage());

src/test/java/com/aliyun/oss/common/provider/STSKeyPairSessionCredentialsProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void testStsKeyPairCredentialsProviderNegative() throws ClientException,
9898

9999
credentialsProvider = CredentialsProviderFactory.newSTSKeyPairSessionCredentialsProvider(TestConfig.RAM_REGION_ID,
100100
publicKey.getPublicKeyId(), AuthUtils.loadPrivateKeyFromFile(TestConfig.PRIVATE_KEY_PATH))
101-
.withExpiredDuration(3601);
101+
.withExpiredDuration(100);
102102

103103
Assert.assertNull(credentialsProvider.getCredentials());
104104

0 commit comments

Comments
 (0)