Skip to content

Commit

Permalink
refactor: make method private
Browse files Browse the repository at this point in the history
It was public becuase it was being used in a test but it can be used the
`authenticate` method instead.
  • Loading branch information
josecelano committed Aug 1, 2024
1 parent e00feef commit 8d58882
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,9 +988,7 @@ impl Tracker {
/// # Errors
///
/// Will return a `key::Error` if unable to get any `auth_key`.
pub async fn verify_auth_key(&self, key: &Key) -> Result<(), auth::Error> {
// code-review: this function is public only because it's used in a test.
// We should change the test and make it private.
async fn verify_auth_key(&self, key: &Key) -> Result<(), auth::Error> {
match self.keys.read().await.get(key) {
None => Err(auth::Error::UnableToReadKey {
location: Location::caller(),
Expand Down Expand Up @@ -1830,13 +1828,11 @@ mod tests {

#[tokio::test]
async fn it_should_verify_a_valid_authentication_key() {
// todo: this should not be tested directly because
// `verify_auth_key` should be a private method.
let tracker = private_tracker();

let expiring_key = tracker.generate_auth_key(Some(Duration::from_secs(100))).await.unwrap();

assert!(tracker.verify_auth_key(&expiring_key.key()).await.is_ok());
assert!(tracker.authenticate(&expiring_key.key()).await.is_ok());
}

#[tokio::test]
Expand Down
9 changes: 3 additions & 6 deletions tests/servers/api/v1/contract/context/auth_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ async fn should_allow_generating_a_new_random_auth_key() {

let auth_key_resource = assert_auth_key_utf8(response).await;

// Verify the key with the tracker
assert!(env
.tracker
.verify_auth_key(&auth_key_resource.key.parse::<Key>().unwrap())
.authenticate(&auth_key_resource.key.parse::<Key>().unwrap())
.await
.is_ok());

Expand All @@ -49,10 +48,9 @@ async fn should_allow_uploading_a_preexisting_auth_key() {

let auth_key_resource = assert_auth_key_utf8(response).await;

// Verify the key with the tracker
assert!(env
.tracker
.verify_auth_key(&auth_key_resource.key.parse::<Key>().unwrap())
.authenticate(&auth_key_resource.key.parse::<Key>().unwrap())
.await
.is_ok());

Expand Down Expand Up @@ -357,10 +355,9 @@ mod deprecated_generate_key_endpoint {

let auth_key_resource = assert_auth_key_utf8(response).await;

// Verify the key with the tracker
assert!(env
.tracker
.verify_auth_key(&auth_key_resource.key.parse::<Key>().unwrap())
.authenticate(&auth_key_resource.key.parse::<Key>().unwrap())
.await
.is_ok());

Expand Down

0 comments on commit 8d58882

Please sign in to comment.