-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #109: Revert unintentional change for auth key generation API e…
…ndpoint 409f82a test: [#108] add e2e test for auth key generation API endpoint (Jose Celano) ede0460 feat: [#108] add dev dependency reqwest (Jose Celano) 23916a6 fix: [#108] revert change in auth key generation endpoint (Jose Celano) Pull request description: Tasks: - [x] Revert change. - [x] E2E test for the endpoint. ACKs for top commit: da2ce7: ACK 409f82a Tree-SHA512: 66422f2ab68925581fde950b1d618899189160df1d0d07c747f833d909d44fe2f945d212362cd8454f1f9c384f67b1c4dffdde66ec5e175a1cd12114977e630d
- Loading branch information
Showing
10 changed files
with
337 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
/config.toml | ||
/data.db | ||
/.vscode/launch.json | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod resources; | ||
pub mod server; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use std::convert::From; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::key::AuthKey; | ||
use crate::protocol::clock::DurationSinceUnixEpoch; | ||
|
||
#[derive(Serialize, Deserialize, Debug, PartialEq)] | ||
pub struct AuthKeyResource { | ||
pub key: String, | ||
pub valid_until: Option<u64>, | ||
} | ||
|
||
impl From<AuthKeyResource> for AuthKey { | ||
fn from(auth_key_resource: AuthKeyResource) -> Self { | ||
AuthKey { | ||
key: auth_key_resource.key, | ||
valid_until: auth_key_resource | ||
.valid_until | ||
.map(|valid_until| DurationSinceUnixEpoch::new(valid_until, 0)), | ||
} | ||
} | ||
} | ||
|
||
impl From<AuthKey> for AuthKeyResource { | ||
fn from(auth_key: AuthKey) -> Self { | ||
AuthKeyResource { | ||
key: auth_key.key, | ||
valid_until: auth_key.valid_until.map(|valid_until| valid_until.as_secs()), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::time::Duration; | ||
|
||
use super::AuthKeyResource; | ||
use crate::key::AuthKey; | ||
use crate::protocol::clock::{DefaultClock, TimeNow}; | ||
|
||
#[test] | ||
fn it_should_be_convertible_into_an_auth_key() { | ||
let duration_in_secs = 60; | ||
|
||
let auth_key_resource = AuthKeyResource { | ||
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line | ||
valid_until: Some(duration_in_secs), | ||
}; | ||
|
||
assert_eq!( | ||
AuthKey::from(auth_key_resource), | ||
AuthKey { | ||
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line | ||
valid_until: Some(DefaultClock::add(&Duration::new(duration_in_secs, 0)).unwrap()) | ||
} | ||
) | ||
} | ||
|
||
#[test] | ||
fn it_should_be_convertible_from_an_auth_key() { | ||
let duration_in_secs = 60; | ||
|
||
let auth_key = AuthKey { | ||
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line | ||
valid_until: Some(DefaultClock::add(&Duration::new(duration_in_secs, 0)).unwrap()), | ||
}; | ||
|
||
assert_eq!( | ||
AuthKeyResource::from(auth_key), | ||
AuthKeyResource { | ||
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line | ||
valid_until: Some(duration_in_secs) | ||
} | ||
) | ||
} | ||
|
||
#[test] | ||
fn it_should_be_convertible_into_json() { | ||
assert_eq!( | ||
serde_json::to_string(&AuthKeyResource { | ||
key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".to_string(), // cspell:disable-line | ||
valid_until: Some(60) | ||
}) | ||
.unwrap(), | ||
"{\"key\":\"IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM\",\"valid_until\":60}" // cspell:disable-line | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//! These are the Rest API resources. | ||
//! | ||
//! WIP. Not all endpoints have their resource structs. | ||
//! | ||
//! - [x] AuthKeys | ||
//! - [ ] ... | ||
//! - [ ] ... | ||
//! - [ ] ... | ||
pub mod auth_key_resource; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.