@@ -21,6 +21,7 @@ import (
2121 "github.com/stretchr/testify/assert"
2222 "github.com/stretchr/testify/require"
2323 "golang.org/x/oauth2"
24+ "sigs.k8s.io/yaml"
2425
2526 "github.com/argoproj/argo-cd/v3/common"
2627 "github.com/argoproj/argo-cd/v3/server/settings/oidc"
@@ -204,6 +205,108 @@ requestedScopes: ["oidc"]`, oidcTestServer.URL),
204205 assert .NotContains (t , w .Body .String (), "certificate signed by unknown authority" )
205206 })
206207
208+ t .Run ("OIDC auth" , func (t * testing.T ) {
209+ cdSettings := & settings.ArgoCDSettings {
210+ URL : "https://argocd.example.com" ,
211+ OIDCTLSInsecureSkipVerify : true ,
212+ }
213+ oidcConfig := settings.OIDCConfig {
214+ Name : "Test" ,
215+ Issuer : oidcTestServer .URL ,
216+ ClientID : "xxx" ,
217+ ClientSecret : "yyy" ,
218+ }
219+ oidcConfigRaw , err := yaml .Marshal (oidcConfig )
220+ require .NoError (t , err )
221+ cdSettings .OIDCConfigRAW = string (oidcConfigRaw )
222+
223+ app , err := NewClientApp (cdSettings , dexTestServer .URL , & dex.DexTLSConfig {StrictValidation : false }, "https://argocd.example.com" , cache .NewInMemoryCache (24 * time .Hour ))
224+ require .NoError (t , err )
225+
226+ req := httptest .NewRequest (http .MethodGet , "https://argocd.example.com/auth/login" , nil )
227+ w := httptest .NewRecorder ()
228+ app .HandleLogin (w , req )
229+
230+ assert .Equal (t , http .StatusSeeOther , w .Code )
231+ location , err := url .Parse (w .Header ().Get ("Location" ))
232+ require .NoError (t , err )
233+ values , err := url .ParseQuery (location .RawQuery )
234+ require .NoError (t , err )
235+ assert .Equal (t , []string {"openid" , "profile" , "email" , "groups" }, strings .Split (values .Get ("scope" ), " " ))
236+ assert .Equal (t , "xxx" , values .Get ("client_id" ))
237+ assert .Equal (t , "code" , values .Get ("response_type" ))
238+ })
239+
240+ t .Run ("OIDC auth with custom scopes" , func (t * testing.T ) {
241+ cdSettings := & settings.ArgoCDSettings {
242+ URL : "https://argocd.example.com" ,
243+ OIDCTLSInsecureSkipVerify : true ,
244+ }
245+ oidcConfig := settings.OIDCConfig {
246+ Name : "Test" ,
247+ Issuer : oidcTestServer .URL ,
248+ ClientID : "xxx" ,
249+ ClientSecret : "yyy" ,
250+ RequestedScopes : []string {"oidc" },
251+ }
252+ oidcConfigRaw , err := yaml .Marshal (oidcConfig )
253+ require .NoError (t , err )
254+ cdSettings .OIDCConfigRAW = string (oidcConfigRaw )
255+
256+ app , err := NewClientApp (cdSettings , dexTestServer .URL , & dex.DexTLSConfig {StrictValidation : false }, "https://argocd.example.com" , cache .NewInMemoryCache (24 * time .Hour ))
257+ require .NoError (t , err )
258+
259+ req := httptest .NewRequest (http .MethodGet , "https://argocd.example.com/auth/login" , nil )
260+ w := httptest .NewRecorder ()
261+ app .HandleLogin (w , req )
262+
263+ assert .Equal (t , http .StatusSeeOther , w .Code )
264+ location , err := url .Parse (w .Header ().Get ("Location" ))
265+ require .NoError (t , err )
266+ values , err := url .ParseQuery (location .RawQuery )
267+ require .NoError (t , err )
268+ assert .Equal (t , []string {"oidc" }, strings .Split (values .Get ("scope" ), " " ))
269+ assert .Equal (t , "xxx" , values .Get ("client_id" ))
270+ assert .Equal (t , "code" , values .Get ("response_type" ))
271+ })
272+
273+ t .Run ("Dex auth" , func (t * testing.T ) {
274+ cdSettings := & settings.ArgoCDSettings {
275+ URL : dexTestServer .URL ,
276+ }
277+ dexConfig := map [string ]any {
278+ "connectors" : []map [string ]any {
279+ {
280+ "type" : "github" ,
281+ "name" : "GitHub" ,
282+ "config" : map [string ]any {
283+ "clientId" : "aabbccddeeff00112233" ,
284+ "clientSecret" : "aabbccddeeff00112233" ,
285+ },
286+ },
287+ },
288+ }
289+ dexConfigRaw , err := yaml .Marshal (dexConfig )
290+ require .NoError (t , err )
291+ cdSettings .DexConfig = string (dexConfigRaw )
292+
293+ app , err := NewClientApp (cdSettings , dexTestServer .URL , & dex.DexTLSConfig {StrictValidation : false }, "https://argocd.example.com" , cache .NewInMemoryCache (24 * time .Hour ))
294+ require .NoError (t , err )
295+
296+ req := httptest .NewRequest (http .MethodGet , "https://argocd.example.com/auth/login" , nil )
297+ w := httptest .NewRecorder ()
298+ app .HandleLogin (w , req )
299+
300+ assert .Equal (t , http .StatusSeeOther , w .Code )
301+ location , err := url .Parse (w .Header ().Get ("Location" ))
302+ require .NoError (t , err )
303+ values , err := url .ParseQuery (location .RawQuery )
304+ require .NoError (t , err )
305+ assert .Equal (t , []string {"openid" , "profile" , "email" , "groups" , common .DexFederatedScope }, strings .Split (values .Get ("scope" ), " " ))
306+ assert .Equal (t , common .ArgoCDClientAppID , values .Get ("client_id" ))
307+ assert .Equal (t , "code" , values .Get ("response_type" ))
308+ })
309+
207310 t .Run ("with additional base URL" , func (t * testing.T ) {
208311 cdSettings := & settings.ArgoCDSettings {
209312 URL : "https://argocd.example.com" ,
0 commit comments