Skip to content

Commit

Permalink
chore: make clippy warnings into failures (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
sighphyre authored Jul 22, 2024
1 parent c1a3acd commit 8e57fe3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 116 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/clippy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,5 @@ jobs:
run: cargo install clippy-sarif sarif-fmt
- name: Run rust-clippy
run: |
cargo clippy --all-features --message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
continue-on-error: true
- name: Upload analysis results to Github
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: rust-clippy-results.sarif
category: clippy
wait-for-processing: true
cargo clippy --all-features -- -D warnings
24 changes: 13 additions & 11 deletions server/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use unleash_types::client_features::ClientFeatures;
use unleash_yggdrasil::EngineState;

use crate::cli::RedisMode;
use crate::http::unleash_client::new_reqwest_client;
use crate::offline::offline_hotload::{load_bootstrap, load_offline_engine_cache};
use crate::persistence::file::FilePersister;
use crate::persistence::redis::RedisPersister;
Expand Down Expand Up @@ -180,18 +181,19 @@ async fn build_edge(args: &EdgeArgs, app_name: &str) -> EdgeResult<EdgeInfo> {

let persistence = get_data_source(args).await;

let http_client = new_reqwest_client(
"unleash_edge".into(),
args.skip_ssl_verification,
args.client_identity.clone(),
args.upstream_certificate_file.clone(),
Duration::seconds(args.upstream_request_timeout),
Duration::seconds(args.upstream_socket_timeout),
app_name.into(),
)?;

let unleash_client = Url::parse(&args.upstream_url.clone())
.map(|url| {
UnleashClient::from_url(
url,
args.skip_ssl_verification,
args.client_identity.clone(),
args.upstream_certificate_file.clone(),
Duration::seconds(args.upstream_request_timeout),
Duration::seconds(args.upstream_socket_timeout),
args.token_header.token_header.clone(),
app_name.into(),
)
UnleashClient::from_url(url, args.token_header.token_header.clone(), http_client)
})
.map(|c| c.with_custom_client_headers(args.custom_client_headers.clone()))
.map(Arc::new)
Expand Down Expand Up @@ -298,7 +300,7 @@ mod tests {
token_revalidation_interval_seconds: Default::default(),
};

let result = build_edge(&args, &"test-app").await;
let result = build_edge(&args, "test-app").await;
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
Expand Down
100 changes: 24 additions & 76 deletions server/src/http/feature_refresher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ mod tests {
use unleash_yggdrasil::EngineState;

use crate::filters::{project_filter, FeatureFilterSet};
use crate::http::unleash_client::new_reqwest_client;
use crate::tests::features_from_disk;
use crate::tokens::cache_key;
use crate::types::TokenValidationStatus::Validated;
Expand All @@ -483,18 +484,28 @@ mod tests {
}
}

#[tokio::test]
pub async fn registering_token_for_refresh_works() {
let unleash_client = UnleashClient::from_url(
Url::parse("http://localhost:4242").unwrap(),
fn create_test_client() -> UnleashClient {
let http_client = new_reqwest_client(
"unleash_edge".into(),
false,
None,
None,
Duration::seconds(5),
Duration::seconds(5),
"Authorization".to_string(),
"test-client".into(),
);
)
.expect("Failed to create client");

UnleashClient::from_url(
Url::parse("http://localhost:4242").unwrap(),
"Authorization".to_string(),
http_client,
)
}

#[tokio::test]
pub async fn registering_token_for_refresh_works() {
let unleash_client = create_test_client();
let features_cache = Arc::new(DashMap::default());
let engine_cache = Arc::new(DashMap::default());

Expand All @@ -518,16 +529,7 @@ mod tests {
#[tokio::test]
pub async fn registering_multiple_tokens_with_same_environment_reduces_tokens_to_valid_minimal_set(
) {
let unleash_client = UnleashClient::from_url(
Url::parse("http://localhost:4242").unwrap(),
false,
None,
None,
Duration::seconds(5),
Duration::seconds(5),
"Authorization".to_string(),
"test-client".into(),
);
let unleash_client = create_test_client();
let features_cache = Arc::new(DashMap::default());
let engine_cache = Arc::new(DashMap::default());

Expand Down Expand Up @@ -555,16 +557,7 @@ mod tests {

#[tokio::test]
pub async fn registering_multiple_non_overlapping_tokens_will_keep_all() {
let unleash_client = UnleashClient::from_url(
Url::parse("http://localhost:4242").unwrap(),
false,
None,
None,
Duration::seconds(5),
Duration::seconds(5),
"Authorization".to_string(),
"test-client".into(),
);
let unleash_client = create_test_client();
let features_cache = Arc::new(DashMap::default());
let engine_cache = Arc::new(DashMap::default());
let duration = Duration::seconds(5);
Expand Down Expand Up @@ -599,16 +592,7 @@ mod tests {

#[tokio::test]
pub async fn registering_wildcard_project_token_only_keeps_the_wildcard() {
let unleash_client = UnleashClient::from_url(
Url::parse("http://localhost:4242").unwrap(),
false,
None,
None,
Duration::seconds(5),
Duration::seconds(5),
"Authorization".to_string(),
"test-client".into(),
);
let unleash_client = create_test_client();
let features_cache = Arc::new(DashMap::default());
let engine_cache = Arc::new(DashMap::default());
let duration = Duration::seconds(5);
Expand Down Expand Up @@ -652,16 +636,7 @@ mod tests {

#[tokio::test]
pub async fn registering_tokens_with_multiple_projects_overwrites_single_tokens() {
let unleash_client = UnleashClient::from_url(
Url::parse("http://localhost:4242").unwrap(),
false,
None,
None,
Duration::seconds(5),
Duration::seconds(5),
"Authorization".to_string(),
"test-client".into(),
);
let unleash_client = create_test_client();
let features_cache = Arc::new(DashMap::default());
let engine_cache = Arc::new(DashMap::default());
let duration = Duration::seconds(5);
Expand Down Expand Up @@ -709,16 +684,7 @@ mod tests {

#[tokio::test]
pub async fn registering_a_token_that_is_already_subsumed_does_nothing() {
let unleash_client = UnleashClient::from_url(
Url::parse("http://localhost:4242").unwrap(),
false,
None,
None,
Duration::seconds(5),
Duration::seconds(5),
"Authorization".to_string(),
"test-client".into(),
);
let unleash_client = create_test_client();
let features_cache = Arc::new(DashMap::default());
let engine_cache = Arc::new(DashMap::default());

Expand Down Expand Up @@ -751,16 +717,7 @@ mod tests {

#[tokio::test]
pub async fn simplification_only_happens_in_same_environment() {
let unleash_client = UnleashClient::from_url(
Url::parse("http://localhost:4242").unwrap(),
false,
None,
None,
Duration::seconds(5),
Duration::seconds(5),
"Authorization".to_string(),
"test-client".into(),
);
let unleash_client = create_test_client();
let features_cache = Arc::new(DashMap::default());
let engine_cache = Arc::new(DashMap::default());

Expand Down Expand Up @@ -788,16 +745,7 @@ mod tests {

#[tokio::test]
pub async fn is_able_to_only_fetch_for_tokens_due_to_refresh() {
let unleash_client = UnleashClient::from_url(
Url::parse("http://localhost:4242").unwrap(),
false,
None,
None,
Duration::seconds(5),
Duration::seconds(5),
"Authorization".to_string(),
"test-client".into(),
);
let unleash_client = create_test_client();
let features_cache = Arc::new(DashMap::default());
let engine_cache = Arc::new(DashMap::default());

Expand Down
20 changes: 3 additions & 17 deletions server/src/http/unleash_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn build_identity(tls: Option<ClientIdentity>) -> EdgeResult<ClientBuilder> {
)
}

fn new_reqwest_client(
pub fn new_reqwest_client(
instance_id: String,
skip_ssl_verification: bool,
client_identity: Option<ClientIdentity>,
Expand Down Expand Up @@ -180,26 +180,12 @@ pub struct EdgeTokens {
impl UnleashClient {
pub fn from_url(
server_url: Url,
skip_ssl_verification: bool,
client_identity: Option<ClientIdentity>,
upstream_certificate_file: Option<PathBuf>,
connect_timeout: Duration,
socket_timeout: Duration,
token_header: String,
app_name: String,
backing_client: Client,
) -> Self {
Self {
urls: UnleashUrls::from_base_url(server_url),
backing_client: new_reqwest_client(
"unleash_edge".into(),
skip_ssl_verification,
client_identity,
upstream_certificate_file,
connect_timeout,
socket_timeout,
app_name,
)
.unwrap(),
backing_client,
custom_headers: Default::default(),
token_header,
}
Expand Down
15 changes: 11 additions & 4 deletions server/src/middleware/client_token_from_frontend_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod tests {

use crate::auth::token_validator::TokenValidator;
use crate::http::feature_refresher::FeatureRefresher;
use crate::http::unleash_client::UnleashClient;
use crate::http::unleash_client::{new_reqwest_client, UnleashClient};
use crate::tests::upstream_server;
use crate::types::{EdgeToken, TokenType, TokenValidationStatus};

Expand Down Expand Up @@ -132,15 +132,22 @@ mod tests {
upstream_engine_cache.clone(),
)
.await;
let unleash_client = UnleashClient::from_url(
Url::parse(&upstream_server.url("/")).unwrap(),

let http_client = new_reqwest_client(
"unleash_edge".into(),
false,
None,
None,
Duration::seconds(5),
Duration::seconds(5),
"Authorization".to_string(),
"test-client".into(),
)
.expect("Failed to create client");

let unleash_client = UnleashClient::from_url(
Url::parse(&upstream_server.url("/")).unwrap(),
"test-client".into(),
http_client,
);
let local_features_cache: Arc<DashMap<String, ClientFeatures>> =
Arc::new(DashMap::default());
Expand Down
1 change: 1 addition & 0 deletions server/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ impl Default for BuildInfo {
package_major: build::PKG_VERSION_MAJOR.into(),
package_minor: build::PKG_VERSION_MINOR.into(),
package_patch: build::PKG_VERSION_PATCH.into(),
#[allow(clippy::const_is_empty)]
package_version_pre: if build::PKG_VERSION_PRE.is_empty() {
None
} else {
Expand Down

0 comments on commit 8e57fe3

Please sign in to comment.