Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not unwrap when creating a bucket #82

Merged
merged 2 commits into from
Oct 4, 2023

Conversation

irevoire
Copy link
Contributor

Hey, while trying this amazing lib, I miss-typed my URL and got an unwrap from the lib; I guess it’s better to forward the error to the caller than panicking in the callee, right?

@paolobarbolini
Copy link
Owner

paolobarbolini commented Sep 26, 2023

Thanks for the PR. We didn't expect that unwrap to be reachable honestly. Could you share the miss-typed URL?

@codecov
Copy link

codecov bot commented Sep 26, 2023

Codecov Report

Merging #82 (8197a85) into main (0b60b9d) will decrease coverage by 0.81%.
Report is 4 commits behind head on main.
The diff coverage is 62.50%.

@@            Coverage Diff             @@
##             main      #82      +/-   ##
==========================================
- Coverage   91.03%   90.23%   -0.81%     
==========================================
  Files          29       29              
  Lines        1361     1372      +11     
==========================================
- Hits         1239     1238       -1     
- Misses        122      134      +12     
Files Coverage Δ
src/bucket.rs 92.91% <62.50%> (-2.29%) ⬇️

... and 2 files with indirect coverage changes

@irevoire
Copy link
Contributor Author

Hey @paolobarbolini,

Here is the exact code I ran to trigger this panic:

use std::time::Duration;

use rusty_s3::actions::{CreateBucket, S3Action};
use rusty_s3::{Bucket, Credentials, UrlStyle};

#[test]
pub fn create_bucket() {
    let mut buf = [0; 8];
    getrandom::getrandom(&mut buf).expect("getrandom");

    let name = "tamo".to_string();

    let url = "http://localhost:9000".parse().unwrap();
    let key = "minioadmin";
    let secret = "minioadmin";
    let region = "minio";

    let bucket = Bucket::new(url, UrlStyle::VirtualHost, name, region).unwrap();
    let credentials = Credentials::new(key, secret);

    let action = CreateBucket::new(&bucket, &credentials);
    let url = action.sign(Duration::from_secs(60));
    ureq::put(dbg!(url.as_str())).call().unwrap();
}

And here’s the logs:

[tests/create_bucket.rs:23] url.as_str() = "http://tamo.localhost:9000/?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20230926%2Fminio%2Fs3%2Faws4_request&X-Amz-Date=20230926T171833Z&X-Amz-Expires=60&X-Amz-SignedHeaders=host&X-Amz-Signature=29a6c757fb080c06dd0834df2765b3004592aee46e47c700dd1712be11b3c0f6"
thread 'create_bucket' panicked at tests/create_bucket.rs:23:42:
called `Result::unwrap()` on an `Err` value: Transport(Transport { kind: Dns, message: Some("resolve dns name 'tamo.localhost:9000'"), url: Some(Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("tamo.localhost")), port: Some(9000), path: "/", query: Some("X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20230926%2Fminio%2Fs3%2Faws4_request&X-Amz-Date=20230926T171833Z&X-Amz-Expires=60&X-Amz-SignedHeaders=host&X-Amz-Signature=29a6c757fb080c06dd0834df2765b3004592aee46e47c700dd1712be11b3c0f6"), fragment: None }), source: Some(Custom { kind: Uncategorized, error: "failed to lookup address information: nodename nor servname provided, or not known" }) })

So, from what I understand,

Could you share the miss-typed URL?

The URL is http://tamo.localhost:9000/?...stuff....

Also, the fix is to change the UrlStyle::VirtualHost to UrlStyle::Path.

I’ll be honest, I’m a huge S3 noob, so I have no idea of what it means (I see it changes the URL, but I don't even know why I have the choice 😅).

You can reproduce this issue easily on your side by updating the tests/common.rs file and changing the UrlStyle. Then just run cargo test --test create_delete_bucket

Copy link
Owner

@paolobarbolini paolobarbolini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and the for posting the reproduction. I'll try merging and releasing over the weekend

src/bucket.rs Outdated Show resolved Hide resolved
Co-authored-by: Paolo Barbolini <paolo@paolo565.org>
@paolobarbolini paolobarbolini merged commit 75699a8 into paolobarbolini:main Oct 4, 2023
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants