use dope_aws::sigv4::{CanonicalRequest, SigningParams, authorization};

const AMZ_DATE: &str = "20150830T123600Z";
const DATE_STAMP: &str = "20150830";

fn params() -> SigningParams<'static> {
    SigningParams {
        access_key_id: "AKIDEXAMPLE",
        secret_access_key: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
        region: "us-east-1",
        service: "service",
    }
}

fn base_headers() -> Vec<(String, String)> {
    vec![
        ("Host".to_string(), "example.amazonaws.com".to_string()),
        ("X-Amz-Date".to_string(), AMZ_DATE.to_string()),
    ]
}

#[test]
fn get_vanilla() {
    let headers = base_headers();
    let req = CanonicalRequest {
        method: "GET",
        path: "/",
        query: &[],
        headers: &headers,
        body: b"",
    };
    let auth = authorization(&params(), &req, AMZ_DATE, DATE_STAMP);
    assert_eq!(
        auth,
        "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, \
         SignedHeaders=host;x-amz-date, \
         Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31"
    );
}

#[test]
fn post_vanilla() {
    let headers = base_headers();
    let req = CanonicalRequest {
        method: "POST",
        path: "/",
        query: &[],
        headers: &headers,
        body: b"",
    };
    let auth = authorization(&params(), &req, AMZ_DATE, DATE_STAMP);
    assert_eq!(
        auth,
        "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, \
         SignedHeaders=host;x-amz-date, \
         Signature=5da7c1a2acd57cee7505fc6676e4e544621c30862966e37dddb68e92efbe5d6b"
    );
}

#[test]
fn get_vanilla_query_order_key_case() {
    let headers = base_headers();
    let query = vec![
        ("Param2".to_string(), "value2".to_string()),
        ("Param1".to_string(), "value1".to_string()),
    ];
    let req = CanonicalRequest {
        method: "GET",
        path: "/",
        query: &query,
        headers: &headers,
        body: b"",
    };
    let auth = authorization(&params(), &req, AMZ_DATE, DATE_STAMP);
    assert_eq!(
        auth,
        "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, \
         SignedHeaders=host;x-amz-date, \
         Signature=b97d918cfa904a5beff61c982a1b6f458b799221646efd99d3219ec94cdf2500"
    );
}
