mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-12-23 19:12:06 +03:00
Add support for cacert entry option.
This commit is contained in:
parent
81c1233623
commit
aae808b0b0
@ -1,3 +1,4 @@
|
||||
curl 'https://localhost:8001/hello' --insecure
|
||||
curl 'https://localhost:8001/hello' --insecure
|
||||
curl 'https://localhost:8001/hello' --cacert ssl/cert.pem
|
||||
|
||||
|
@ -14,3 +14,11 @@ insecure: true
|
||||
|
||||
HTTP/* 200
|
||||
```Hello World!```
|
||||
|
||||
|
||||
GET https://localhost:8001/hello
|
||||
[Options]
|
||||
cacert: ssl/cert.pem # with a custom certificate
|
||||
|
||||
HTTP/* 200
|
||||
```Hello World!```
|
||||
|
7
integration/tests_error_parser/options_cacert.err
Normal file
7
integration/tests_error_parser/options_cacert.err
Normal file
@ -0,0 +1,7 @@
|
||||
error: Parsing filename
|
||||
--> tests_error_parser/options_cacert.hurl:3:9
|
||||
|
|
||||
3 | cacert: # missing filename !
|
||||
| ^ expecting a filename
|
||||
|
|
||||
|
1
integration/tests_error_parser/options_cacert.exit
Normal file
1
integration/tests_error_parser/options_cacert.exit
Normal file
@ -0,0 +1 @@
|
||||
2
|
5
integration/tests_error_parser/options_cacert.hurl
Normal file
5
integration/tests_error_parser/options_cacert.hurl
Normal file
@ -0,0 +1,5 @@
|
||||
GET http://localhost:8000
|
||||
[Options]
|
||||
cacert: # missing filename !
|
||||
|
||||
HTTP/* *
|
@ -249,10 +249,17 @@ fn get_entry_options(
|
||||
for section in &entry.request.sections {
|
||||
if let SectionValue::Options(options) = §ion.value {
|
||||
for option in options {
|
||||
let EntryOption::Insecure(insecure_option) = option;
|
||||
client_options.insecure = insecure_option.value;
|
||||
match option {
|
||||
EntryOption::Insecure(option) => {
|
||||
client_options.insecure = option.value;
|
||||
logger.debug(format!("insecure: {}", client_options.insecure).as_str());
|
||||
}
|
||||
EntryOption::CaCertificate(option) => {
|
||||
client_options.cacert_file = Some(option.filename.value.clone());
|
||||
logger.debug(format!("cacert: {}", option.filename.value).as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
client_options
|
||||
|
@ -668,6 +668,7 @@ pub struct Variable {
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum EntryOption {
|
||||
Insecure(InsecureOption),
|
||||
CaCertificate(CaCertificateOption),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
@ -679,3 +680,13 @@ pub struct InsecureOption {
|
||||
pub value: bool,
|
||||
pub line_terminator0: LineTerminator,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CaCertificateOption {
|
||||
pub line_terminators: Vec<LineTerminator>,
|
||||
pub space0: Whitespace,
|
||||
pub space1: Whitespace,
|
||||
pub space2: Whitespace,
|
||||
pub filename: Filename,
|
||||
pub line_terminator0: LineTerminator,
|
||||
}
|
||||
|
@ -233,6 +233,7 @@ impl Htmlable for EntryOption {
|
||||
fn to_html(&self) -> String {
|
||||
match self {
|
||||
EntryOption::Insecure(option) => option.to_html(),
|
||||
EntryOption::CaCertificate(option) => option.to_html(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -254,6 +255,23 @@ impl Htmlable for InsecureOption {
|
||||
}
|
||||
}
|
||||
|
||||
impl Htmlable for CaCertificateOption {
|
||||
fn to_html(&self) -> String {
|
||||
let mut buffer = String::from("");
|
||||
add_line_terminators(&mut buffer, self.line_terminators.clone());
|
||||
buffer.push_str("<span class=\"line\">");
|
||||
buffer.push_str(self.space0.to_html().as_str());
|
||||
buffer.push_str("<span class=\"string\">cacert</span>");
|
||||
buffer.push_str(self.space1.to_html().as_str());
|
||||
buffer.push_str("<span>:</span>");
|
||||
buffer.push_str(self.space2.to_html().as_str());
|
||||
buffer.push_str(self.filename.to_html().as_str());
|
||||
buffer.push_str("</span>");
|
||||
buffer.push_str(self.line_terminator0.to_html().as_str());
|
||||
buffer
|
||||
}
|
||||
}
|
||||
|
||||
impl Htmlable for MultipartParam {
|
||||
fn to_html(&self) -> String {
|
||||
match self {
|
||||
|
@ -368,8 +368,25 @@ fn option_insecure(reader: &mut Reader) -> ParseResult<'static, EntryOption> {
|
||||
}
|
||||
|
||||
fn option_cacert(reader: &mut Reader) -> ParseResult<'static, EntryOption> {
|
||||
let line_terminators = optional_line_terminators(reader)?;
|
||||
let space0 = zero_or_more_spaces(reader)?;
|
||||
try_literal("cacert", reader)?;
|
||||
unimplemented!()
|
||||
let space1 = zero_or_more_spaces(reader)?;
|
||||
try_literal(":", reader)?;
|
||||
let space2 = zero_or_more_spaces(reader)?;
|
||||
let f = filename::parse(reader)?;
|
||||
let line_terminator0 = line_terminator(reader)?;
|
||||
|
||||
let option = CaCertificateOption {
|
||||
line_terminators,
|
||||
space0,
|
||||
space1,
|
||||
space2,
|
||||
filename: f,
|
||||
line_terminator0,
|
||||
};
|
||||
|
||||
Ok(EntryOption::CaCertificate(option))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -533,28 +550,28 @@ mod tests {
|
||||
value: "".to_string(),
|
||||
source_info: SourceInfo {
|
||||
start: Pos { line: 1, column: 1 },
|
||||
end: Pos { line: 1, column: 1 }
|
||||
}
|
||||
end: Pos { line: 1, column: 1 },
|
||||
},
|
||||
},
|
||||
space1: Whitespace {
|
||||
value: "".to_string(),
|
||||
source_info: SourceInfo {
|
||||
start: Pos { line: 1, column: 9 },
|
||||
end: Pos { line: 1, column: 9 }
|
||||
}
|
||||
end: Pos { line: 1, column: 9 },
|
||||
},
|
||||
},
|
||||
space2: Whitespace {
|
||||
value: " ".to_string(),
|
||||
source_info: SourceInfo {
|
||||
start: Pos {
|
||||
line: 1,
|
||||
column: 10
|
||||
column: 10,
|
||||
},
|
||||
end: Pos {
|
||||
line: 1,
|
||||
column: 11
|
||||
}
|
||||
}
|
||||
column: 11,
|
||||
},
|
||||
},
|
||||
},
|
||||
value: true,
|
||||
line_terminator0: LineTerminator {
|
||||
@ -563,13 +580,13 @@ mod tests {
|
||||
source_info: SourceInfo {
|
||||
start: Pos {
|
||||
line: 1,
|
||||
column: 15
|
||||
column: 15,
|
||||
},
|
||||
end: Pos {
|
||||
line: 1,
|
||||
column: 15
|
||||
}
|
||||
}
|
||||
column: 15,
|
||||
},
|
||||
},
|
||||
},
|
||||
comment: None,
|
||||
newline: Whitespace {
|
||||
@ -577,15 +594,15 @@ mod tests {
|
||||
source_info: SourceInfo {
|
||||
start: Pos {
|
||||
line: 1,
|
||||
column: 15
|
||||
column: 15,
|
||||
},
|
||||
end: Pos {
|
||||
line: 1,
|
||||
column: 15
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
column: 15,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -597,6 +614,85 @@ mod tests {
|
||||
assert_eq!(error.recoverable, false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_option_cacert() {
|
||||
let mut reader = Reader::init("cacert: /home/foo/cert.pem");
|
||||
let option = option_cacert(&mut reader).unwrap();
|
||||
assert_eq!(
|
||||
option,
|
||||
EntryOption::CaCertificate(CaCertificateOption {
|
||||
line_terminators: vec![],
|
||||
space0: Whitespace {
|
||||
value: "".to_string(),
|
||||
source_info: SourceInfo {
|
||||
start: Pos { line: 1, column: 1 },
|
||||
end: Pos { line: 1, column: 1 },
|
||||
},
|
||||
},
|
||||
space1: Whitespace {
|
||||
value: "".to_string(),
|
||||
source_info: SourceInfo {
|
||||
start: Pos { line: 1, column: 7 },
|
||||
end: Pos { line: 1, column: 7 },
|
||||
},
|
||||
},
|
||||
space2: Whitespace {
|
||||
value: " ".to_string(),
|
||||
source_info: SourceInfo {
|
||||
start: Pos { line: 1, column: 8 },
|
||||
end: Pos { line: 1, column: 9 },
|
||||
},
|
||||
},
|
||||
filename: Filename {
|
||||
value: "/home/foo/cert.pem".to_string(),
|
||||
source_info: SourceInfo {
|
||||
start: Pos { line: 1, column: 9 },
|
||||
end: Pos {
|
||||
line: 1,
|
||||
column: 27
|
||||
}
|
||||
}
|
||||
},
|
||||
line_terminator0: LineTerminator {
|
||||
space0: Whitespace {
|
||||
value: "".to_string(),
|
||||
source_info: SourceInfo {
|
||||
start: Pos {
|
||||
line: 1,
|
||||
column: 27,
|
||||
},
|
||||
end: Pos {
|
||||
line: 1,
|
||||
column: 27,
|
||||
},
|
||||
},
|
||||
},
|
||||
comment: None,
|
||||
newline: Whitespace {
|
||||
value: "".to_string(),
|
||||
source_info: SourceInfo {
|
||||
start: Pos {
|
||||
line: 1,
|
||||
column: 27,
|
||||
},
|
||||
end: Pos {
|
||||
line: 1,
|
||||
column: 27,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_option_cacert_error() {
|
||||
let mut reader = Reader::init("cacert: ###");
|
||||
let error = option_cacert(&mut reader).err().unwrap();
|
||||
assert_eq!(error.recoverable, false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cookie_error() {
|
||||
let mut reader = Reader::init("Foo: {{Bar");
|
||||
|
@ -819,6 +819,7 @@ impl Tokenizable for EntryOption {
|
||||
fn tokenize(&self) -> Vec<Token> {
|
||||
match self {
|
||||
EntryOption::Insecure(option) => option.tokenize(),
|
||||
EntryOption::CaCertificate(option) => option.tokenize(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -843,3 +844,24 @@ impl Tokenizable for InsecureOption {
|
||||
tokens
|
||||
}
|
||||
}
|
||||
|
||||
impl Tokenizable for CaCertificateOption {
|
||||
fn tokenize(&self) -> Vec<Token> {
|
||||
let mut tokens: Vec<Token> = vec![];
|
||||
tokens.append(
|
||||
&mut self
|
||||
.line_terminators
|
||||
.iter()
|
||||
.flat_map(|e| e.tokenize())
|
||||
.collect(),
|
||||
);
|
||||
tokens.append(&mut self.space0.tokenize());
|
||||
tokens.push(Token::String("cacert".to_string()));
|
||||
tokens.append(&mut self.space1.tokenize());
|
||||
tokens.push(Token::Colon(String::from(":")));
|
||||
tokens.append(&mut self.space2.tokenize());
|
||||
tokens.append(&mut self.filename.tokenize());
|
||||
tokens.append(&mut self.line_terminator0.tokenize());
|
||||
tokens
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user