mirror of
https://github.com/portainer/portainer.git
synced 2025-07-21 14:29:40 +02:00
* add updateSettingsToDB28 func and test * update DBversion const * migration func naming modification * feat(oauth): add sso, hide internal auth teaser and logout options. (#5039) * cleanup and make helper func for unit testing * dbversion update * feat(publicSettings): public settings response modification for OAuth SSO EE-608 (#5062) * feat(oauth): updated logout logic with logoutUrl. (#5064) * add exclusive token generation for OAuth * swagger annotation revision * add unit test * updates based on tech review feedback * feat(oauth): updated oauth settings model * feat(oauth): added oauth logout url * feat(oauth): fixed SSO toggle and logout issue. * set SSO to ON by default * update migrator unit test * set SSO to true by default for new instance * prevent applying the SSO logout url to the initial admin user Co-authored-by: fhanportainer <79428273+fhanportainer@users.noreply.github.com> Co-authored-by: Felix Han <felix.han@portainer.io>
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package migrator
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/boltdb/bolt"
|
|
"github.com/portainer/portainer/api/bolt/settings"
|
|
)
|
|
|
|
var (
|
|
testingDBStorePath string
|
|
testingDBFileName string
|
|
dummyLogoURL string
|
|
dbConn *bolt.DB
|
|
settingsService *settings.Service
|
|
)
|
|
|
|
func setup() error {
|
|
testingDBStorePath, _ = os.Getwd()
|
|
testingDBFileName = "portainer-ee-mig-30.db"
|
|
dummyLogoURL = "example.com"
|
|
var err error
|
|
dbConn, err = initTestingDBConn(testingDBStorePath, testingDBFileName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
dummySettingsObj := map[string]interface{}{
|
|
"LogoURL": dummyLogoURL,
|
|
}
|
|
settingsService, err = initTestingSettingsService(dbConn, dummySettingsObj)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func TestUpdateSettingsToDB31(t *testing.T) {
|
|
if err := setup(); err != nil {
|
|
t.Errorf("failed to complete testing setups, err: %v", err)
|
|
}
|
|
defer dbConn.Close()
|
|
defer os.Remove(testingDBFileName)
|
|
m := &Migrator{
|
|
db: dbConn,
|
|
settingsService: settingsService,
|
|
}
|
|
if err := m.updateSettingsToDB31(); err != nil {
|
|
t.Errorf("failed to update settings: %v", err)
|
|
}
|
|
updatedSettings, err := m.settingsService.Settings()
|
|
if err != nil {
|
|
t.Errorf("failed to retrieve the updated settings: %v", err)
|
|
}
|
|
if updatedSettings.LogoURL != dummyLogoURL {
|
|
t.Errorf("unexpected value changes in the updated settings, want LogoURL value: %s, got LogoURL value: %s", dummyLogoURL, updatedSettings.LogoURL)
|
|
}
|
|
if updatedSettings.OAuthSettings.SSO != false {
|
|
t.Errorf("unexpected default OAuth SSO setting, want: false, got: %t", updatedSettings.OAuthSettings.SSO)
|
|
}
|
|
if updatedSettings.OAuthSettings.LogoutURI != "" {
|
|
t.Errorf("unexpected default OAuth HideInternalAuth setting, want:, got: %s", updatedSettings.OAuthSettings.LogoutURI)
|
|
}
|
|
}
|