@@ -65,11 +65,18 @@ async fn main() -> Result<(), anyhow::Error> {
6565
6666 let scenario = Arc :: new ( scenario:: Scenario :: load ( scenario_file. as_deref ( ) ) . await ?) ;
6767
68- let provider = create_oidc_provider ( ) . await ?;
69- let custom_client = Transaction :: new ( Arc :: new ( move |user| {
70- let provider = provider. clone ( ) ;
71- Box :: pin ( async move { setup_custom_client ( & provider, user) . await } )
72- } ) ) ;
68+ let custom_client = if !matches ! (
69+ std:: env:: var( "AUTH_DISABLED" ) . ok( ) . as_deref( ) ,
70+ None | Some ( "true" | "1" )
71+ ) {
72+ let provider = create_oidc_provider ( ) . await ?;
73+ Some ( Transaction :: new ( Arc :: new ( move |user| {
74+ let provider = provider. clone ( ) ;
75+ Box :: pin ( async move { setup_custom_client ( & provider, user) . await } )
76+ } ) ) )
77+ } else {
78+ None
79+ } ;
7380
7481 GooseAttack :: initialize ( ) ?
7582 . test_start (
@@ -85,45 +92,37 @@ async fn main() -> Result<(), anyhow::Error> {
8592 } ) )
8693 . set_name ( "log scenario" ) ,
8794 )
88- . register_scenario (
89- scenario ! ( "WebsiteUser" )
90- // .set_weight(1)?
91- . register_transaction ( custom_client. clone ( ) . set_name ( "logon" ) )
92- // After each transactions runs, sleep randomly from 5 to 15 seconds.
93- . set_wait_time (
94- Duration :: from_secs ( wait_time_from) ,
95- Duration :: from_secs ( wait_time_to) ,
96- ) ?
97- . register_transaction ( tx ! ( website_index) )
98- . register_transaction ( tx ! ( website_openapi) )
99- . register_transaction ( tx ! ( website_sboms) )
100- . register_transaction ( tx ! ( website_packages) )
101- . register_transaction ( tx ! ( website_advisories) )
102- . register_transaction ( tx ! ( website_importers) ) ,
103- )
10495 . register_scenario ( {
105- let mut s = scenario ! ( "RestAPIUser" )
106- // .set_weight(1)?
107- . register_transaction ( custom_client. clone ( ) . set_name ( "logon" ) )
108- // After each transactions runs, sleep randomly from 5 to 15 seconds.
109- . set_wait_time (
110- Duration :: from_secs ( wait_time_from) ,
111- Duration :: from_secs ( wait_time_to) ,
112- ) ?
113- . register_transaction ( tx ! ( list_organizations) )
114- . register_transaction ( tx ! ( list_advisory) )
115- . register_transaction ( tx ! ( list_advisory_paginated) )
116- . register_transaction ( tx ! ( get_advisory_by_doc_id) )
117- . register_transaction ( tx ! ( list_vulnerabilities) )
118- . register_transaction ( tx ! ( list_vulnerabilities_paginated) )
119- . register_transaction ( tx ! ( list_importer) )
120- . register_transaction ( tx ! ( list_packages) )
121- . register_transaction ( tx ! ( list_packages_paginated) )
122- . register_transaction ( tx ! ( search_purls) )
123- . register_transaction ( tx ! ( search_exact_purl) )
124- . register_transaction ( tx ! ( list_products) )
125- . register_transaction ( tx ! ( list_sboms) )
126- . register_transaction ( tx ! ( list_sboms_paginated) ) ;
96+ create_scenario (
97+ "WebsiteUser" ,
98+ wait_time_from,
99+ wait_time_to,
100+ custom_client. clone ( ) ,
101+ ) ?
102+ . register_transaction ( tx ! ( website_index) )
103+ . register_transaction ( tx ! ( website_openapi) )
104+ . register_transaction ( tx ! ( website_sboms) )
105+ . register_transaction ( tx ! ( website_packages) )
106+ . register_transaction ( tx ! ( website_advisories) )
107+ . register_transaction ( tx ! ( website_importers) )
108+ } )
109+ . register_scenario ( {
110+ let mut s =
111+ create_scenario ( "RestAPIUser" , wait_time_from, wait_time_to, custom_client) ?
112+ . register_transaction ( tx ! ( list_organizations) )
113+ . register_transaction ( tx ! ( list_advisory) )
114+ . register_transaction ( tx ! ( list_advisory_paginated) )
115+ . register_transaction ( tx ! ( get_advisory_by_doc_id) )
116+ . register_transaction ( tx ! ( list_vulnerabilities) )
117+ . register_transaction ( tx ! ( list_vulnerabilities_paginated) )
118+ . register_transaction ( tx ! ( list_importer) )
119+ . register_transaction ( tx ! ( list_packages) )
120+ . register_transaction ( tx ! ( list_packages_paginated) )
121+ . register_transaction ( tx ! ( search_purls) )
122+ . register_transaction ( tx ! ( search_exact_purl) )
123+ . register_transaction ( tx ! ( list_products) )
124+ . register_transaction ( tx ! ( list_sboms) )
125+ . register_transaction ( tx ! ( list_sboms_paginated) ) ;
127126
128127 tx ! ( s. get_sbom?( scenario. get_sbom. clone( ) ) ) ;
129128 tx ! ( s. get_sbom_advisories?( scenario. get_sbom_advisories. clone( ) ) ) ;
@@ -158,6 +157,22 @@ async fn main() -> Result<(), anyhow::Error> {
158157 Ok ( ( ) )
159158}
160159
160+ fn create_scenario (
161+ name : & str ,
162+ wait_time_from : u64 ,
163+ wait_time_to : u64 ,
164+ custom_client : Option < Transaction > ,
165+ ) -> Result < Scenario , GooseError > {
166+ let mut s = scenario ! ( name) ;
167+ if let Some ( client) = custom_client {
168+ s = s. register_transaction ( client. set_name ( "logon" ) ) ;
169+ }
170+ s. set_wait_time (
171+ Duration :: from_secs ( wait_time_from) ,
172+ Duration :: from_secs ( wait_time_to) ,
173+ )
174+ }
175+
161176async fn create_oidc_provider ( ) -> anyhow:: Result < OpenIdTokenProvider > {
162177 let issuer_url = std:: env:: var ( "ISSUER_URL" ) . context ( "Missing env-var 'ISSUER_URL'" ) ?;
163178 let client_id = std:: env:: var ( "CLIENT_ID" ) . context ( "Missing env-var 'CLIENT_ID'" ) ?;
0 commit comments