@@ -6,9 +6,11 @@ import (
6
6
"fmt"
7
7
"net/http"
8
8
"net/http/httptest"
9
+ "net/url"
9
10
"os"
10
11
"testing"
11
12
13
+ "github.com/dexidp/dex/connector"
12
14
"github.com/sirupsen/logrus"
13
15
"github.com/stretchr/testify/assert"
14
16
admin "google.golang.org/api/admin/directory/v1"
@@ -291,3 +293,60 @@ func TestDomainToAdminEmailConfig(t *testing.T) {
291
293
})
292
294
}
293
295
}
296
+
297
+ func TestPromptTypeConfig (t * testing.T ) {
298
+ promptTypeLogin := "login"
299
+ cases := []struct {
300
+ name string
301
+ promptType * string
302
+ expectedPromptTypeValue string
303
+ }{
304
+ {
305
+ name : "prompt type is nil" ,
306
+ promptType : nil ,
307
+ expectedPromptTypeValue : "consent" ,
308
+ },
309
+ {
310
+ name : "prompt type is empty" ,
311
+ promptType : new (string ),
312
+ expectedPromptTypeValue : "" ,
313
+ },
314
+ {
315
+ name : "prompt type is set" ,
316
+ promptType : & promptTypeLogin ,
317
+ expectedPromptTypeValue : "login" ,
318
+ },
319
+ }
320
+
321
+ ts := testSetup ()
322
+ defer ts .Close ()
323
+
324
+ serviceAccountFilePath , err := tempServiceAccountKey ()
325
+ assert .Nil (t , err )
326
+
327
+ os .Setenv ("GOOGLE_APPLICATION_CREDENTIALS" , serviceAccountFilePath )
328
+
329
+ for _ , test := range cases {
330
+ t .Run (test .name , func (t * testing.T ) {
331
+ conn , err := newConnector (& Config {
332
+ ClientID : "testClient" ,
333
+ ClientSecret : "testSecret" ,
334
+ RedirectURI : ts .URL + "/callback" ,
335
+ Scopes : []string {"openid" , "groups" , "offline_access" },
336
+ DomainToAdminEmail : map [string ]string {"dexidp.com" : "admin@dexidp.com" },
337
+ PromptType : test .promptType ,
338
+ })
339
+
340
+ assert .Nil (t , err )
341
+ assert .Equal (t , test .expectedPromptTypeValue , conn .promptType )
342
+
343
+ loginURL , err := conn .LoginURL (connector.Scopes {OfflineAccess : true }, ts .URL + "/callback" , "state" )
344
+ assert .Nil (t , err )
345
+
346
+ urlp , err := url .Parse (loginURL )
347
+ assert .Nil (t , err )
348
+
349
+ assert .Equal (t , test .expectedPromptTypeValue , urlp .Query ().Get ("prompt" ))
350
+ })
351
+ }
352
+ }
0 commit comments