Skip to content

Commit

Permalink
Add Username and Password for Selenium Grid Basic Auth
Browse files Browse the repository at this point in the history
Signed-off-by: Vei0vis <[email protected]>
  • Loading branch information
Vei0vis authored and Vei0vis committed Sep 7, 2024
1 parent f6358d5 commit 6f3150a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/scalers/selenium_grid_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions pkg/scalers/selenium_grid_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 6f3150a

Please sign in to comment.