mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
* [experiment] Add "Sign in with SSO" to Login Reusing existing parts: * `/complete-auth` page of Dashbaord to forward results of authN flows running in a modal * Adding preliminary UI to the Login view: Org-slug and simple button. * [gitpod-db] get team/org by slug * [gitpod-db] fix OIDCClientConfig.OrganizationID field's type * [oidc] consider returnTo URL * [oidc] consider orgSlug param from start request * [oidc] fix oauth2 clientId propagation * [oidc] fix a flaky test * [onboarding] skip for organizational accounts * Move SSO Login UI into it's own component * adjust validation a bit, add useCallbacks * adding GetOIDCClientConfigByOrgSlug * add table name * removing commented out code --------- Co-authored-by: Brad Harris <bmharris@gmail.com>
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License.AGPL.txt in the project root for license information.
|
|
|
|
package dbtest
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
db "github.com/gitpod-io/gitpod/components/gitpod-db/go"
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func NewOIDCClientConfig(t *testing.T, record db.OIDCClientConfig) db.OIDCClientConfig {
|
|
t.Helper()
|
|
|
|
cipher, _ := GetTestCipher(t)
|
|
encrypted, err := db.EncryptJSON(cipher, db.OIDCSpec{})
|
|
require.NoError(t, err)
|
|
|
|
now := time.Now().UTC().Truncate(time.Millisecond)
|
|
result := db.OIDCClientConfig{
|
|
ID: uuid.New(),
|
|
Issuer: "issuer",
|
|
Data: encrypted,
|
|
LastModified: now,
|
|
}
|
|
|
|
if record.ID != uuid.Nil {
|
|
result.ID = record.ID
|
|
}
|
|
|
|
if record.OrganizationID != uuid.Nil {
|
|
result.OrganizationID = record.OrganizationID
|
|
}
|
|
|
|
if record.Issuer != "" {
|
|
result.Issuer = record.Issuer
|
|
}
|
|
|
|
if record.Data != nil {
|
|
result.Data = record.Data
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func CreateOIDCClientConfigs(t *testing.T, conn *gorm.DB, entries ...db.OIDCClientConfig) []db.OIDCClientConfig {
|
|
t.Helper()
|
|
|
|
var records []db.OIDCClientConfig
|
|
var ids []string
|
|
for _, entry := range entries {
|
|
record := NewOIDCClientConfig(t, entry)
|
|
records = append(records, record)
|
|
ids = append(ids, record.ID.String())
|
|
|
|
_, err := db.CreateOIDCCLientConfig(context.Background(), conn, record)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
t.Cleanup(func() {
|
|
HardDeleteOIDCClientConfigs(t, ids...)
|
|
})
|
|
|
|
return records
|
|
}
|
|
|
|
func HardDeleteOIDCClientConfigs(t *testing.T, ids ...string) {
|
|
if len(ids) > 0 {
|
|
require.NoError(t, conn.Where(ids).Delete(&db.OIDCClientConfig{}).Error)
|
|
}
|
|
}
|