Skip to content

Commit

Permalink
move default time to GAU and replace the no-time deserialization test
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewHelmer authored and djc committed Mar 14, 2023
1 parent f06ff27 commit 4f03eeb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 16 additions & 1 deletion src/gcloud_authorized_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ use std::process::Command;
use std::sync::RwLock;

use async_trait::async_trait;
use time::Duration;
use which::which;

use crate::authentication_manager::ServiceAccount;
use crate::error::Error;
use crate::error::Error::{GCloudError, GCloudNotFound, GCloudParseError};
use crate::types::{HyperClient, DEFAULT_TOKEN_DURATION};
use crate::types::HyperClient;
use crate::Token;

/// The default number of seconds that it takes for a Google Cloud auth token to expire.
/// This appears to be the default from practical testing, but we have not found evidence
/// that this will always be the default duration.
pub(crate) const DEFAULT_TOKEN_DURATION: Duration = Duration::seconds(3600);

#[derive(Debug)]
pub(crate) struct GCloudAuthorizedUser {
gcloud: PathBuf,
Expand Down Expand Up @@ -107,4 +113,13 @@ mod tests {
assert!(token.expires_at() < expires + Duration::seconds(1));
assert!(token.expires_at() > expires - Duration::seconds(1));
}

#[test]
fn test_deserialise_no_time() {
let s = r#"{"access_token":"abc123"}"#;
let result = serde_json::from_str::<Token>(s)
.expect_err("Deserialization from JSON should fail when no expiry_time is included");

assert!(result.is_data());
}
}
6 changes: 0 additions & 6 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ use serde::{Deserialize, Serialize};
use time::{Duration, OffsetDateTime};

use crate::Error;

/// The default number of seconds that it takes for a Google Cloud auth token to expire.
/// This appears to be the default from practical testing, but we have not found evidence
/// that this will always be the default duration.
pub(crate) const DEFAULT_TOKEN_DURATION: Duration = Duration::seconds(3600);

/// Represents an access token. All access tokens are Bearer tokens.
///
/// Tokens should not be cached, the [`AuthenticationManager`] handles the correct caching
Expand Down

0 comments on commit 4f03eeb

Please sign in to comment.