Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to skip cert validation for internal test situations #565

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ pub struct GooseConfiguration {
/// Follows base_url redirect with subsequent requests
#[options(no_short)]
pub sticky_follow: bool,
/// Disables validation of https certificates
#[options(no_short)]
pub accept_invalid_certs: bool,
}

/// Optionally defines a subset of active Scenarios to run during a load test.
Expand Down Expand Up @@ -332,6 +335,8 @@ pub(crate) struct GooseDefaults {
pub websocket_host: Option<String>,
/// An optional default for port WebSocket Controller listens on.
pub websocket_port: Option<u16>,
/// An optional default for not validating https certificates.
pub accept_invalid_certs: Option<bool>,
}

/// Defines all [`GooseConfiguration`] options that can be programmatically configured with
Expand Down Expand Up @@ -432,6 +437,8 @@ pub enum GooseDefault {
WebSocketHost,
/// An optional default for port WebSocket Controller listens on.
WebSocketPort,
/// An optional default for not validating https certificates.
AcceptInvalidCerts,
jeremyandrews marked this conversation as resolved.
Show resolved Hide resolved
}

/// Most run-time options can be programmatically configured with custom defaults.
Expand Down Expand Up @@ -610,7 +617,8 @@ impl GooseDefaultType<&str> for GooseAttack {
| GooseDefault::NoGzip
| GooseDefault::NoStatusCodes
| GooseDefault::StickyFollow
| GooseDefault::NoGranularData => {
| GooseDefault::NoGranularData
| GooseDefault::AcceptInvalidCerts => {
return Err(GooseError::InvalidOption {
option: format!("GooseDefault::{:?}", key),
value: value.to_string(),
Expand Down Expand Up @@ -701,7 +709,8 @@ impl GooseDefaultType<usize> for GooseAttack {
| GooseDefault::NoGzip
| GooseDefault::NoStatusCodes
| GooseDefault::StickyFollow
| GooseDefault::NoGranularData => {
| GooseDefault::NoGranularData
| GooseDefault::AcceptInvalidCerts => {
return Err(GooseError::InvalidOption {
option: format!("GooseDefault::{:?}", key),
value: format!("{}", value),
Expand Down Expand Up @@ -757,6 +766,7 @@ impl GooseDefaultType<bool> for GooseAttack {
GooseDefault::NoWebSocket => self.defaults.no_websocket = Some(value),
GooseDefault::NoAutoStart => self.defaults.no_autostart = Some(value),
GooseDefault::NoGzip => self.defaults.no_gzip = Some(value),
GooseDefault::AcceptInvalidCerts => self.defaults.accept_invalid_certs = Some(value),
GooseDefault::NoStatusCodes => self.defaults.no_status_codes = Some(value),
GooseDefault::StickyFollow => self.defaults.sticky_follow = Some(value),
GooseDefault::NoGranularData => self.defaults.no_granular_report = Some(value),
Expand Down Expand Up @@ -856,7 +866,8 @@ impl GooseDefaultType<GooseCoordinatedOmissionMitigation> for GooseAttack {
| GooseDefault::NoGzip
| GooseDefault::NoStatusCodes
| GooseDefault::StickyFollow
| GooseDefault::NoGranularData => {
| GooseDefault::NoGranularData
| GooseDefault::AcceptInvalidCerts => {
return Err(GooseError::InvalidOption {
option: format!("GooseDefault::{:?}", key),
value: format!("{:?}", value),
Expand Down Expand Up @@ -956,7 +967,8 @@ impl GooseDefaultType<GooseLogFormat> for GooseAttack {
| GooseDefault::NoGzip
| GooseDefault::NoStatusCodes
| GooseDefault::StickyFollow
| GooseDefault::NoGranularData => {
| GooseDefault::NoGranularData
| GooseDefault::AcceptInvalidCerts => {
return Err(GooseError::InvalidOption {
option: format!("GooseDefault::{:?}", key),
value: format!("{:?}", value),
Expand Down Expand Up @@ -1731,6 +1743,24 @@ impl GooseConfiguration {
])
.unwrap_or(false);

// Configure `accept_invalid_certs`
self.accept_invalid_certs = self
.get_value(vec![
// Use --accept-invalid-certs if set.
GooseValue {
value: Some(self.accept_invalid_certs),
filter: !self.accept_invalid_certs,
message: "accept_invalid_certs",
},
// Use GooseDefault if not already set and not Worker.
GooseValue {
value: defaults.accept_invalid_certs,
filter: defaults.accept_invalid_certs.is_none(),
message: "accept_invalid_certs",
},
])
.unwrap_or(false);

self.co_mitigation = self.get_value(vec![
// Use --co-mitigation if set.
GooseValue {
Expand Down
2 changes: 2 additions & 0 deletions src/goose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2318,6 +2318,8 @@ pub(crate) fn create_reqwest_client(
.timeout(Duration::from_millis(timeout))
// Enable gzip unless `--no-gzip` flag is enabled.
.gzip(!configuration.no_gzip)
// Validate https certificates unless `--accept_invalid_certs` is enabled.
.danger_accept_invalid_certs(configuration.accept_invalid_certs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include a comment, for example:

// Validate https certificates unless --accept_invalid_certs is enabled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, sorry, I think that's actually --accept-invalid-certs -- can you test and confirm, and fix if necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

.build()
}

Expand Down