From 6f3150a4f7cd55e71229c1f7f2a2b8e6ef2c9bd2 Mon Sep 17 00:00:00 2001 From: Vei0vis Date: Sat, 7 Sep 2024 15:16:33 +0200 Subject: [PATCH] Add Username and Password for Selenium Grid Basic Auth Signed-off-by: Vei0vis --- pkg/scalers/selenium_grid_scaler.go | 7 ++++++ pkg/scalers/selenium_grid_scaler_test.go | 27 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/pkg/scalers/selenium_grid_scaler.go b/pkg/scalers/selenium_grid_scaler.go index 4e1f75667ad..09f0adfd319 100644 --- a/pkg/scalers/selenium_grid_scaler.go +++ b/pkg/scalers/selenium_grid_scaler.go @@ -37,6 +37,10 @@ type seleniumGridScalerMetadata struct { UnsafeSsl bool `keda:"name=unsafeSsl, order=triggerMetadata, optional, default=false"` PlatformName string `keda:"name=platformName, order=triggerMetadata, optional, default=linux"` + // auth + Username string `keda:"name=username, order=authParams;resolvedEnv;triggerMetadata, optional"` + Password string `keda:"name=password, order=authParams;resolvedEnv;triggerMetadata, optional"` + TargetValue int64 } @@ -164,6 +168,9 @@ func (s *seleniumGridScaler) getSessionsCount(ctx context.Context, logger logr.L return -1, err } + // Add HTTP Auth + req.SetBasicAuth(s.metadata.Username, s.metadata.Password) + res, err := s.httpClient.Do(req) if err != nil { return -1, err diff --git a/pkg/scalers/selenium_grid_scaler_test.go b/pkg/scalers/selenium_grid_scaler_test.go index 95e24743c1e..557861b357e 100644 --- a/pkg/scalers/selenium_grid_scaler_test.go +++ b/pkg/scalers/selenium_grid_scaler_test.go @@ -610,6 +610,33 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) { PlatformName: "linux", }, }, + { + name: "valid username and password in AuthParams, url, browsername, and sessionbrowsername should return metadata", + args: args{ + config: &scalersconfig.ScalerConfig{ + AuthParams: map[string]string{ + "username": "username", + "password": "password", + }, + TriggerMetadata: map[string]string{ + "url": "http://selenium-hub:4444/graphql", + "browserName": "MicrosoftEdge", + "sessionBrowserName": "msedge", + }, + }, + }, + wantErr: false, + want: &seleniumGridScalerMetadata{ + URL: "http://selenium-hub:4444/graphql", + BrowserName: "MicrosoftEdge", + SessionBrowserName: "msedge", + TargetValue: 1, + BrowserVersion: "latest", + PlatformName: "linux", + Username: "username", + Password: "password", + }, + }, { name: "valid url and browsername should return metadata", args: args{