Skip to content

Commit

Permalink
allow to skip cert validation for internal test situations
Browse files Browse the repository at this point in the history
  • Loading branch information
raffaeleragni-virtualminds committed Sep 28, 2023
1 parent 58e9da3 commit d5d9959
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
37 changes: 33 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,
/// Allows to test internally when https validation is not required
#[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>,
/// Allow for internal testing when no certificates are available but still using https
pub accept_invalid_certs: Option<bool>,
}

/// Defines all [`GooseConfiguration`] options that can be programmatically configured with
Expand Down Expand Up @@ -432,6 +437,7 @@ pub enum GooseDefault {
WebSocketHost,
/// An optional default for port WebSocket Controller listens on.
WebSocketPort,
AcceptInvalidCerts,
}

/// Most run-time options can be programmatically configured with custom defaults.
Expand Down Expand Up @@ -610,7 +616,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 +708,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 +765,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 +865,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 +966,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 +1742,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
1 change: 1 addition & 0 deletions src/goose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2318,6 +2318,7 @@ pub(crate) fn create_reqwest_client(
.timeout(Duration::from_millis(timeout))
// Enable gzip unless `--no-gzip` flag is enabled.
.gzip(!configuration.no_gzip)
.danger_accept_invalid_certs(configuration.accept_invalid_certs)
.build()
}

Expand Down

0 comments on commit d5d9959

Please sign in to comment.