|
|
|
|
@ -6,6 +6,7 @@ import (
|
|
|
|
|
"fmt" |
|
|
|
|
"net/http" |
|
|
|
|
"net/http/httptest" |
|
|
|
|
"net/url" |
|
|
|
|
"os" |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
@ -13,6 +14,8 @@ import (
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
|
admin "google.golang.org/api/admin/directory/v1" |
|
|
|
|
"google.golang.org/api/option" |
|
|
|
|
|
|
|
|
|
"github.com/dexidp/dex/connector" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
@ -291,3 +294,60 @@ func TestDomainToAdminEmailConfig(t *testing.T) {
|
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestPromptTypeConfig(t *testing.T) { |
|
|
|
|
promptTypeLogin := "login" |
|
|
|
|
cases := []struct { |
|
|
|
|
name string |
|
|
|
|
promptType *string |
|
|
|
|
expectedPromptTypeValue string |
|
|
|
|
}{ |
|
|
|
|
{ |
|
|
|
|
name: "prompt type is nil", |
|
|
|
|
promptType: nil, |
|
|
|
|
expectedPromptTypeValue: "consent", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "prompt type is empty", |
|
|
|
|
promptType: new(string), |
|
|
|
|
expectedPromptTypeValue: "", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "prompt type is set", |
|
|
|
|
promptType: &promptTypeLogin, |
|
|
|
|
expectedPromptTypeValue: "login", |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ts := testSetup() |
|
|
|
|
defer ts.Close() |
|
|
|
|
|
|
|
|
|
serviceAccountFilePath, err := tempServiceAccountKey() |
|
|
|
|
assert.Nil(t, err) |
|
|
|
|
|
|
|
|
|
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", serviceAccountFilePath) |
|
|
|
|
|
|
|
|
|
for _, test := range cases { |
|
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
|
|
|
conn, err := newConnector(&Config{ |
|
|
|
|
ClientID: "testClient", |
|
|
|
|
ClientSecret: "testSecret", |
|
|
|
|
RedirectURI: ts.URL + "/callback", |
|
|
|
|
Scopes: []string{"openid", "groups", "offline_access"}, |
|
|
|
|
DomainToAdminEmail: map[string]string{"dexidp.com": "admin@dexidp.com"}, |
|
|
|
|
PromptType: test.promptType, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
assert.Nil(t, err) |
|
|
|
|
assert.Equal(t, test.expectedPromptTypeValue, conn.promptType) |
|
|
|
|
|
|
|
|
|
loginURL, err := conn.LoginURL(connector.Scopes{OfflineAccess: true}, ts.URL+"/callback", "state") |
|
|
|
|
assert.Nil(t, err) |
|
|
|
|
|
|
|
|
|
urlp, err := url.Parse(loginURL) |
|
|
|
|
assert.Nil(t, err) |
|
|
|
|
|
|
|
|
|
assert.Equal(t, test.expectedPromptTypeValue, urlp.Query().Get("prompt")) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|