mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-27 16:26:40 +03:00
Fix URL runtime evaluation.
This commit is contained in:
parent
264c6f290b
commit
4f6a00170a
7
integration/tests_failed/invalid_url_1.err
Normal file
7
integration/tests_failed/invalid_url_1.err
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
error: Invalid URL
|
||||||
|
--> tests_failed/invalid_url_1.hurl:3:5
|
||||||
|
|
|
||||||
|
3 | GET {{host}}
|
||||||
|
| ^^^^^^^^ URL <localhost:8000> must start with http:// or https://
|
||||||
|
|
|
||||||
|
|
2
integration/tests_failed/invalid_url_1.exit
Normal file
2
integration/tests_failed/invalid_url_1.exit
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
3
|
||||||
|
|
5
integration/tests_failed/invalid_url_1.html
Normal file
5
integration/tests_failed/invalid_url_1.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"></span><span class="comment"># We test that an URL should be valid (starts with http:// or https://)</span>
|
||||||
|
<span class="line"></span><span class="comment"># even if injected through variable.</span>
|
||||||
|
<span class="line"><span class="method">GET</span> <span class="url">{{host}}</span></span>
|
||||||
|
</span></span><span class="line"></span>
|
||||||
|
</code></pre>
|
4
integration/tests_failed/invalid_url_1.hurl
Normal file
4
integration/tests_failed/invalid_url_1.hurl
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# We test that an URL should be valid (starts with http:// or https://)
|
||||||
|
# even if injected through variable.
|
||||||
|
GET {{host}}
|
||||||
|
|
1
integration/tests_failed/invalid_url_1.json
Normal file
1
integration/tests_failed/invalid_url_1.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"entries":[{"request":{"method":"GET","url":"{{host}}"}}]}
|
3
integration/tests_failed/invalid_url_1.ps1
Normal file
3
integration/tests_failed/invalid_url_1.ps1
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Set-StrictMode -Version latest
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
hurl --variable host=localhost:8000 tests_failed/invalid_url_1.hurl
|
3
integration/tests_failed/invalid_url_1.sh
Executable file
3
integration/tests_failed/invalid_url_1.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -Eeuo pipefail
|
||||||
|
hurl --variable host=localhost:8000 tests_failed/invalid_url_1.hurl
|
@ -41,6 +41,7 @@ pub enum HttpError {
|
|||||||
description: String,
|
description: String,
|
||||||
},
|
},
|
||||||
InvalidUrl(String),
|
InvalidUrl(String),
|
||||||
|
InvalidUrlPrefix(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<curl::Error> for HttpError {
|
impl From<curl::Error> for HttpError {
|
||||||
|
@ -68,17 +68,19 @@ impl Request {
|
|||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
Err(_) => return Err(HttpError::InvalidUrl(self.url.clone())),
|
Err(_) => return Err(HttpError::InvalidUrl(self.url.clone())),
|
||||||
};
|
};
|
||||||
let base_url = format!(
|
let scheme = url.scheme();
|
||||||
"{}://{}{}",
|
if scheme != "http" && scheme != "https" {
|
||||||
url.scheme(),
|
return Err(HttpError::InvalidUrlPrefix(self.url.clone()));
|
||||||
url.host().unwrap(),
|
|
||||||
if let Some(port) = url.port() {
|
|
||||||
format!(":{port}")
|
|
||||||
} else {
|
|
||||||
"".to_string()
|
|
||||||
}
|
}
|
||||||
);
|
let host = match url.host() {
|
||||||
Ok(base_url)
|
Some(host) => host,
|
||||||
|
None => return Err(HttpError::InvalidUrl(self.url.clone())),
|
||||||
|
};
|
||||||
|
let port = match url.port() {
|
||||||
|
Some(port) => format!(":{port}"),
|
||||||
|
None => "".to_string(),
|
||||||
|
};
|
||||||
|
Ok(format!("{scheme}://{host}{port}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +119,7 @@ pub enum RunnerError {
|
|||||||
value: String,
|
value: String,
|
||||||
},
|
},
|
||||||
InvalidUrl(String),
|
InvalidUrl(String),
|
||||||
|
InvalidUrlPrefix(String),
|
||||||
|
|
||||||
HttpConnection {
|
HttpConnection {
|
||||||
url: String,
|
url: String,
|
||||||
|
@ -31,6 +31,7 @@ impl Error for runner::Error {
|
|||||||
fn description(&self) -> String {
|
fn description(&self) -> String {
|
||||||
match &self.inner {
|
match &self.inner {
|
||||||
RunnerError::InvalidUrl(..) => "Invalid URL".to_string(),
|
RunnerError::InvalidUrl(..) => "Invalid URL".to_string(),
|
||||||
|
RunnerError::InvalidUrlPrefix(..) => "Invalid URL".to_string(),
|
||||||
RunnerError::TemplateVariableNotDefined { .. } => "Undefined variable".to_string(),
|
RunnerError::TemplateVariableNotDefined { .. } => "Undefined variable".to_string(),
|
||||||
RunnerError::VariableNotDefined { .. } => "Undefined variable".to_string(),
|
RunnerError::VariableNotDefined { .. } => "Undefined variable".to_string(),
|
||||||
RunnerError::HttpConnection { .. } => "HTTP connection".to_string(),
|
RunnerError::HttpConnection { .. } => "HTTP connection".to_string(),
|
||||||
@ -75,6 +76,9 @@ impl Error for runner::Error {
|
|||||||
fn fixme(&self) -> String {
|
fn fixme(&self) -> String {
|
||||||
match &self.inner {
|
match &self.inner {
|
||||||
RunnerError::InvalidUrl(url) => format!("invalid URL <{url}>"),
|
RunnerError::InvalidUrl(url) => format!("invalid URL <{url}>"),
|
||||||
|
RunnerError::InvalidUrlPrefix(url) => {
|
||||||
|
format!("URL <{url}> must start with http:// or https://")
|
||||||
|
}
|
||||||
RunnerError::TemplateVariableNotDefined { name } => {
|
RunnerError::TemplateVariableNotDefined { name } => {
|
||||||
format!("you must set the variable {name}")
|
format!("you must set the variable {name}")
|
||||||
}
|
}
|
||||||
@ -203,6 +207,7 @@ impl From<HttpError> for RunnerError {
|
|||||||
RunnerError::UnsupportedContentEncoding(description)
|
RunnerError::UnsupportedContentEncoding(description)
|
||||||
}
|
}
|
||||||
HttpError::InvalidUrl(url) => RunnerError::InvalidUrl(url),
|
HttpError::InvalidUrl(url) => RunnerError::InvalidUrl(url),
|
||||||
|
HttpError::InvalidUrlPrefix(url) => RunnerError::InvalidUrlPrefix(url),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user