forked from tatsuya6502/rusoto
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinstance-profile-test.rs
More file actions
30 lines (26 loc) · 1.15 KB
/
instance-profile-test.rs
File metadata and controls
30 lines (26 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use rusoto_credential::{IMDSVersion, InstanceMetadataProvider, ProvideAwsCredentials};
use std::time::Duration;
// This test is marked ignored because it requires special setup.
// It's run with the `credential_integration_test` Makefile target.
#[tokio::test]
#[ignore]
async fn it_fetches_basic_role() {
fetches_basic_role_impl(IMDSVersion::V1).await;
fetches_basic_role_impl(IMDSVersion::V2).await;
}
async fn fetches_basic_role_impl(ver: IMDSVersion) {
// set env vars to point to local provider
let mut provider = InstanceMetadataProvider::new();
provider.set_timeout(Duration::from_secs(5));
provider.set_ip_addr_with_port("127.0.0.1", "8080");
provider.set_version(ver);
let creds = provider.credentials().await.expect("credentials");
assert_eq!(creds.aws_access_key_id(), "Access_key_id_value");
assert_eq!(creds.aws_secret_access_key(), "Secret_access_key_value");
assert_eq!(creds.token().as_ref(), Some(&"AAAAA".to_string()));
let dt = match creds.expires_at().as_ref() {
Some(d) => d.to_string(),
None => panic!("Expiration should be present"),
};
assert_eq!(dt, "2015-08-04 06:32:37 UTC");
}