Skip to content

Commit d90f59e

Browse files
committed
bak
1 parent f6e432e commit d90f59e

File tree

4 files changed

+54
-30
lines changed

4 files changed

+54
-30
lines changed

server/src/file_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl FileCache {
233233
.cloned();
234234
if let Some(v) = index_opt {
235235
result.insert(format!("{key_prefix}/"), v.clone());
236-
result.insert(key_prefix.to_string(), v); //GitHub Action CI would trigger This, but I could not trigger this in my compute
236+
// result.insert(key_prefix.to_string(), v); //GitHub Action CI would trigger This, but I could not trigger this in my compute
237237
}
238238
}
239239
None => {

tests/tests/acme_test.rs

+31-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::common::*;
2+
use spa_server::config::get_host_path_from_domain;
23
use std::fs;
34
use std::path::PathBuf;
45
use std::time::Duration;
56
use tokio::time::sleep;
6-
use spa_server::config::get_host_path_from_domain;
77

88
mod common;
99

@@ -30,19 +30,35 @@ async fn simple_acme_test() {
3030
upload_file_and_check(domain, request_prefix, 1, vec![]).await;
3131

3232
let (api, _) = get_client_api("client_config.conf");
33-
let mut wait_count =0;
33+
let mut wait_count = 0;
3434
loop {
35-
assert!(wait_count < 30, "30 seconds doest not have cert");
35+
assert!(wait_count < 60, "60 seconds doest not have cert");
3636
sleep(Duration::from_secs(1)).await;
37-
let cert_info = api.get_acme_cert_info(Some(get_host_path_from_domain(domain).0.to_string())).await.unwrap();
37+
let cert_info = api
38+
.get_acme_cert_info(Some(get_host_path_from_domain(domain).0.to_string()))
39+
.await
40+
.unwrap();
3841
if !cert_info.is_empty() {
39-
break
42+
break;
4043
}
41-
wait_count +=1;
44+
wait_count += 1;
4245
}
43-
46+
47+
assert_redirect_correct(request_prefix, "/27/").await;
48+
assert_redirect_correct(
49+
&format!("http://{LOCAL_HOST}:5002/27"),
50+
&format!("https://{LOCAL_HOST}:8443/27"),
51+
)
52+
.await;
53+
4454
assert_files(domain, request_prefix, 1, vec!["", "index.html"]).await;
45-
assert_files(domain, &format!("http://{LOCAL_HOST}:8443/27"), 1, vec!["", "index.html"]).await;
55+
assert_files(
56+
domain,
57+
&format!("http://{LOCAL_HOST}:5002/27"),
58+
1,
59+
vec!["", "index.html"],
60+
)
61+
.await;
4662
/*
4763
wait_count = 0;
4864
server.abort();
@@ -63,7 +79,6 @@ async fn simple_acme_test() {
6379
*/
6480
}
6581

66-
6782
#[tokio::test]
6883
async fn simple_acme_test2() {
6984
let domain = LOCAL_HOST.to_owned();
@@ -77,15 +92,18 @@ async fn simple_acme_test2() {
7792
upload_file_and_check(domain, request_prefix, 1, vec![]).await;
7893

7994
let (api, _) = get_client_api("client_config.conf");
80-
let mut wait_count =0;
95+
let mut wait_count = 0;
8196
loop {
8297
assert!(wait_count < 30, "30 seconds doest not have cert");
8398
sleep(Duration::from_secs(1)).await;
84-
let cert_info = api.get_acme_cert_info(Some(get_host_path_from_domain(domain).0.to_string())).await.unwrap();
99+
let cert_info = api
100+
.get_acme_cert_info(Some(get_host_path_from_domain(domain).0.to_string()))
101+
.await
102+
.unwrap();
85103
if !cert_info.is_empty() {
86-
break
104+
break;
87105
}
88-
wait_count +=1;
106+
wait_count += 1;
89107
}
90108

91109
assert_files(domain, request_prefix, 1, vec!["", "index.html"]).await;

tests/tests/common.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ pub async fn assert_files(
134134
get_file_text(domain, version, file).unwrap()
135135
);
136136
println!("begin to check: {request_prefix}/, version:{version}");
137-
let result = client.get(format!("{request_prefix}/")).send().await.unwrap();
137+
let result = client
138+
.get(format!("{request_prefix}/"))
139+
.send()
140+
.await
141+
.unwrap();
138142
assert_eq!(result.status(), StatusCode::OK);
139143
assert_eq!(
140144
result.text().await.unwrap(),
@@ -143,28 +147,28 @@ pub async fn assert_files(
143147
}
144148
}
145149
}
146-
pub async fn assert_index_redirect_correct(request_prefix: &str) {
150+
pub async fn assert_redirect_correct(request_prefix: &str, target_prefix: &str) {
147151
let client = ClientBuilder::new()
148152
.danger_accept_invalid_certs(true)
149153
.redirect(Policy::none())
150154
.build()
151155
.unwrap();
152156
let query = [("lang", "rust"), ("browser", "servo"), ("zh", "转义字符")];
153-
let url = Url::parse_with_params(request_prefix,
154-
&query).unwrap();
157+
let url = Url::parse_with_params(request_prefix, &query).unwrap();
155158
println!("{}", url);
156159
let path = url.path();
157160
let query = url.query().unwrap();
158-
let response= client.get(url.clone()).send().await.unwrap();
159-
assert_eq!(response.status(),StatusCode::MOVED_PERMANENTLY);
160-
assert_eq!(response.headers().get("location").unwrap().to_str().unwrap(),
161-
format!("{path}/?{query}")
161+
let response = client.get(url.clone()).send().await.unwrap();
162+
assert_eq!(response.status(), StatusCode::MOVED_PERMANENTLY);
163+
assert_eq!(
164+
response
165+
.headers()
166+
.get("location")
167+
.unwrap()
168+
.to_str()
169+
.unwrap(),
170+
format!("{target_prefix}?{query}") //format!("{path}/?{query}")
162171
);
163-
164-
165-
166-
167-
168172
}
169173
pub async fn assert_files_no_exists(request_prefix: &str, check_path: Vec<&'static str>) {
170174
for file in check_path {

tests/tests/starter.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use reqwest::header::LOCATION;
12
use reqwest::redirect::Policy;
23
use reqwest::{ClientBuilder, StatusCode};
34
use std::time::Duration;
@@ -6,7 +7,6 @@ mod common;
67
use crate::common::*;
78
use common::run_server;
89

9-
1010
#[tokio::test(flavor = "multi_thread", worker_threads = 3)]
1111
async fn start_server_and_client_upload_file() {
1212
let domain = LOCAL_HOST.to_owned() + "/27";
@@ -21,7 +21,7 @@ async fn start_server_and_client_upload_file() {
2121
tokio::time::sleep(Duration::from_secs(1)).await;
2222

2323
upload_file_and_check(domain, request_prefix, 1, vec!["", "index.html"]).await;
24-
assert_index_redirect_correct(request_prefix).await;
24+
assert_redirect_correct(request_prefix, "/27/").await;
2525

2626
assert_expired(
2727
request_prefix,
@@ -185,7 +185,7 @@ async fn self_signed_cert_https() {
185185
run_server_with_config("server_config_https.conf");
186186
tokio::time::sleep(Duration::from_secs(2)).await;
187187
upload_file_and_check(domain, request_prefix, 1, vec!["", "index.html", "1.html"]).await;
188-
assert_index_redirect_correct(request_prefix).await;
188+
assert_redirect_correct(request_prefix, "/27/").await;
189189
assert_files(
190190
domain,
191191
&format!("http://{LOCAL_HOST}:8080/27"),
@@ -203,4 +203,6 @@ async fn self_signed_cert_https() {
203203
.await
204204
.unwrap();
205205
assert_eq!(result.status(), StatusCode::MOVED_PERMANENTLY);
206+
let location = result.headers().get(LOCATION).unwrap().to_str().unwrap();
207+
assert_eq!(location, format!("https://{LOCAL_HOST}:8443/27/index.html"))
206208
}

0 commit comments

Comments
 (0)