use of com.aliyun.oss.common.auth.ProfileConfigLoader in project aliyun-oss-java-sdk by aliyun.
the class ProfileConfigLoaderTest method testProfileConfigLoader.
@Test
public void testProfileConfigLoader() {
try {
// generate profile
Map<String, String> options = new HashMap<String, String>();
options.put(AuthUtils.OSS_ACCESS_KEY_ID, TEST_ACCESS_KEY_ID);
options.put(AuthUtils.OSS_SECRET_ACCESS_KEY, TEST_ACCESS_KEY_SECRET);
options.put(AuthUtils.OSS_SESSION_TOKEN, TEST_SECURITY_TOKEN);
generateProfileFile(AuthUtils.DEFAULT_PROFILE_PATH, AuthUtils.DEFAULT_SECTION_NAME, options);
// load profiel
ProfileConfigLoader profileLoader = new ProfileConfigLoader();
Map<String, String> properties = profileLoader.loadProfile(new File(AuthUtils.DEFAULT_PROFILE_PATH));
// check
Assert.assertEquals(TEST_ACCESS_KEY_ID, properties.get(AuthUtils.OSS_ACCESS_KEY_ID));
Assert.assertEquals(TEST_ACCESS_KEY_SECRET, properties.get(AuthUtils.OSS_SECRET_ACCESS_KEY));
Assert.assertEquals(TEST_SECURITY_TOKEN, properties.get(AuthUtils.OSS_SESSION_TOKEN));
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.common.auth.ProfileConfigLoader in project aliyun-oss-java-sdk by aliyun.
the class ProfilesConfigFileTest method testGetCredentialsWithLoader.
@Test
public void testGetCredentialsWithLoader() {
try {
// STS
Map<String, String> options = new HashMap<String, String>();
options.put(AuthUtils.OSS_ACCESS_KEY_ID, TEST_ACCESS_KEY_ID);
options.put(AuthUtils.OSS_SECRET_ACCESS_KEY, TEST_ACCESS_KEY_SECRET);
options.put(AuthUtils.OSS_SESSION_TOKEN, TEST_SECURITY_TOKEN);
generateProfileFile(AuthUtils.DEFAULT_PROFILE_PATH, AuthUtils.DEFAULT_SECTION_NAME, options);
ProfileConfigLoader profileLoader = new ProfileConfigLoader();
ProfileConfigFile configFile = new ProfileConfigFile(new File(AuthUtils.DEFAULT_PROFILE_PATH), profileLoader);
Credentials credentials = configFile.getCredentials();
Assert.assertEquals(TEST_ACCESS_KEY_ID, credentials.getAccessKeyId());
Assert.assertEquals(TEST_ACCESS_KEY_SECRET, credentials.getSecretAccessKey());
Assert.assertEquals(TEST_SECURITY_TOKEN, credentials.getSecurityToken());
Assert.assertTrue(credentials.useSecurityToken());
new File(AuthUtils.DEFAULT_PROFILE_PATH).delete();
// Normal
options = new HashMap<String, String>();
options.put(AuthUtils.OSS_ACCESS_KEY_ID, TEST_ACCESS_KEY_ID);
options.put(AuthUtils.OSS_SECRET_ACCESS_KEY, TEST_ACCESS_KEY_SECRET);
generateProfileFile(AuthUtils.DEFAULT_PROFILE_PATH, AuthUtils.DEFAULT_SECTION_NAME, options);
configFile = new ProfileConfigFile(new File(AuthUtils.DEFAULT_PROFILE_PATH), profileLoader);
credentials = configFile.getCredentials();
Assert.assertEquals(TEST_ACCESS_KEY_ID, credentials.getAccessKeyId());
Assert.assertEquals(TEST_ACCESS_KEY_SECRET, credentials.getSecretAccessKey());
Assert.assertNull(credentials.getSecurityToken());
Assert.assertFalse(credentials.useSecurityToken());
new File(AuthUtils.DEFAULT_PROFILE_PATH).delete();
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations