@@ -1642,6 +1642,34 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) {
16421642 NodeMaxSessions : 1 ,
16431643 },
16441644 },
1645+ {
1646+ name : "valid username and password in AuthParams, url, browsername, and sessionbrowsername should return metadata" ,
1647+ args : args {
1648+ config : & scalersconfig.ScalerConfig {
1649+ AuthParams : map [string ]string {
1650+ "username" : "username" ,
1651+ "password" : "password" ,
1652+ },
1653+ TriggerMetadata : map [string ]string {
1654+ "url" : "http://selenium-hub:4444/graphql" ,
1655+ "browserName" : "MicrosoftEdge" ,
1656+ "sessionBrowserName" : "msedge" ,
1657+ },
1658+ },
1659+ },
1660+ wantErr : false ,
1661+ want : & seleniumGridScalerMetadata {
1662+ URL : "http://selenium-hub:4444/graphql" ,
1663+ BrowserName : "MicrosoftEdge" ,
1664+ SessionBrowserName : "msedge" ,
1665+ TargetValue : 1 ,
1666+ BrowserVersion : "latest" ,
1667+ PlatformName : "linux" ,
1668+ Username : "username" ,
1669+ Password : "password" ,
1670+ NodeMaxSessions : 1 ,
1671+ },
1672+ },
16451673 {
16461674 name : "valid url and browsername should return metadata" ,
16471675 args : args {
@@ -1761,20 +1789,22 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) {
17611789 },
17621790 },
17631791 {
1764- name : "valid url, browsername, unsafeSsl, activationThreshold, nodeMaxSessions and platformName should return metadata" ,
1792+ name : "valid url, browsername, unsafeSsl, activationThreshold, nodeMaxSessions and platformName with trigger auth params should return metadata" ,
17651793 args : args {
17661794 config : & scalersconfig.ScalerConfig {
17671795 TriggerMetadata : map [string ]string {
17681796 "url" : "http://selenium-hub:4444/graphql" ,
1769- "username" : "user" ,
1770- "password" : "password" ,
17711797 "browserName" : "chrome" ,
17721798 "browserVersion" : "91.0" ,
17731799 "unsafeSsl" : "true" ,
17741800 "activationThreshold" : "10" ,
17751801 "platformName" : "Windows 11" ,
17761802 "nodeMaxSessions" : "3" ,
17771803 },
1804+ AuthParams : map [string ]string {
1805+ "username" : "user" ,
1806+ "password" : "password" ,
1807+ },
17781808 },
17791809 },
17801810 wantErr : false ,
@@ -1792,6 +1822,110 @@ func Test_parseSeleniumGridScalerMetadata(t *testing.T) {
17921822 NodeMaxSessions : 3 ,
17931823 },
17941824 },
1825+ {
1826+ name : "url in trigger auth param takes precedence over url in trigger metadata" ,
1827+ args : args {
1828+ config : & scalersconfig.ScalerConfig {
1829+ TriggerMetadata : map [string ]string {
1830+ "url" : "http://invalid.dns:4444/graphql" ,
1831+ "browserName" : "chrome" ,
1832+ "browserVersion" : "91.0" ,
1833+ "unsafeSsl" : "true" ,
1834+ "activationThreshold" : "10" ,
1835+ "platformName" : "Windows 11" ,
1836+ "nodeMaxSessions" : "3" ,
1837+ },
1838+ AuthParams : map [string ]string {
1839+ "url" : "http://selenium-hub:4444/graphql" ,
1840+ "username" : "user" ,
1841+ "password" : "password" ,
1842+ },
1843+ },
1844+ },
1845+ wantErr : false ,
1846+ want : & seleniumGridScalerMetadata {
1847+ URL : "http://selenium-hub:4444/graphql" ,
1848+ Username : "user" ,
1849+ Password : "password" ,
1850+ BrowserName : "chrome" ,
1851+ SessionBrowserName : "chrome" ,
1852+ TargetValue : 1 ,
1853+ ActivationThreshold : 10 ,
1854+ BrowserVersion : "91.0" ,
1855+ UnsafeSsl : true ,
1856+ PlatformName : "Windows 11" ,
1857+ NodeMaxSessions : 3 ,
1858+ },
1859+ },
1860+ {
1861+ name : "auth type is not Basic and access token is provided" ,
1862+ args : args {
1863+ config : & scalersconfig.ScalerConfig {
1864+ TriggerMetadata : map [string ]string {
1865+ "url" : "http://selenium-hub:4444/graphql" ,
1866+ "browserName" : "chrome" ,
1867+ "browserVersion" : "91.0" ,
1868+ "unsafeSsl" : "true" ,
1869+ "activationThreshold" : "10" ,
1870+ "platformName" : "Windows 11" ,
1871+ "nodeMaxSessions" : "3" ,
1872+ },
1873+ AuthParams : map [string ]string {
1874+ "url" : "http://selenium-hub:4444/graphql" ,
1875+ "authType" : "OAuth2" ,
1876+ "accessToken" : "my-access-token" ,
1877+ },
1878+ },
1879+ },
1880+ wantErr : false ,
1881+ want : & seleniumGridScalerMetadata {
1882+ URL : "http://selenium-hub:4444/graphql" ,
1883+ AuthType : "OAuth2" ,
1884+ AccessToken : "my-access-token" ,
1885+ BrowserName : "chrome" ,
1886+ SessionBrowserName : "chrome" ,
1887+ TargetValue : 1 ,
1888+ ActivationThreshold : 10 ,
1889+ BrowserVersion : "91.0" ,
1890+ UnsafeSsl : true ,
1891+ PlatformName : "Windows 11" ,
1892+ NodeMaxSessions : 3 ,
1893+ },
1894+ },
1895+ {
1896+ name : "authenticating with bearer access token" ,
1897+ args : args {
1898+ config : & scalersconfig.ScalerConfig {
1899+ TriggerMetadata : map [string ]string {
1900+ "browserName" : "chrome" ,
1901+ "browserVersion" : "91.0" ,
1902+ "unsafeSsl" : "true" ,
1903+ "activationThreshold" : "10" ,
1904+ "platformName" : "Windows 11" ,
1905+ "nodeMaxSessions" : "3" ,
1906+ },
1907+ AuthParams : map [string ]string {
1908+ "url" : "http://selenium-hub:4444/graphql" ,
1909+ "authType" : "Bearer" ,
1910+ "accessToken" : "my-access-token" ,
1911+ },
1912+ },
1913+ },
1914+ wantErr : false ,
1915+ want : & seleniumGridScalerMetadata {
1916+ URL : "http://selenium-hub:4444/graphql" ,
1917+ AuthType : "Bearer" ,
1918+ AccessToken : "my-access-token" ,
1919+ BrowserName : "chrome" ,
1920+ SessionBrowserName : "chrome" ,
1921+ TargetValue : 1 ,
1922+ ActivationThreshold : 10 ,
1923+ BrowserVersion : "91.0" ,
1924+ UnsafeSsl : true ,
1925+ PlatformName : "Windows 11" ,
1926+ NodeMaxSessions : 3 ,
1927+ },
1928+ },
17951929 }
17961930 for _ , tt := range tests {
17971931 t .Run (tt .name , func (t * testing.T ) {
0 commit comments