Skip to content

Commit

Permalink
Change URLs to localhost for tests
Browse files Browse the repository at this point in the history
Surf is still sending requests to B2 even with surf-vcr intercepting
them; this is likely upstream's issue 307[1], but I need to debug to be
certain.

This commit works around the problem by using localhost as our server.
The strange thing is that surf does not appear to always send the
requests, and I have not been able to observe any requests when
listening via netcat.

[1]: http-rs/surf#307
  • Loading branch information
rjframe committed Oct 14, 2021
1 parent f6d9a40 commit c2cf7a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ use chrono::{DateTime, Local};
use serde::{Serialize, Deserialize};


const B2_AUTH_URL: &str = "https://api.backblazeb2.com/b2api/v2/";
const B2_AUTH_URL: &str = if cfg!(test) {
"http://localhost:8765/b2api/v2/"
} else {
"https://api.backblazeb2.com/b2api/v2/"
};

/// Authorization token and related information obtained from
/// [authorize_account].
Expand Down Expand Up @@ -537,11 +541,11 @@ mod tests {
bucket_name: None,
name_prefix: None,
},
api_url: "https://api002.backblazeb2.com".into(),
download_url: "https://f002.backblazeb2.com".into(),
api_url: "http://localhost:8765".into(),
download_url: "http://localhost:8765/download".into(),
recommended_part_size: 100000000,
absolute_minimum_part_size: 5000000,
s3_api_url: "https://s3.us-west-002.backblazeb2.com".into(),
s3_api_url: "http://localhost:8765/s3api".into(),
}
}

Expand Down
10 changes: 5 additions & 5 deletions test_sessions/auth_account.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- Request:
method: GET
url: "https://api.backblazeb2.com/b2api/v2/b2_authorize_account"
url: "http://localhost:8765/b2api/v2/b2_authorize_account"
headers:
authorization:
- Basic QjJfS0VZX0lEOkIyX0FVVEhfS0VZ
Expand All @@ -18,11 +18,11 @@
- "Wed, 13 Oct 2021 14:58:56 GMT"
content-length:
- "720"
body: "{\n \"absoluteMinimumPartSize\": 5000000,\n \"accountId\": \"abcdefg\",\n \"allowed\": {\n \"bucketId\": \"8d625eb63be2775577c70e1a\",\n \"bucketName\": \"testing-b2-client\",\n \"capabilities\": [\n \"listBuckets\",\n \"readBuckets\",\n \"listFiles\",\n \"readFiles\",\n \"shareFiles\",\n \"writeFiles\",\n \"deleteFiles\",\n \"readBucketEncryption\",\n \"writeBucketEncryption\"\n ],\n \"namePrefix\": null\n },\n \"apiUrl\": \"https://api002.backblazeb2.com\",\n \"authorizationToken\": \"4_002d2e6b27577ea0000000002_019f9ac2_4af224_acct_BzTNBWOKUVQvIMyHK3tXHG7YqDQ=\",\n \"downloadUrl\": \"https://f002.backblazeb2.com\",\n \"recommendedPartSize\": 100000000,\n \"s3ApiUrl\": \"https://s3.us-west-002.backblazeb2.com\"\n}\n"
body: "{\n \"absoluteMinimumPartSize\": 5000000,\n \"accountId\": \"abcdefg\",\n \"allowed\": {\n \"bucketId\": \"8d625eb63be2775577c70e1a\",\n \"bucketName\": \"testing-b2-client\",\n \"capabilities\": [\n \"listBuckets\",\n \"readBuckets\",\n \"listFiles\",\n \"readFiles\",\n \"shareFiles\",\n \"writeFiles\",\n \"deleteFiles\",\n \"readBucketEncryption\",\n \"writeBucketEncryption\"\n ],\n \"namePrefix\": null\n },\n \"apiUrl\": \"http://localhost:8765\",\n \"authorizationToken\": \"4_002d2e6b27577ea0000000002_019f9ac2_4af224_acct_BzTNBWOKUVQvIMyHK3tXHG7YqDQ=\",\n \"downloadUrl\": \"http://localhost:8765/download\",\n \"recommendedPartSize\": 100000000,\n \"s3ApiUrl\": \"http://localhost:8765/s3api\"\n}\n"
---
- Request:
method: GET
url: "https://api.backblazeb2.com/b2api/v2/b2_authorize_account"
url: "http://localhost:8765/b2api/v2/b2_authorize_account"
headers:
authorization:
- Basic QjJfS0VZX0lEOndyb25nLWtleQ==
Expand All @@ -45,7 +45,7 @@
---
- Request:
method: GET
url: "https://api.backblazeb2.com/b2api/v2/b2_authorize_account"
url: "http://localhost:8765/b2api/v2/b2_authorize_account"
headers:
authorization:
- Basic d3JvbmctaWQ6QjJfQVVUSF9LRVk=
Expand All @@ -68,7 +68,7 @@
---
- Request:
method: POST
url: "https://api002.backblazeb2.com/b2api/v2/b2_create_key"
url: "http://localhost:8765/b2api/v2/b2_create_key"
headers:
content-type:
- application/json
Expand Down

0 comments on commit c2cf7a8

Please sign in to comment.